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

12345678910111213141516171819202122232425262728293031323334
  1. from django.test import TestCase
  2. from django.contrib.auth.models import User
  3. from django.contrib.auth import authenticate
  4. from django.core import mail
  5. class TestEmailAuthBackendWhenUsersShareAnEmail(TestCase):
  6. def test_authenticates_when_passwords_are_different(self):
  7. # Create two users with the same email address
  8. email = 'person@example.com'
  9. for username in ['user1', 'user2']:
  10. User.objects.create_user(username, email, password=username)
  11. user = authenticate(username=email, password='user1')
  12. self.assertTrue(user is not None)
  13. def test_rejects_when_passwords_match(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='password')
  18. user = authenticate(username=email, password='password')
  19. self.assertTrue(user is None)
  20. def test_mails_admins_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. authenticate(username=email, password='password')
  26. self.assertEqual(1, len(mail.outbox))