You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_auth_backend.py 1.2KB

123456789101112131415161718192021222324252627282930313233
  1. import unittest
  2. import django
  3. from django.test import TestCase
  4. from oscar.apps.customer.auth_backends import EmailBackend
  5. from oscar.test.factories import UserFactory
  6. class AuthBackendTestCase(TestCase):
  7. def setUp(self):
  8. self.user = UserFactory(email='foo@example.com', is_staff=True)
  9. self.user.set_password('letmein')
  10. self.user.save()
  11. self.backend = EmailBackend()
  12. @unittest.skipUnless(django.VERSION < (1, 11), "for Django <1.11 only")
  13. def test_authentication_method_signature_pre_django_1_11(self):
  14. auth_result = self.backend.authenticate('foo@example.com', 'letmein')
  15. self.assertEqual(auth_result, self.user)
  16. @unittest.skipUnless(django.VERSION >= (1, 11), "for Django >=1.11 only")
  17. def test_authentication_method_signature_post_django_1_11(self):
  18. auth_result = self.backend.authenticate(None, 'foo@example.com', 'letmein')
  19. self.assertEqual(auth_result, self.user)
  20. def test_inactive_users_cannot_authenticate(self):
  21. self.user.is_active = False
  22. self.user.save()
  23. auth_result = self.backend.authenticate(None, 'foo@example.com', 'letmein')
  24. self.assertIsNone(auth_result)