forked from City-of-Helsinki/respa
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unique constraint should be dropped from account_emailaddress table manually because it's already previously added in the account migrations. Instead add unique together constraint for email and user_id fields. See 0002_email_max_length.py migration in allauth/account. ALTER TABLE account_emailaddress DROP CONSTRAINT account_emailaddress_email_key; ALTER TABLE account_emailaddress ADD CONSTRAINT account_emailaddress_email_key UNIQUE (user_id, email);
- Loading branch information
1 parent
5e8e4a0
commit 2ade16d
Showing
3 changed files
with
18 additions
and
1 deletion.
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
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,4 +1,5 @@ | ||
from allauth.account.models import EmailAddress | ||
from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
from django.urls import reverse | ||
from rest_framework import status | ||
|
@@ -64,6 +65,7 @@ def test_set_email_not_provided(self): | |
self.assertEqual(self.user.email, "") | ||
|
||
def test_set_email_already_in_use(self): | ||
settings.ACCOUNT_UNIQUE_EMAIL = True | ||
url = reverse("user-set-email", kwargs={"pk": self.user.pk}) | ||
data = {"email": "[email protected]"} # Email already used by other_user | ||
|
||
|
@@ -74,3 +76,16 @@ def test_set_email_already_in_use(self): | |
response.data, {"detail": "The email address is already in use."} | ||
) | ||
self.assertEqual(self.user.email, "") | ||
|
||
def test_allow_to_set_duplicate_email(self): | ||
settings.ACCOUNT_UNIQUE_EMAIL = False | ||
url = reverse("user-set-email", kwargs={"pk": self.user.pk}) | ||
data = {"email": "[email protected]"} # Email already used by other_user | ||
|
||
response = self.client.post(url, data, format="json") | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual( | ||
response.data, {"detail": "Email set successfully."} | ||
) | ||
self.assertEqual(self.user.email, "[email protected]") |