Rename check_character_count method to check_is_message_to_long.

Add different error message for email and text if content is too long.
Use utils version with is_message_too_long method implemented for email templates.
This commit is contained in:
Rebecca Law
2020-11-09 15:19:00 +00:00
parent 5bacfc1df9
commit 171bc74c69
6 changed files with 52 additions and 26 deletions

View File

@@ -143,10 +143,19 @@ def check_if_service_can_send_to_number(service, number):
return international_phone_info
def check_content_char_count(template_with_content):
def check_is_message_too_long(template_with_content):
if template_with_content.is_message_too_long():
message = f"Text messages cannot be longer than {SMS_CHAR_COUNT_LIMIT} characters. " \
f"Your message is {template_with_content.content_count_without_prefix} characters"
message = "Your message is too long. "
if template_with_content.template_type == SMS_TYPE:
message += (
f"Text messages cannot be longer than {SMS_CHAR_COUNT_LIMIT} characters. "
f"Your message is {template_with_content.content_count_without_prefix} characters long."
)
elif template_with_content.template_type == EMAIL_TYPE:
message += (
f"Emails cannot be longer than 1000000 bytes. "
f"Your message is {template_with_content.content_size_in_bytes} bytes."
)
raise BadRequestError(message=message)
@@ -175,7 +184,7 @@ def validate_template(template_id, personalisation, service, notification_type,
# which means the length of the message can be exceeded because it's including the file.
# The document download feature is only available through the api.
if check_char_count:
check_content_char_count(template_with_content)
check_is_message_too_long(template_with_content)
return template, template_with_content

View File

@@ -52,7 +52,7 @@ from app.notifications.validators import (
validate_address,
validate_and_format_recipient,
validate_template,
check_content_char_count)
check_is_message_too_long)
from app.schema_validation import validate
from app.v2.errors import BadRequestError
from app.v2.notifications.create_response import (
@@ -191,7 +191,7 @@ def process_sms_or_email_notification(
template_with_content.values = personalisation
# validate content length after url is replaced in personalisation.
check_content_char_count(template_with_content)
check_is_message_too_long(template_with_content)
resp = create_response_for_post_notification(
notification_id=notification_id,