Guest User

Untitled

a guest
Jun 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. from django.test import TestCase
  2.  
  3. class SampleTest(TestCase):
  4. def setUp(self):
  5. # Login - seems that session cookies behave more
  6. # consistent this way.
  7. self.credentials = {'username': 'user',
  8. 'password': 'passwd'}
  9. self.client.login(**self.credentials)
  10.  
  11. # Set additional attributes on the client object.
  12. ip = {'REMOTE_ADDR': '127.0.0.1'}
  13. setattr(self.client, 'META', ip)
  14.  
  15. # Need to store the session in a separate variable,
  16. # otherwise it doesn't persist.
  17. session = self.client.session
  18. session['somekey'] = 'somevalue'
  19. session.save()
Add Comment
Please, Sign In to add comment