Use new Template method .is_message_empty()

This method has been now added to Template subclasses
used by sms, emails and letters, so we can use it to valdiate if
message is not empty.

Use new template method .is_message_empty()

Refactor function name and add a test
This commit is contained in:
Pea Tyczynska
2019-11-19 17:05:50 +00:00
parent 9c804f701b
commit f4ba82225b
2 changed files with 37 additions and 12 deletions

View File

@@ -121,8 +121,8 @@ def check_sms_content_char_count(content_count):
raise BadRequestError(message=message)
def check_if_notification_content_is_not_empty(template_with_content):
if len(template_with_content.__str__()) == 0:
def check_notification_content_is_not_empty(template_with_content):
if template_with_content.is_message_empty():
message = 'This message is empty.'
raise BadRequestError(message=message)
@@ -140,10 +140,12 @@ def validate_template(template_id, personalisation, service, notification_type):
check_template_is_for_notification_type(notification_type, template.template_type)
check_template_is_active(template)
template_with_content = create_content_for_notification(template, personalisation)
check_notification_content_is_not_empty(template_with_content)
if template.template_type == SMS_TYPE:
check_sms_content_char_count(template_with_content.content_count)
check_if_notification_content_is_not_empty(template_with_content)
return template, template_with_content