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.

auth_tests.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import unittest2
  2. from django.test import TestCase
  3. from django.contrib.auth import authenticate
  4. from django.core import mail
  5. from oscar.core.compat import get_user_model
  6. User = get_user_model()
  7. # Skip these tests for now as they only make sense when there isn't a unique
  8. # index on the user class. The test suite currently uses a custom model that
  9. # *does* have a unique index on email. When I figure out how to swap the user
  10. # model per test, we can re-enable this testcase.
  11. @unittest2.skip
  12. class TestEmailAuthBackendWhenUsersShareAnEmail(TestCase):
  13. def test_authenticates_when_passwords_are_different(self):
  14. # Create two users with the same email address
  15. email = 'person@example.com'
  16. for username in ['user1', 'user2']:
  17. User.objects.create_user(username, email, password=username)
  18. user = authenticate(username=email, password='user1')
  19. self.assertTrue(user is not None)
  20. def test_rejects_when_passwords_match(self):
  21. # Create two users with the same email address
  22. email = 'person@example.com'
  23. for username in ['user1', 'user2']:
  24. User.objects.create_user(username, email, password='password')
  25. user = authenticate(username=email, password='password')
  26. self.assertTrue(user is None)
  27. def test_mails_admins_when_passwords_match(self):
  28. # Create two users with the same email address
  29. email = 'person@example.com'
  30. for username in ['user1', 'user2']:
  31. User.objects.create_user(username, email, password='password')
  32. authenticate(username=email, password='password')
  33. self.assertEqual(1, len(mail.outbox))