Ejemplo n.º 1
0
class TestUsernameAuthBackend(TestCase):
    def setUp(self):
        self.testuser = User.objects.create_user(
            username='******',
            password='******')
        self.authbackend = UsernameAuthBackend()

    def test_lookup_user(self):
        user = self.authbackend.lookup_user(username='******')
        self.assertEqual(user.pk, self.testuser.pk)

    def test_lookup_user_invalid_email(self):
        with self.assertRaises(User.DoesNotExist):
            self.authbackend.lookup_user(username='******')

    def test_get_user(self):
        user = self.authbackend.get_user(self.testuser.pk)
        self.assertEqual(user.pk, self.testuser.pk)

    def test_get_user_returns_none(self):
        user = self.authbackend.get_user(42)
        self.assertIsNone(user)

    def test_authenticate(self):
        user = self.authbackend.authenticate(username='******',
                                             password='******')
        self.assertIsNotNone(user)
        self.assertEqual(self.testuser.pk, user.pk)

    def test_authenticate_invalid_password_returns_none(self):
        user = self.authbackend.authenticate(username='******',
                                             password='******')
        self.assertIsNone(user)

    def test_authenticate_invalid_email_returns_none(self):
        user = self.authbackend.authenticate(username='******',
                                             password='******')
        self.assertIsNone(user)
Ejemplo n.º 2
0
 def setUp(self):
     self.testuser = User.objects.create_user(
         username='******',
         password='******')
     self.authbackend = UsernameAuthBackend()