Skip to content

Commit

Permalink
Improve team key error logging (#1715)
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels authored Dec 20, 2022
1 parent 3851966 commit bcd6054
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/notifications/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def _service_allowed_to_send_to(notification, service):
# FIXME: hard code it for now until we can get en/fr specific links and text
if api_user.key_type == KEY_TYPE_TEAM:
message = (
"Can’t send to this recipient using a team-only API key "
f"Can’t send to this recipient using a team-only API key (service {service.id}) "
f'- see {get_document_url("en", "keys.html#team-and-safelist")}'
)
else:
Expand Down
2 changes: 1 addition & 1 deletion app/notifications/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def service_can_send_to_recipient(send_to, key_type: ApiKeyType, service: Servic
# FIXME: hard code it for now until we can get en/fr specific links and text
if key_type == KEY_TYPE_TEAM:
message = (
"Can’t send to this recipient using a team-only API key "
f"Can’t send to this recipient using a team-only API key (service {service.id}) "
f'- see {get_document_url("en", "keys.html#team-and-safelist")}'
)
else:
Expand Down
10 changes: 5 additions & 5 deletions tests/app/notifications/rest/test_send_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def test_should_not_return_html_in_body(notify_api, notify_db, notify_db_session
assert json.loads(response.get_data(as_text=True))["data"]["body"] == "hello\nthere"


def test_should_not_send_email_if_team_api_key_and_not_a_service_user(notify_api, sample_email_template, mocker):
def test_should_not_send_email_if_team_api_key_and_not_a_service_user(notify_api, sample_email_template, sample_service, mocker):
with notify_api.test_request_context(), notify_api.test_client() as client:
mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
data = {
Expand All @@ -514,12 +514,12 @@ def test_should_not_send_email_if_team_api_key_and_not_a_service_user(notify_api

assert response.status_code == 400
assert [
"Can’t send to this recipient using a team-only API key "
f"Can’t send to this recipient using a team-only API key (service {sample_service.id}) "
f'- see {get_document_url("en", "keys.html#team-and-safelist")}'
] == json_resp["message"]["to"]


def test_should_not_send_sms_if_team_api_key_and_not_a_service_user(notify_api, sample_template, mocker):
def test_should_not_send_sms_if_team_api_key_and_not_a_service_user(notify_api, sample_template, sample_service, mocker):
with notify_api.test_request_context(), notify_api.test_client() as client:
mocker.patch("app.celery.provider_tasks.deliver_sms.apply_async")

Expand All @@ -541,7 +541,7 @@ def test_should_not_send_sms_if_team_api_key_and_not_a_service_user(notify_api,

assert response.status_code == 400
assert [
"Can’t send to this recipient using a team-only API key "
f"Can’t send to this recipient using a team-only API key (service {sample_service.id}) "
f'- see {get_document_url("en", "keys.html#team-and-safelist")}'
] == json_resp["message"]["to"]

Expand Down Expand Up @@ -849,7 +849,7 @@ def test_should_not_send_notification_to_non_safelist_recipient_in_trial_mode(
("Can’t send to this recipient when service is in trial mode " f'– see {get_document_url("en", "keys.html#live")}')
if key_type == KEY_TYPE_NORMAL
else (
"Can’t send to this recipient using a team-only API key "
f"Can’t send to this recipient using a team-only API key (service {service.id}) "
f'- see {get_document_url("en", "keys.html#team-and-safelist")}'
)
)
Expand Down
6 changes: 3 additions & 3 deletions tests/app/notifications/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def test_service_can_send_to_recipient_fails_when_ignoring_safelist(
)
assert exec_info.value.status_code == 400
assert (
exec_info.value.message == "Can’t send to this recipient using a team-only API key "
exec_info.value.message == f"Can’t send to this recipient using a team-only API key (service {sample_service.id}) "
f'- see {get_document_url("en", "keys.html#team-and-safelist")}'
)
assert exec_info.value.fields == []
Expand All @@ -413,7 +413,7 @@ def test_service_can_send_to_recipient_fails_when_ignoring_safelist(
@pytest.mark.parametrize(
"key_type, error_message",
[
("team", "Can’t send to this recipient using a team-only API key - see"),
("team", "Can’t send to this recipient using a team-only API key"),
("normal", "Can’t send to this recipient when service is in trial mode – see "),
],
) # noqa
Expand All @@ -438,7 +438,7 @@ def test_service_can_send_to_recipient_fails_when_mobile_number_is_not_on_team(n
service_can_send_to_recipient("0758964221", "team", live_service)
assert e.value.status_code == 400
assert (
e.value.message == "Can’t send to this recipient using a team-only API key "
e.value.message == f"Can’t send to this recipient using a team-only API key (service {live_service.id}) "
f'- see {get_document_url("en", "keys.html#team-and-safelist")}'
)
assert e.value.fields == []
Expand Down
2 changes: 1 addition & 1 deletion tests/app/v2/notifications/test_post_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def test_post_sms_notification_returns_400_if_number_not_safelisted(self, notify
assert error_json["errors"] == [
{
"error": "BadRequestError",
"message": "Can’t send to this recipient using a team-only API key "
"message": f"Can’t send to this recipient using a team-only API key (service {service.id}) "
f'- see {get_document_url("en", "keys.html#team-and-safelist")}',
}
]
Expand Down

0 comments on commit bcd6054

Please sign in to comment.