Skip to content

Commit

Permalink
Merge branch 'main' into feat/provide-list-of-sending-domains
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbahrai authored Dec 19, 2024
2 parents 5c3bb9a + 2454078 commit cb63225
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 35 deletions.
13 changes: 5 additions & 8 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@
"vsliveshare.vsliveshare"
],
"settings": {
"ruff.lint.ignore": ["F401"],
"ruff.lint.run": "onSave",
"ruff.organizeImports": false,
"[python]": {
"ruff.lint.run": "onSave",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
}
},
"ruff.configurationPreference": "filesystemFirst"
"editor.defaultFormatter": "charliermarsh.ruff"
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ run-gunicorn:

.PHONY: format
format:
ruff check --select I --fix .
ruff check --fix .
ruff check
ruff format .
mypy ./
Expand Down
16 changes: 12 additions & 4 deletions app/main/views/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,15 @@ def check_notification_preview(service_id, template_id, filetype):
@main.route("/services/<service_id>/start-job/<upload_id>", methods=["POST"])
@user_has_permissions("send_messages", restrict_admin_usage=True)
def start_job(service_id, upload_id):
job_api_client.create_job(upload_id, service_id, scheduled_for=request.form.get("scheduled_for", ""))

try:
job_api_client.create_job(upload_id, service_id, scheduled_for=request.form.get("scheduled_for", ""))
except HTTPError as exception:
return render_template(
"views/notifications/check.html",
time_to_reset=get_limit_reset_time_et(),
**(get_template_error_dict(exception) if exception else {}),
template=None,
)
session.pop("sender_id", None)

return redirect(
Expand Down Expand Up @@ -1107,11 +1114,12 @@ def get_template_error_dict(exception):
error = "too-many-sms-messages"
elif "Content for template has a character count greater than the limit of" in exception.message:
error = "message-too-long"
elif "Exceeded annual email sending limit" in exception.message:
elif "Exceeded annual email sending" in exception.message:
error = "too-many-email-annual"
elif "Exceeded annual SMS sending limit" in exception.message:
elif "Exceeded annual SMS sending" in exception.message:
error = "too-many-sms-annual"
else:
current_app.logger.error("Unhandled exception from API: {}".format(exception))
raise exception

return {
Expand Down
4 changes: 3 additions & 1 deletion app/templates/views/notifications/check.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ <h2 class="heading-medium">{{_('You cannot send this email message today') }}</h
) }}
{% endif %}

{{ template|string|translate_preview_template }}
{% if template %}
{{ template|string|translate_preview_template }}
{% endif %}

<div class="js-stick-at-bottom-when-scrolling">
<form method="post" enctype="multipart/form-data" action="{{url_for(
Expand Down
40 changes: 20 additions & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mypy = "1.11.2"
monkeytype = "23.3.0"
poethepoet = "^0.24.4"
pre-commit = "^3.7.1"
ruff = "^0.6.9"
ruff = "^0.8.2"

# stubs libraries to keep mypy happy
types-python-dateutil = "2.9.0.20241003"
Expand Down
3 changes: 3 additions & 0 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ display_result $? 1 "Code style check"
ruff check --select I .
display_result $? 1 "Import order check"

ruff format --check .
display_result $? 1 "Code format check"

mypy ./
display_result $? 1 "Type check"

Expand Down
98 changes: 98 additions & 0 deletions tests/app/main/views/test_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -3679,3 +3679,101 @@ def test_correct_error_displayed(
elif error_shown == "none":
assert page.find(attrs={"data-testid": "exceeds-annual"}) is None
assert page.find(attrs={"data-testid": "exceeds-daily"}) is None

@pytest.mark.parametrize(
"notification_type, exception_msg_api, expected_error_msg_admin",
[
("email", "Exceeded annual email sending", "These messages exceed the annual limit"),
("sms", "Exceeded annual SMS sending", "These messages exceed the annual limit"),
],
)
def test_error_msgs_from_api_for_one_off(
self,
client_request,
service_one,
fake_uuid,
mocker,
mock_get_service_template_with_placeholders,
mock_get_template_statistics,
notification_type,
exception_msg_api,
expected_error_msg_admin,
):
class MockHTTPError(HTTPError):
message = exception_msg_api

mocker.patch(
"app.notification_api_client.send_notification",
side_effect=MockHTTPError(),
)

if notification_type == "sms":
with client_request.session_transaction() as session:
session["recipient"] = "6502532223"
session["placeholders"] = {"name": "a" * 600}
elif notification_type == "email":
with client_request.session_transaction() as session:
session["recipient"] = "[email protected]"
session["placeholders"] = {"name": "a" * 600}

page = client_request.post(
"main.send_notification",
service_id=service_one["id"],
template_id=fake_uuid,
_expected_status=200,
)

assert normalize_spaces(page.select("h1")[0].text) == expected_error_msg_admin

@pytest.mark.parametrize(
"exception_msg_api, expected_error_msg_admin",
[
# ("email","Exceeded annual email sending", "These messages exceed the annual limit"),
("Exceeded annual SMS sending", "These messages exceed the annual limit")
],
)
def test_error_msgs_from_api_for_bulk(
self,
client_request,
mock_create_job,
mock_get_job,
mock_get_notifications,
mock_get_service_template,
mock_get_service_data_retention,
mocker,
fake_uuid,
exception_msg_api,
expected_error_msg_admin,
):
class MockHTTPError(HTTPError):
message = exception_msg_api

data = mock_get_job(SERVICE_ONE_ID, fake_uuid)["data"]
job_id = data["id"]
original_file_name = data["original_file_name"]
template_id = data["template"]
notification_count = data["notification_count"]
with client_request.session_transaction() as session:
session["file_uploads"] = {
fake_uuid: {
"template_id": template_id,
"notification_count": notification_count,
"valid": True,
}
}

mocker.patch(
"app.job_api_client.create_job",
side_effect=MockHTTPError(),
)
page = client_request.post(
"main.start_job",
service_id=SERVICE_ONE_ID,
upload_id=job_id,
original_file_name=original_file_name,
_data={},
_follow_redirects=True,
_expected_status=200,
)

assert normalize_spaces(page.select("h1")[0].text) == expected_error_msg_admin

0 comments on commit cb63225

Please sign in to comment.