Ticket #5189: client.patch
File client.patch, 2.6 KB (added by , 17 years ago) |
---|
-
django/test/client.py
253 253 else: 254 254 return False 255 255 256 def logout(self): 257 """Removes the authenticated user's cookies. 258 259 Causes the authenticated user to be logged out. 260 """ 261 try: 262 Session.objects.get(session_key=self.cookies['sessionid'].value).delete() 263 except KeyError: 264 pass 265 266 self.cookies = SimpleCookie() 267 No newline at end of file -
tests/modeltests/test_client/models.py
246 246 login = self.client.login(username='inactive', password='password') 247 247 self.failIf(login) 248 248 249 def test_logout(self): 250 # Log in 251 self.client.login(username='testclient', password='password') 252 253 # Request a page that requires a login 254 response = self.client.get('/test_client/login_protected_view/') 255 self.assertEqual(response.status_code, 200) 256 self.assertEqual(response.context['user'].username, 'testclient') 257 258 # Log out 259 self.client.logout() 260 261 # Request a page that requires a login 262 response = self.client.get('/test_client/login_protected_view/') 263 self.assertRedirects(response, '/accounts/login/') 264 249 265 def test_session_modifying_view(self): 250 266 "Request a page that modifies the session" 251 267 # Session value isn't set initially -
docs/testing.txt
550 550 conditions. You'll need to create users as part of the test suite -- either 551 551 manually (using the Django model API) or with a test fixture. 552 552 553 ``logout()`` 554 **New in Django development version** 555 556 If your site uses Django's `authentication system`_ and you deal with 557 logging in users using test client's ``login()`` method you can also use 558 client's ``logout()`` method to simulate the effect of logging a user out from 559 the site. 560 561 After you call this method, the test client will have all the cookies and 562 session data cleared to defaults. Your current user will become an 563 Anonymous User. 564 565 553 566 .. _authentication system: ../authentication/ 554 567 .. _authentication backend: ../authentication/#other-authentication-sources