From 99a9b2d868f352fb5f3229ee6c4f77f418970b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matja=C5=BE=20Horvat?= Date: Thu, 16 May 2024 10:31:32 +0200 Subject: [PATCH] Add unit test --- pontoon/messaging/tests/__init__.py | 0 pontoon/messaging/tests/test_views.py | 32 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 pontoon/messaging/tests/__init__.py create mode 100644 pontoon/messaging/tests/test_views.py diff --git a/pontoon/messaging/tests/__init__.py b/pontoon/messaging/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pontoon/messaging/tests/test_views.py b/pontoon/messaging/tests/test_views.py new file mode 100644 index 0000000000..2ae8ac0c39 --- /dev/null +++ b/pontoon/messaging/tests/test_views.py @@ -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"] == "/"