-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We want to save the reply_to_email_addresses in the cache (#2255)
* start * Adding reply_to_adress in a Service * fix * Fix deserialization * add tests for testing service serilization
- Loading branch information
Showing
4 changed files
with
159 additions
and
38 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
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
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 |
---|---|---|
|
@@ -81,6 +81,7 @@ | |
create_notification, | ||
create_notification_history, | ||
create_organisation, | ||
create_reply_to_email, | ||
create_service, | ||
create_service_with_defined_sms_sender, | ||
create_service_with_inbound_number, | ||
|
@@ -607,30 +608,61 @@ def test_get_service_by_id_returns_service(notify_db_session): | |
assert dao_fetch_service_by_id(service.id).name == "testing" | ||
|
||
|
||
def test_get_service_by_id_uses_redis_cache_when_use_cache_specified(notify_db_session, mocker): | ||
sample_service = create_service(service_name="testing", email_from="testing") | ||
service_json = {"data": service_schema.dump(sample_service)} | ||
class TestServiceCache: | ||
def test_get_service_by_id_uses_redis_cache_when_use_cache_specified(self, notify_db_session, mocker): | ||
sample_service = create_service(service_name="testing", email_from="testing") | ||
service_json = {"data": service_schema.dump(sample_service)} | ||
|
||
service_json["data"]["all_template_folders"] = ["b5035a31-b1da-42f8-b2b8-ce2acaa0b819"] | ||
service_json["data"]["annual_billing"] = ["8676fa80-a97b-43e7-8318-ee905de2d652", "a0751f79-984b-4d9e-9edd-42457fd458e9"] | ||
service_json["data"]["email_branding"] = "d51a41b2-c420-48a9-a8c5-e88444013020" | ||
service_json["data"]["inbound_number"] = "aa129e4b-d37c-493a-84da-62a31a8199e3" | ||
service_json["data"]["inbound_sms"] = ["fsdfdsfdsfdsfdsfsdf"] | ||
service_json["data"]["service_callback_api"] = ["wfeewfwefewfewfewfewfew"] | ||
service_json["data"]["service_data_retention"] = ["fdsfsdfsdfsdfsdfdsf"] | ||
|
||
mocked_redis_get = mocker.patch.object( | ||
redis_store, | ||
"get", | ||
return_value=bytes( | ||
json.dumps(service_json, default=lambda o: o.hex if isinstance(o, uuid.UUID) else None), encoding="utf-8" | ||
), | ||
) | ||
|
||
service_json["data"]["all_template_folders"] = ["b5035a31-b1da-42f8-b2b8-ce2acaa0b819"] | ||
service_json["data"]["annual_billing"] = ["8676fa80-a97b-43e7-8318-ee905de2d652", "a0751f79-984b-4d9e-9edd-42457fd458e9"] | ||
service_json["data"]["email_branding"] = "d51a41b2-c420-48a9-a8c5-e88444013020" | ||
service_json["data"]["inbound_number"] = "aa129e4b-d37c-493a-84da-62a31a8199e3" | ||
service_json["data"]["inbound_sms"] = ["fsdfdsfdsfdsfdsfsdf"] | ||
service_json["data"]["service_callback_api"] = ["wfeewfwefewfewfewfewfew"] | ||
service_json["data"]["service_data_retention"] = ["fdsfsdfsdfsdfsdfdsf"] | ||
service = dao_fetch_service_by_id(sample_service.id, use_cache=True) | ||
|
||
assert mocked_redis_get.called | ||
assert str(sample_service.id) == service.id | ||
|
||
def test_get_service_with_reply_to_from_cache_and_db(self, notify_db_session, mocker): | ||
sample_service = create_service(service_name="testing", email_from="testing") | ||
create_reply_to_email(sample_service, "[email protected]") | ||
service_json = {"data": service_schema.dump(sample_service)} | ||
|
||
service_json["data"]["all_template_folders"] = ["b5035a31-b1da-42f8-b2b8-ce2acaa0b819"] | ||
service_json["data"]["annual_billing"] = ["8676fa80-a97b-43e7-8318-ee905de2d652", "a0751f79-984b-4d9e-9edd-42457fd458e9"] | ||
service_json["data"]["email_branding"] = "d51a41b2-c420-48a9-a8c5-e88444013020" | ||
service_json["data"]["inbound_number"] = "aa129e4b-d37c-493a-84da-62a31a8199e3" | ||
service_json["data"]["inbound_sms"] = ["fsdfdsfdsfdsfdsfsdf"] | ||
service_json["data"]["service_callback_api"] = ["wfeewfwefewfewfewfewfew"] | ||
service_json["data"]["service_data_retention"] = ["fdsfsdfsdfsdfsdfdsf"] | ||
|
||
mocked_redis_get = mocker.patch.object( | ||
redis_store, | ||
"get", | ||
return_value=bytes( | ||
json.dumps(service_json, default=lambda o: o.hex if isinstance(o, uuid.UUID) else None), encoding="utf-8" | ||
), | ||
) | ||
|
||
mocked_redis_get = mocker.patch.object( | ||
redis_store, | ||
"get", | ||
return_value=bytes( | ||
json.dumps(service_json, default=lambda o: o.hex if isinstance(o, uuid.UUID) else None), encoding="utf-8" | ||
), | ||
) | ||
service = dao_fetch_service_by_id(sample_service.id, use_cache=True) | ||
|
||
service = dao_fetch_service_by_id(sample_service.id, use_cache=True) | ||
assert mocked_redis_get.called | ||
assert str(sample_service.id) == service.id | ||
assert str(service.reply_to_email_addresses[0].id) == str(sample_service.reply_to_email_addresses[0].id) | ||
|
||
assert mocked_redis_get.called | ||
assert str(sample_service.id) == service.id | ||
service = dao_fetch_service_by_id(sample_service.id, use_cache=False) | ||
assert str(service.reply_to_email_addresses[0].id) == str(sample_service.reply_to_email_addresses[0].id) | ||
|
||
|
||
def test_create_service_returns_service_with_default_permissions(notify_db_session): | ||
|
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 |
---|---|---|
|
@@ -2623,14 +2623,15 @@ def test_is_email_from_unique_returns_400_when_email_from_does_not_exist(admin_r | |
assert response["message"][1]["email_from"] == ["Can't be empty"] | ||
|
||
|
||
def test_get_email_reply_to_addresses_when_there_are_no_reply_to_email_addresses(client, sample_service): | ||
response = client.get( | ||
"/service/{}/email-reply-to".format(sample_service.id), | ||
headers=[create_authorization_header()], | ||
) | ||
class TestServiceEmailReplyTo: | ||
def test_get_email_reply_to_addresses_when_there_are_no_reply_to_email_addresses(self, client, sample_service): | ||
response = client.get( | ||
"/service/{}/email-reply-to".format(sample_service.id), | ||
headers=[create_authorization_header()], | ||
) | ||
|
||
assert json.loads(response.get_data(as_text=True)) == [] | ||
assert response.status_code == 200 | ||
assert json.loads(response.get_data(as_text=True)) == [] | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_get_email_reply_to_addresses_with_one_email_address(client, notify_db, notify_db_session): | ||
|
@@ -3223,3 +3224,32 @@ def test_get_monthly_notification_data_by_service(mocker, admin_request): | |
|
||
dao_mock.assert_called_once_with(start_date, end_date) | ||
assert response == [] | ||
|
||
|
||
class TestSerializationofServiceReplyto: | ||
def test_get_service(self, client, sample_service): | ||
sample_service.reply_to_email = "[email protected]" | ||
create_reply_to_email(service=sample_service, email_address="[email protected]") | ||
auth_header = create_authorization_header() | ||
resp = client.get( | ||
"/service/{}".format(sample_service.id), | ||
headers=[auth_header], | ||
) | ||
assert resp.status_code == 200 | ||
json_resp = resp.json | ||
assert json_resp["data"]["name"] == sample_service.name | ||
assert json_resp["data"]["id"] == str(sample_service.id) | ||
assert json_resp["data"]["reply_to_email_addresses"][0]["email_address"] == "[email protected]" | ||
|
||
def test_get_service_no_reply_to(self, client, sample_service): | ||
sample_service.reply_to_email = "[email protected]" | ||
auth_header = create_authorization_header() | ||
resp = client.get( | ||
"/service/{}".format(sample_service.id), | ||
headers=[auth_header], | ||
) | ||
assert resp.status_code == 200 | ||
json_resp = resp.json | ||
assert json_resp["data"]["name"] == sample_service.name | ||
assert json_resp["data"]["id"] == str(sample_service.id) | ||
assert json_resp["data"]["reply_to_email_addresses"] == [] |