Testing authentication in Django

, , django, tests, authentication

In order to check if user is authentcated in test, you can run:

  from django.contrib.auth import get_user

  class MyTestCase(TestCase):
      def test_login(self):
          self.assertFalse(get_user(self.client).is_authenticated())
          self.client.login(username='fred', password='secret')
          self.assertTrue(get_user(self.client).is_authenticated())
contact us right now