Skip to content

Commit

Permalink
chore: formatting / refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleith committed Sep 14, 2023
1 parent 51003d5 commit 018ab39
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
15 changes: 5 additions & 10 deletions app/main/views/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
from flask_login import current_user
from markupsafe import Markup
from notifications_python_client.errors import HTTPError
from notifications_utils import (
EMAIL_CHAR_COUNT_LIMIT,
SMS_CHAR_COUNT_LIMIT,
TEMPLATE_NAME_CHAR_COUNT_LIMIT,
)
from notifications_utils import TEMPLATE_NAME_CHAR_COUNT_LIMIT
from notifications_utils.formatters import nl2br
from notifications_utils.recipients import first_column_headings

Expand Down Expand Up @@ -109,8 +105,7 @@ def delete_preview_data(service_id, template_id=None):
redis_client.delete(key)


def get_char_limit_error_msg(template_type):
CHAR_LIMIT = SMS_CHAR_COUNT_LIMIT if template_type == "sms" else EMAIL_CHAR_COUNT_LIMIT
def get_char_limit_error_msg():
return _("Too many characters")


Expand Down Expand Up @@ -192,7 +187,7 @@ def preview_template(service_id, template_id=None):
except HTTPError as e:
if e.status_code == 400:
if "content" in e.message and any(["character count greater than" in x for x in e.message["content"]]):
error_message = get_char_limit_error_msg(template["template_type"])
error_message = get_char_limit_error_msg()
flash(error_message)
elif "name" in e.message and any(["Template name must be less than" in x for x in e.message["name"]]):
error_message = (_("Template name must be less than {char_limit} characters")).format(
Expand Down Expand Up @@ -758,7 +753,7 @@ def add_service_template(service_id, template_type, template_folder_id=None):
and "content" in e.message
and any(["character count greater than" in x for x in e.message["content"]])
):
error_message = get_char_limit_error_msg(template_type)
error_message = get_char_limit_error_msg()
form.template_content.errors.extend([error_message])
elif "name" in e.message and any(["Template name must be less than" in x for x in e.message["name"]]):
error_message = (_("Template name must be less than {char_limit} characters")).format(
Expand Down Expand Up @@ -886,7 +881,7 @@ def edit_service_template(service_id, template_id):
except HTTPError as e:
if e.status_code == 400:
if "content" in e.message and any(["character count greater than" in x for x in e.message["content"]]):
error_message = get_char_limit_error_msg(template["template_type"])
error_message = get_char_limit_error_msg()
form.template_content.errors.extend([error_message])
elif "name" in e.message and any(["Template name must be less than" in x for x in e.message["name"]]):
error_message = (_("Template name must be less than {char_limit} characters")).format(
Expand Down
3 changes: 1 addition & 2 deletions tests/app/main/views/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,8 +1400,7 @@ def test_dashboard_daily_limits(
assert page.find_all(class_="remaining-messages")[component_index].find(class_="rm-used").text == expected_sent
assert page.find_all(class_="remaining-messages")[component_index].find(class_="rm-total").text[3:] == expected_limit
assert (
expected_color
in page.find_all(class_="remaining-messages")[component_index].find(class_="rm-bar-usage").attrs["class"]
expected_color in page.find_all(class_="remaining-messages")[component_index].find(class_="rm-bar-usage").attrs["class"]
)

if expect_accessible_message:
Expand Down

0 comments on commit 018ab39

Please sign in to comment.