-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dependabot/pip/requests-2.32.0
- Loading branch information
Showing
4 changed files
with
354 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "6.44.5" | ||
__version__ = "6.44.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
send_dotmailer_consent_confirmation_email_to_user, | ||
DotmailerUserType, | ||
) | ||
from django.core import mail | ||
from django.test import Client | ||
from django.urls import reverse | ||
|
||
|
@@ -41,19 +40,15 @@ def now(cls): | |
monkeypatch.setattr(datetime, "datetime", mydatetime) | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_send_new_users_numbers_email(): | ||
client = Client() | ||
response = client.get(reverse("send_new_users_report")) | ||
assert response.status_code == 200 | ||
assert len(mail.outbox) == 1 | ||
|
||
|
||
def test_newsletter_calls_correct_requests(mocker, monkeypatch): | ||
mocked_create_contact = mocker.patch("common.helpers.emails.create_contact") | ||
mocked_add_to_address_book = mocker.patch("common.helpers.emails.add_contact_to_address_book") | ||
mocked_add_to_address_book = mocker.patch( | ||
"common.helpers.emails.add_contact_to_address_book" | ||
) | ||
|
||
add_to_dotmailer("Ray", "Charles", "[email protected]", DotmailerUserType.TEACHER) | ||
add_to_dotmailer( | ||
"Ray", "Charles", "[email protected]", DotmailerUserType.TEACHER | ||
) | ||
|
||
mocked_create_contact.assert_called_once() | ||
mocked_add_to_address_book.assert_called_once() | ||
|
@@ -74,10 +69,15 @@ def test_delete_account(mocker): | |
|
||
delete_contact("[email protected]") | ||
|
||
mocked_delete.assert_called_once_with(DOTMAILER_DELETE_USER_BY_ID_URL, auth=(DOTMAILER_USER, DOTMAILER_PASSWORD)) | ||
mocked_delete.assert_called_once_with( | ||
DOTMAILER_DELETE_USER_BY_ID_URL, | ||
auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), | ||
) | ||
|
||
|
||
def test_newsletter_sends_correct_request_data(mocker, monkeypatch, patch_datetime_now): | ||
def test_newsletter_sends_correct_request_data( | ||
mocker, monkeypatch, patch_datetime_now | ||
): | ||
mocked_post = mocker.patch("common.helpers.emails.post") | ||
|
||
expected_body1 = { | ||
|
@@ -91,7 +91,13 @@ def test_newsletter_sends_correct_request_data(mocker, monkeypatch, patch_dateti | |
{"key": "FULLNAME", "value": "Ray Charles"}, | ||
], | ||
}, | ||
"consentFields": [{"fields": [{"key": "DATETIMECONSENTED", "value": FAKE_TIME.__str__()}]}], | ||
"consentFields": [ | ||
{ | ||
"fields": [ | ||
{"key": "DATETIMECONSENTED", "value": FAKE_TIME.__str__()} | ||
] | ||
} | ||
], | ||
"preferences": [{"trout": True}], | ||
} | ||
|
||
|
@@ -109,51 +115,76 @@ def test_newsletter_sends_correct_request_data(mocker, monkeypatch, patch_dateti | |
create_contact("Ray", "Charles", "[email protected]") | ||
|
||
mocked_post.assert_called_once_with( | ||
DOTMAILER_CREATE_CONTACT_URL, auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), json=expected_body1 | ||
DOTMAILER_CREATE_CONTACT_URL, | ||
auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), | ||
json=expected_body1, | ||
) | ||
|
||
add_contact_to_address_book("Ray", "Charles", "[email protected]", DotmailerUserType.TEACHER) | ||
add_contact_to_address_book( | ||
"Ray", "Charles", "[email protected]", DotmailerUserType.TEACHER | ||
) | ||
|
||
assert mocked_post.call_count == 3 | ||
|
||
mocked_post.assert_any_call( | ||
DOTMAILER_MAIN_ADDRESS_BOOK_URL, auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), json=expected_body2 | ||
DOTMAILER_MAIN_ADDRESS_BOOK_URL, | ||
auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), | ||
json=expected_body2, | ||
) | ||
|
||
mocked_post.assert_any_call( | ||
DOTMAILER_TEACHER_ADDRESS_BOOK_URL, auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), json=expected_body2 | ||
DOTMAILER_TEACHER_ADDRESS_BOOK_URL, | ||
auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), | ||
json=expected_body2, | ||
) | ||
|
||
mocked_post.reset_mock() | ||
|
||
add_contact_to_address_book("Ray", "Charles", "[email protected]", DotmailerUserType.STUDENT) | ||
add_contact_to_address_book( | ||
"Ray", "Charles", "[email protected]", DotmailerUserType.STUDENT | ||
) | ||
|
||
assert mocked_post.call_count == 2 | ||
|
||
mocked_post.assert_any_call( | ||
DOTMAILER_MAIN_ADDRESS_BOOK_URL, auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), json=expected_body2 | ||
DOTMAILER_MAIN_ADDRESS_BOOK_URL, | ||
auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), | ||
json=expected_body2, | ||
) | ||
|
||
mocked_post.assert_any_call( | ||
DOTMAILER_STUDENT_ADDRESS_BOOK_URL, auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), json=expected_body2 | ||
DOTMAILER_STUDENT_ADDRESS_BOOK_URL, | ||
auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), | ||
json=expected_body2, | ||
) | ||
|
||
mocked_post.reset_mock() | ||
|
||
add_contact_to_address_book("Ray", "Charles", "[email protected]", DotmailerUserType.NO_ACCOUNT) | ||
add_contact_to_address_book( | ||
"Ray", | ||
"Charles", | ||
"[email protected]", | ||
DotmailerUserType.NO_ACCOUNT, | ||
) | ||
|
||
assert mocked_post.call_count == 2 | ||
|
||
mocked_post.assert_any_call( | ||
DOTMAILER_MAIN_ADDRESS_BOOK_URL, auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), json=expected_body2 | ||
DOTMAILER_MAIN_ADDRESS_BOOK_URL, | ||
auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), | ||
json=expected_body2, | ||
) | ||
|
||
mocked_post.assert_any_call( | ||
DOTMAILER_NO_ACCOUNT_ADDRESS_BOOK_URL, auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), json=expected_body2 | ||
DOTMAILER_NO_ACCOUNT_ADDRESS_BOOK_URL, | ||
auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), | ||
json=expected_body2, | ||
) | ||
|
||
|
||
def test_consent_calls_send_correct_request_data(mocker, monkeypatch, patch_datetime_now): | ||
def test_consent_calls_send_correct_request_data( | ||
mocker, monkeypatch, patch_datetime_now | ||
): | ||
mocked_post = mocker.patch("common.helpers.emails.post") | ||
mocked_put = mocker.patch("common.helpers.emails.put") | ||
|
||
|
@@ -181,21 +212,34 @@ def test_consent_calls_send_correct_request_data(mocker, monkeypatch, patch_date | |
{"key": "FULLNAME", "value": "Ray Charles"}, | ||
], | ||
}, | ||
"consentFields": [{"fields": [{"key": "DATETIMECONSENTED", "value": FAKE_TIME.__str__()}]}], | ||
"consentFields": [ | ||
{ | ||
"fields": [ | ||
{"key": "DATETIMECONSENTED", "value": FAKE_TIME.__str__()} | ||
] | ||
} | ||
], | ||
} | ||
|
||
expected_body2 = {"campaignID": DOTMAILER_THANKS_FOR_STAYING_CAMPAIGN_ID, "contactIds": ["1"]} | ||
expected_body2 = { | ||
"campaignID": DOTMAILER_THANKS_FOR_STAYING_CAMPAIGN_ID, | ||
"contactIds": ["1"], | ||
} | ||
|
||
add_consent_record_to_dotmailer_user(user) | ||
|
||
mocked_put.assert_called_once_with( | ||
DOTMAILER_PUT_CONSENT_DATA_URL, auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), json=expected_body1 | ||
DOTMAILER_PUT_CONSENT_DATA_URL, | ||
auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), | ||
json=expected_body1, | ||
) | ||
|
||
send_dotmailer_consent_confirmation_email_to_user(user) | ||
|
||
mocked_post.assert_called_with( | ||
DOTMAILER_SEND_CAMPAIGN_URL, auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), json=expected_body2 | ||
DOTMAILER_SEND_CAMPAIGN_URL, | ||
auth=(DOTMAILER_USER, DOTMAILER_PASSWORD), | ||
json=expected_body2, | ||
) | ||
|
||
|
||
|
@@ -212,9 +256,15 @@ def test_dotmailer_consent_form(mocker, monkeypatch): | |
c = Client() | ||
consent_form_url = reverse("consent_form") | ||
|
||
mocked_get_user_success = mocker.patch("portal.views.dotmailer.get_dotmailer_user_by_email") | ||
mocked_add_consent = mocker.patch("portal.views.dotmailer.add_consent_record_to_dotmailer_user") | ||
mocked_send_campaign = mocker.patch("portal.views.dotmailer.send_dotmailer_consent_confirmation_email_to_user") | ||
mocked_get_user_success = mocker.patch( | ||
"portal.views.dotmailer.get_dotmailer_user_by_email" | ||
) | ||
mocked_add_consent = mocker.patch( | ||
"portal.views.dotmailer.add_consent_record_to_dotmailer_user" | ||
) | ||
mocked_send_campaign = mocker.patch( | ||
"portal.views.dotmailer.send_dotmailer_consent_confirmation_email_to_user" | ||
) | ||
|
||
get_consent_form_response = c.get(consent_form_url) | ||
|
||
|
@@ -244,7 +294,10 @@ def test_dotmailer_consent_form(mocker, monkeypatch): | |
mocked_add_consent.assert_called_once() | ||
mocked_send_campaign.assert_called_once() | ||
|
||
mocker.patch("portal.views.dotmailer.add_consent_record_to_dotmailer_user", side_effect=KeyError) | ||
mocker.patch( | ||
"portal.views.dotmailer.add_consent_record_to_dotmailer_user", | ||
side_effect=KeyError, | ||
) | ||
|
||
wrong_email_response = c.post(consent_form_url, data=good_request_data) | ||
|
||
|
@@ -255,4 +308,7 @@ def test_dotmailer_consent_form(mocker, monkeypatch): | |
|
||
def _is_warning_message_showing(response): | ||
messages = list(response.wsgi_request._messages) | ||
assert messages[0].message == "Valid email address and consent required. Please try again." | ||
assert ( | ||
messages[0].message | ||
== "Valid email address and consent required. Please try again." | ||
) |
Oops, something went wrong.