diff --git a/app/core/models.py b/app/core/models.py index 0edd236..06f621e 100644 --- a/app/core/models.py +++ b/app/core/models.py @@ -13,7 +13,7 @@ class UserManager(BaseUserManager): """Manager for users.""" def create_user(self, email, password=None, **extra_fields): - user = self.model(email=email, **extra_fields) + user = self.model(email=self.normalize_email(email), **extra_fields) user.set_password(password) user.save(using=self._db) diff --git a/app/core/tests/test_models.py b/app/core/tests/test_models.py index 1ed55ae..57245e2 100644 --- a/app/core/tests/test_models.py +++ b/app/core/tests/test_models.py @@ -14,3 +14,14 @@ def test_create_user_with_email_successful(self): self.assertEqual(user.email, email) self.assertTrue(user.check_password(password)) + + def test_new_user_email_normalized(self): + sample_emails = [ + ['test1@EXAMPLE.com', 'test1@example.com'], + ['Test2@Example.com', 'Test2@example.com'], + ['TEST3@EXAMPLE.COM', 'TEST3@example.com'], + ['test4@example.COM', 'test4@example.com'], + ] + for email, expected in sample_emails: + user = get_user_model().objects.create_user(email, 'sample123') + self.assertEqual(user.email, expected)