Skip to content

Commit 6b24be4

Browse files
authored
Add error message for rows_with_combined_variable_content_too_long (#2160)
* Add error message for rows_with_combined_variable_content_too_long * Fix tests - Bump Waffles version - Bump Utils version
1 parent a049ee2 commit 6b24be4

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
run: |
6868
cp -f .env.example .env
6969
- name: Checks for new endpoints against AWS WAF rules
70-
uses: cds-snc/notification-utils/.github/actions/waffles@06a40db6286f525fe3551e029418458d33342592 # 52.1.0
70+
uses: cds-snc/notification-utils/.github/actions/waffles@4e204b1ec688961ae32c3a6646246c58a1c1bc4f # 52.1.10
7171
with:
7272
app-loc: '/github/workspace'
7373
app-libs: '/github/workspace/env/site-packages'

app/v2/notifications/post_notifications.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import werkzeug
99
from flask import abort, current_app, jsonify, request
10+
from notifications_utils import SMS_CHAR_COUNT_LIMIT
1011
from notifications_utils.recipients import (
1112
RecipientCSV,
1213
try_validate_and_format_phone_number,
@@ -699,6 +700,12 @@ def check_for_csv_errors(recipient_csv, max_rows, remaining_messages):
699700
message=f"You cannot send to these recipients {explanation}",
700701
status_code=400,
701702
)
703+
if any(recipient_csv.rows_with_combined_variable_content_too_long):
704+
raise BadRequestError(
705+
message=f"Row {next(recipient_csv.rows_with_combined_variable_content_too_long).index + 1} - has a character count greater than {SMS_CHAR_COUNT_LIMIT} characters. Some messages may be too long due to custom content.",
706+
status_code=400,
707+
)
708+
702709
if recipient_csv.rows_with_errors:
703710

704711
def row_error(row):

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Werkzeug = "2.3.7"
6464
MarkupSafe = "2.1.4"
6565
# REVIEW: v2 is using sha512 instead of sha1 by default (in v1)
6666
itsdangerous = "2.1.2"
67-
notifications-utils = { git = "https://github.com/cds-snc/notifier-utils.git", tag = "52.1.5" }
67+
notifications-utils = { git = "https://github.com/cds-snc/notifier-utils.git", tag = "52.1.10" }
6868
# rsa = "4.9 # awscli 1.22.38 depends on rsa<4.8
6969
typing-extensions = "4.7.1"
7070
greenlet = "2.0.2"

tests/app/celery/test_tasks.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import uuid
33
from datetime import datetime, timedelta
44
from unittest import mock
5-
from unittest.mock import Mock, call
5+
from unittest.mock import MagicMock, Mock, call
66

77
import pytest
88
import requests_mock
@@ -891,9 +891,10 @@ def test_process_rows_sends_save_task(
891891
mocker.patch("app.celery.tasks.create_uuid", return_value="noti_uuid")
892892
task_mock = mocker.patch("app.celery.tasks.{}".format(expected_function))
893893
signer_mock = mocker.patch("app.celery.tasks.signer_notification.sign")
894-
template = Mock(id="template_id", template_type=template_type, process_type=NORMAL)
894+
template = MagicMock(id="template_id", template_type=template_type, process_type=NORMAL)
895895
job = Mock(id="job_id", template_version="temp_vers", notification_count=1, api_key_id=api_key_id, sender_id=sender_id)
896896
service = Mock(id="service_id", research_mode=research_mode)
897+
template.__len__.return_value = 1
897898

898899
process_rows(
899900
[
@@ -950,10 +951,11 @@ def test_should_redirect_email_job_to_queue_depending_on_csv_threshold(
950951
):
951952
mock_save_email = mocker.patch("app.celery.tasks.save_emails")
952953

953-
template = Mock(id=1, template_type=EMAIL_TYPE, process_type=template_process_type)
954+
template = MagicMock(id=1, template_type=EMAIL_TYPE, process_type=template_process_type)
954955
api_key = Mock(id=1, key_type=KEY_TYPE_NORMAL)
955956
job = Mock(id=1, template_version="temp_vers", notification_count=1, api_key=api_key)
956957
service = Mock(id=1, research_mode=False)
958+
template.__len__.return_value = 1
957959

958960
row = next(
959961
RecipientCSV(
@@ -994,10 +996,11 @@ def test_should_redirect_sms_job_to_queue_depending_on_csv_threshold(
994996
):
995997
mock_save_sms = mocker.patch("app.celery.tasks.save_smss")
996998

997-
template = Mock(id=1, template_type=SMS_TYPE, process_type=template_process_type)
999+
template = MagicMock(id=1, template_type=SMS_TYPE, process_type=template_process_type)
9981000
api_key = Mock(id=1, key_type=KEY_TYPE_NORMAL)
9991001
job = Mock(id=1, template_version="temp_vers", notification_count=1, api_key=api_key)
10001002
service = Mock(id=1, research_mode=False)
1003+
template.__len__.return_value = 1
10011004

10021005
row = next(
10031006
RecipientCSV(
@@ -1066,7 +1069,8 @@ def test_process_rows_works_without_key_type(
10661069
mocker.patch("app.celery.tasks.create_uuid", return_value="noti_uuid")
10671070
task_mock = mocker.patch("app.celery.tasks.{}".format(expected_function))
10681071
signer_mock = mocker.patch("app.celery.tasks.signer_notification.sign")
1069-
template = Mock(id="template_id", template_type=template_type, process_type=NORMAL)
1072+
template = MagicMock(id="template_id", template_type=template_type, process_type=NORMAL)
1073+
template.__len__.return_value = 1
10701074
api_key = {}
10711075
job = Mock(
10721076
id="job_id",

tests/app/v2/notifications/test_post_notifications.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,7 @@ def test_post_bulk_with_too_large_sms_fails(self, client, notify_db, notify_db_s
24952495
mocker.patch("app.v2.notifications.post_notifications.create_bulk_job", return_value=str(uuid.uuid4()))
24962496

24972497
service = create_service(sms_daily_limit=10, message_limit=100)
2498-
template = create_sample_template(notify_db, notify_db_session, service=service, template_type="sms", content="a" * 612)
2498+
template = create_sample_template(notify_db, notify_db_session, service=service, template_type="sms", content="a" * 613)
24992499
data = {
25002500
"name": "job_name",
25012501
"template_id": template.id,
@@ -2546,7 +2546,7 @@ def test_post_bulk_with_too_large_sms_fail_and_shows_correct_row(
25462546
)
25472547
assert response.status_code == 400
25482548
assert "has a character count greater than" in str(response.data)
2549-
assert "row #{}".format(failure_row) in str(response.data)
2549+
assert "Row {}".format(failure_row) in str(response.data)
25502550

25512551

25522552
class TestBatchPriorityLanes:

0 commit comments

Comments
 (0)