Careful.
Also, how about sessions that has been set? is it possible to check their values in the test?
TDD is about externally visible behavior. To see if the user has a session, you would provide a link that only works when the user is logged in and has a session.
The usual drill is something like the following.
class When_NoLogin( TestCase ):
def test_should_not_get_some_resource( self ):
response= self.client.get( "/path/that/requires/login" )
self.assertEquals( 301, response.status_code )
That is, when not logged in, some (or all) URI's redirect to the login page.
class When_Login( TestCase ):
def setUp( self ):
self.client.login( username='this', password='that' )
def test_should_get_some_resource( self ):
response= self.client.get( "/path/that/requires/login" )
self.assertContains( response, '<input attr="this"', status_code=200 )
self.assertContains( response, '<tr class="that"', count=5 )
http://docs.djangoproject.com/en/1.2/topics/testing/#django.test.TestCase.assertContains
That is, when logged in, some (or all) URI's work as expected.
Further, the URI response contains the tags you require.
You don't test Django to see if it creates a session. Django already has unit tests for this. You test your application's externally visible behavior -- does it behave like there's a session? Are pages properly visible? Are they properly customized with session-specific information?