diff --git a/src/unique_user_email/apps.py b/src/unique_user_email/apps.py index d407dfb..4a3894a 100644 --- a/src/unique_user_email/apps.py +++ b/src/unique_user_email/apps.py @@ -22,5 +22,4 @@ def ready(self): ), ] User._meta.constraints = User.Meta.constraints - # ... as long as original_attrs is not updated. - # User._meta.original_attrs["constraints"] = User.Meta.constraints + User._meta.original_attrs["constraints"] = User.Meta.constraints diff --git a/tests/tests.py b/tests/tests.py index fd87b87..daf7fba 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -6,6 +6,7 @@ from django.test import TestCase from unique_user_email.backend import EmailBackend from unique_user_email.forms import AuthenticationForm +from django.db.models.constraints import UniqueConstraint class UniqueEmailTestCase(TestCase): @@ -55,6 +56,13 @@ def test_model_save_disallows_duplicate_emails(self): ): user2.save() + def test_user_constraints(self): + self.assertIsInstance(User._meta.constraints[0], UniqueConstraint) + self.assertEqual("unique_user_email", User._meta.constraints[0].name) + self.assertEqual( + "unique_user_email", + User._meta.original_attrs.get("constraints")[0].name + ) class EmailBackendTests(TestCase): def test_none_for_username_logins(self):