mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-31 03:53:50 +00:00 
			
		
		
		
	test_signup: Test List-Unsubscribe POST request.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						 Tim Abbott
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							f4b3c15fe8
						
					
				
				
					commit
					31105b78f2
				
			| @@ -13,7 +13,7 @@ from django.contrib.auth.views import PasswordResetConfirmView | ||||
| from django.contrib.contenttypes.models import ContentType | ||||
| from django.core.exceptions import ValidationError | ||||
| from django.http import HttpResponse | ||||
| from django.test import override_settings | ||||
| from django.test import Client, override_settings | ||||
| from django.urls import reverse | ||||
| from 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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user