-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from open-zaak/feature/OAF#39-user-email-unique
🐛[maykinmedia/open-api-framework#39] make user emails unique
- Loading branch information
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/nrc/accounts/migrations/0005_user_filled_email_unique.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 4.2.11 on 2024-07-02 14:18 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("accounts", "0004_migrate_from_auth_adfs_db"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddConstraint( | ||
model_name="user", | ||
constraint=models.UniqueConstraint( | ||
condition=models.Q(("email", ""), _negated=True), | ||
fields=("email",), | ||
name="filled_email_unique", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from django.db import IntegrityError | ||
from django.test import TestCase | ||
|
||
from ..models import User | ||
|
@@ -20,3 +21,15 @@ def test_create_user(self): | |
self.assertFalse(user.is_superuser) | ||
self.assertFalse(user.is_staff) | ||
self.assertFalse(user.has_usable_password()) | ||
|
||
def test_create_users_with_same_email(self): | ||
User.objects.create(username="AAA", email="[email protected]", password="aaa!") | ||
|
||
with self.assertRaises(IntegrityError): | ||
User.objects.create(username="BBB", email="[email protected]", password="bbb!") | ||
|
||
def test_create_user_with_blank_emails(self): | ||
User.objects.create(username="AAA", email="", password="aaa!") | ||
User.objects.create(username="BBB", email="", password="bbb!") | ||
|
||
self.assertEqual(User.objects.count(), 2) |