Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
test_signup: Test List-Unsubscribe POST request.
Anders Kaseorg31105b78f2e6
diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex ae9c772560f..84dfa04cd39 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -13,7 +13,7 @@ from django.contrib.auth.views import PasswordResetConfirmViewfrom django.contrib.contenttypes.models import ContentTypefrom django.core.exceptions import ValidationErrorfrom django.http import HttpResponse-from django.test import override_settings+from django.test import Client, override_settingsfrom django.urls import reversefrom django.utils.timezone import now as timezone_now@@ -2676,6 +2676,27 @@ class EmailUnsubscribeTests(ZulipTestCase):user_profile.refresh_from_db()self.assertFalse(user_profile.enable_marketing_emails)+ def test_marketing_unsubscribe_post(self) -> None:+ """+ The List-Unsubscribe-Post header lets email clients trigger an+ automatic unsubscription request via POST (see RFC 8058), so+ test that too.+ """+ user_profile = self.example_user("hamlet")+ self.assertTrue(user_profile.enable_marketing_emails)++ # Simulate unsubscribing from marketing e-mails.+ unsubscribe_link = one_click_unsubscribe_link(user_profile, "marketing")+ client = Client(enforce_csrf_checks=True)+ result = client.post(+ urllib.parse.urlparse(unsubscribe_link).path, {"List-Unsubscribe": "One-Click"}+ )+ self.assertEqual(result.status_code, 200)++ # Circumvent user_profile caching.+ user_profile.refresh_from_db()+ self.assertFalse(user_profile.enable_marketing_emails)+class RealmCreationTest(ZulipTestCase):@override_settings(OPEN_REALM_CREATION=True)