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.3KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from django.test import TestCase
  2. from django.contrib.auth import authenticate
  3. from django.core import mail
  4. from oscar.core.compat import get_user_model
  5. User = get_user_model()
  6. class TestEmailAuthBackendWhenUsersShareAnEmail(TestCase):
  7. def test_authenticates_when_passwords_are_different(self):
  8. # Create two users with the same email address
  9. email = 'person@example.com'
  10. for username in ['user1', 'user2']:
  11. User.objects.create_user(username, email, password=username)
  12. user = authenticate(username=email, password='user1')
  13. self.assertTrue(user is not None)
  14. def test_rejects_when_passwords_match(self):
  15. # Create two users with the same email address
  16. email = 'person@example.com'
  17. for username in ['user1', 'user2']:
  18. User.objects.create_user(username, email, password='password')
  19. user = authenticate(username=email, password='password')
  20. self.assertTrue(user is None)
  21. def test_mails_admins_when_passwords_match(self):
  22. # Create two users with the same email address
  23. email = 'person@example.com'
  24. for username in ['user1', 'user2']:
  25. User.objects.create_user(username, email, password='password')
  26. authenticate(username=email, password='password')
  27. self.assertEqual(1, len(mail.outbox))