Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mathjazz committed May 16, 2024
1 parent ed2d878 commit 99a9b2d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Empty file.
32 changes: 32 additions & 0 deletions pontoon/messaging/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest

from pontoon.base.models import User


@pytest.mark.django_db
def test_dismiss_email_consent(member):
"""Test if dismiss_email_consent view works and fails as expected."""
params = {}
response = member.client.post(f"/dismiss-email-consent/", params)
assert response.status_code == 400
assert response.json()["message"] == "Bad Request: Value not set"

params = {
"value": "false",
}
response = member.client.post(f"/dismiss-email-consent/", params)
profile = User.objects.get(pk=member.user.pk).profile
assert profile.email_communications_enabled is False
assert profile.email_consent_dismissed_at is not None
assert response.status_code == 200
assert response.json()["next"] == "/"

params = {
"value": "true",
}
response = member.client.post(f"/dismiss-email-consent/", params)
profile = User.objects.get(pk=member.user.pk).profile
assert profile.email_communications_enabled is True
assert profile.email_consent_dismissed_at is not None
assert response.status_code == 200
assert response.json()["next"] == "/"

0 comments on commit 99a9b2d

Please sign in to comment.