Meticulous.
Also, what about the sessions that were established? Is it possible to check their values ββin the test?
TDD is an externally visible behavior. To find out if a user has a session, you must specify a link that only works when the user is logged in and has a session.
A typical exercise is as follows.
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 it is not logged in, some (or all) URIs are redirected 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 )
https://docs.djangoproject.com/en/dev/topics/testing/tools/#django.test.SimpleTestCase.assertContains
That is, at login, some (or all) of the URIs work as expected.
In addition, the URI response contains the tags you need.
You are not testing Django to see if it is creating a session. For this, Django already has unit tests. You check the external visible behavior of your application - does it behave like a session? Are the pages displayed correctly? Are they configured correctly with session information?
source share