@@ -16,7 +16,7 @@ def test_unsubscribe_valid_token(command, enrollment, anonymous_client):
1616 }
1717 )
1818
19- response = anonymous_client .get (f"{ URL } ?token={ token } " )
19+ response = anonymous_client .get (f"{ URL } ?token={ token } &confirm=true " )
2020
2121 assert command .return_value .execute .called
2222 assert response .status_code == 200
@@ -28,6 +28,30 @@ def test_unsubscribe_valid_token(command, enrollment, anonymous_client):
2828 )
2929
3030
31+ @patch ("django_email_learning.personalised.views.UnsubscribeCommand" )
32+ def test_unsubscribe_valid_token_confirmation (command , enrollment , anonymous_client ):
33+ token = jwt_service .generate_jwt (
34+ {
35+ "email" : enrollment .learner .email ,
36+ "course_slug" : enrollment .course .slug ,
37+ "organization_id" : enrollment .course .organization .id ,
38+ }
39+ )
40+
41+ response = anonymous_client .get (f"{ URL } ?token={ token } " )
42+
43+ assert not command .return_value .execute .called
44+ assert response .status_code == 200
45+ assert "page_title" in response .context
46+ assert response .context ["page_title" ] == "Confirm Unsubscription"
47+ assert (
48+ response .context ["confirmation_message" ]
49+ == "Are you sure you want to unsubscribe from our mailing list?"
50+ )
51+ assert "confirm_url" in response .context
52+ assert response .context ["confirm_url" ] == f"{ URL } ?token={ token } &confirm=true"
53+
54+
3155def test_unsubscribe_invalid_token (anonymous_client ):
3256 response = anonymous_client .get (f"{ URL } ?token=invalidtoken" )
3357 assert response .status_code == 400
0 commit comments