mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04:00
Use new value of SMS_CHAR_COUNT_LIMIT from utils
Admin, API and utils were all defining a value for SMS_CHAR_COUNT_LIMIT. This value has been updated in notifications-utils to allow text messages to be 4 fragments long and notifications-api now gets the value of SMS_CHAR_COUNT_LIMIT from notifications-utils instead of defining it in config. Also updated some tests to check for the higher limit.
This commit is contained in:
@@ -126,7 +126,6 @@ class Config(object):
|
||||
SQLALCHEMY_POOL_RECYCLE = 300
|
||||
PAGE_SIZE = 50
|
||||
API_PAGE_SIZE = 250
|
||||
SMS_CHAR_COUNT_LIMIT = 495
|
||||
TEST_MESSAGE_FILENAME = 'Test message'
|
||||
ONE_OFF_MESSAGE_FILENAME = 'Report'
|
||||
MAX_VERIFY_CODE_COUNT = 10
|
||||
|
||||
@@ -39,6 +39,7 @@ from app.schemas import (
|
||||
from app.service.utils import service_allowed_to_send_to
|
||||
from app.utils import pagination_links, get_template_instance, get_public_notify_type_text
|
||||
|
||||
from notifications_utils import SMS_CHAR_COUNT_LIMIT
|
||||
from notifications_utils.recipients import get_international_phone_info
|
||||
|
||||
notifications = Blueprint('notifications', __name__)
|
||||
@@ -198,10 +199,9 @@ def create_template_object_for_notification(template, personalisation):
|
||||
|
||||
if (
|
||||
template_object.template_type == SMS_TYPE and
|
||||
template_object.content_count > current_app.config.get('SMS_CHAR_COUNT_LIMIT')
|
||||
template_object.content_count > SMS_CHAR_COUNT_LIMIT
|
||||
):
|
||||
char_count = current_app.config.get('SMS_CHAR_COUNT_LIMIT')
|
||||
message = 'Content has a character count greater than the limit of {}'.format(char_count)
|
||||
message = 'Content has a character count greater than the limit of {}'.format(SMS_CHAR_COUNT_LIMIT)
|
||||
errors = {'content': [message]}
|
||||
raise InvalidRequest(errors, status_code=400)
|
||||
return template_object
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from flask import current_app
|
||||
from notifications_utils import SMS_CHAR_COUNT_LIMIT
|
||||
from notifications_utils.recipients import (
|
||||
validate_and_format_phone_number,
|
||||
validate_and_format_email_address,
|
||||
@@ -115,9 +116,8 @@ def validate_and_format_recipient(send_to, key_type, service, notification_type,
|
||||
|
||||
|
||||
def check_sms_content_char_count(content_count):
|
||||
char_count_limit = current_app.config.get('SMS_CHAR_COUNT_LIMIT')
|
||||
if content_count > char_count_limit:
|
||||
message = 'Content for template has a character count greater than the limit of {}'.format(char_count_limit)
|
||||
if content_count > SMS_CHAR_COUNT_LIMIT:
|
||||
message = 'Content for template has a character count greater than the limit of {}'.format(SMS_CHAR_COUNT_LIMIT)
|
||||
raise BadRequestError(message=message)
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ from flask import (
|
||||
current_app,
|
||||
jsonify,
|
||||
request)
|
||||
from notifications_utils import SMS_CHAR_COUNT_LIMIT
|
||||
from notifications_utils.pdf import extract_page_from_pdf
|
||||
from notifications_utils.template import SMSMessageTemplate
|
||||
from requests import post as requests_post
|
||||
@@ -42,7 +43,7 @@ def _content_count_greater_than_limit(content, template_type):
|
||||
if template_type != SMS_TYPE:
|
||||
return False
|
||||
template = SMSMessageTemplate({'content': content, 'template_type': template_type})
|
||||
return template.content_count > current_app.config.get('SMS_CHAR_COUNT_LIMIT')
|
||||
return template.content_count > SMS_CHAR_COUNT_LIMIT
|
||||
|
||||
|
||||
@template_blueprint.route('', methods=['POST'])
|
||||
@@ -61,8 +62,7 @@ def create_template(service_id):
|
||||
new_template.service = fetched_service
|
||||
over_limit = _content_count_greater_than_limit(new_template.content, new_template.template_type)
|
||||
if over_limit:
|
||||
char_count_limit = current_app.config.get('SMS_CHAR_COUNT_LIMIT')
|
||||
message = 'Content has a character count greater than the limit of {}'.format(char_count_limit)
|
||||
message = 'Content has a character count greater than the limit of {}'.format(SMS_CHAR_COUNT_LIMIT)
|
||||
errors = {'content': [message]}
|
||||
raise InvalidRequest(errors, status_code=400)
|
||||
|
||||
@@ -104,8 +104,7 @@ def update_template(service_id, template_id):
|
||||
|
||||
over_limit = _content_count_greater_than_limit(updated_template['content'], fetched_template.template_type)
|
||||
if over_limit:
|
||||
char_count_limit = current_app.config.get('SMS_CHAR_COUNT_LIMIT')
|
||||
message = 'Content has a character count greater than the limit of {}'.format(char_count_limit)
|
||||
message = 'Content has a character count greater than the limit of {}'.format(SMS_CHAR_COUNT_LIMIT)
|
||||
errors = {'content': [message]}
|
||||
raise InvalidRequest(errors, status_code=400)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user