Guest User

Untitled

a guest
Aug 2nd, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. django - get user logged into test client
  2. def test_author_set_once(self):
  3. self.client.login(username='Adam', password='password')
  4. #create an object and test the author is adam
  5. self.client.login(username='Barry', password='password')
  6. #modify the first object and test that the author has not changed
  7.  
  8. self.assertEqual(object.author, self.client.user)
  9.  
  10. self.client.login(username='Adam', password='password')
  11. self.user = User.objects.get(username='Adam')
  12. #create an object
  13. self.assertEqual(object.author, self.user)
  14.  
  15. response.request.user
Add Comment
Please, Sign In to add comment