-
Notifications
You must be signed in to change notification settings - Fork 0
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 #59 from City-of-Turku/feature/mailing-list-changes
Feature/mailing list changes
- Loading branch information
Showing
5 changed files
with
79 additions
and
7 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
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
25 changes: 25 additions & 0 deletions
25
account/migrations/0015_email_and_mailing_list_jointly_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,25 @@ | ||
# Generated by Django 4.1.13 on 2024-04-30 07:25 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("account", "0014_remove_profile_is_filled_for_fun"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="mailinglistemail", | ||
name="email", | ||
field=models.EmailField(max_length=254), | ||
), | ||
migrations.AddConstraint( | ||
model_name="mailinglistemail", | ||
constraint=models.UniqueConstraint( | ||
fields=("email", "mailing_list"), | ||
name="email_and_mailing_list_must_be_jointly: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 |
---|---|---|
|
@@ -374,3 +374,34 @@ def test_mailing_list_unsubscribe_email_not_provided( | |
url = reverse("account:profiles-unsubscribe") | ||
response = api_client_with_custom_ip_address.post(url) | ||
assert response.status_code == 400 | ||
|
||
|
||
@pytest.mark.django_db | ||
@pytest.mark.parametrize( | ||
"ip_address", | ||
[ | ||
("100.19.91.40"), | ||
], | ||
) | ||
def test_mailing_list_unique_constraints(api_client_with_custom_ip_address, users): | ||
url = reverse("account:profiles-subscribe") | ||
user = users.get(username="test1") | ||
response = api_client_with_custom_ip_address.post( | ||
url, {"email": "[email protected]", "user": user.id} | ||
) | ||
assert response.status_code == 201 | ||
assert MailingListEmail.objects.count() == 1 | ||
# Subscribed as the result (MailingList) is different than for user 'test1' | ||
user = users.get(username="test2") | ||
response = api_client_with_custom_ip_address.post( | ||
url, {"email": "[email protected]", "user": user.id} | ||
) | ||
assert response.status_code == 201 | ||
assert MailingListEmail.objects.count() == 2 | ||
# Fails, as the email and result are not jointly unique. | ||
user = users.get(username="test3") | ||
response = api_client_with_custom_ip_address.post( | ||
url, {"email": "[email protected]", "user": user.id} | ||
) | ||
assert response.status_code == 400 | ||
assert MailingListEmail.objects.count() == 2 |