Skip to content

Commit

Permalink
Delineate between daily / annual limit csv validation
Browse files Browse the repository at this point in the history
  • Loading branch information
whabanks committed Dec 3, 2024
1 parent 25ef1ae commit 5fdb753
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/actions/waffles/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docopt==0.6.2
Flask==2.3.3
markupsafe==2.1.5
git+https://github.com/cds-snc/[email protected].0#egg=notifications-utils
git+https://github.com/cds-snc/[email protected].1#egg=notifications-utils
17 changes: 12 additions & 5 deletions notifications_utils/recipients.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def __init__(
max_initial_rows_shown=10,
safelist=None,
template=None,
remaining_messages=sys.maxsize,
remaining_daily_messages=sys.maxsize,
remaining_annual_messages=sys.maxsize,
international_sms=False,
max_rows=50000,
user_language="en",
Expand All @@ -103,7 +104,8 @@ def __init__(
self.safelist = safelist
self.template = template if isinstance(template, Template) else None
self.international_sms = international_sms
self.remaining_messages = remaining_messages
self.remaining_daily_messages = remaining_daily_messages
self.remaining_annual_messages = remaining_annual_messages
self.rows_as_list = None
self.max_rows = max_rows

Expand Down Expand Up @@ -162,7 +164,8 @@ def has_errors(self):
return bool(
self.missing_column_headers
or self.duplicate_recipient_column_headers
or self.more_rows_than_can_send
or self.more_rows_than_can_send_this_year
or self.more_rows_than_can_send_today
or self.too_many_rows
or (not self.allowed_to_send_to)
or any(self.rows_with_errors)
Expand Down Expand Up @@ -230,8 +233,12 @@ def get_rows(self):
yield None

@property
def more_rows_than_can_send(self):
return len(self) > self.remaining_messages
def more_rows_than_can_send_today(self):
return len(self) > self.remaining_daily_messages

@property
def more_rows_than_can_send_this_year(self):
return len(self) > self.remaining_annual_messages

@property
def sms_fragment_count(self):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "notifications-utils"
version = "52.4.0"
version = "52.4.1"
description = "Shared python code for Notification - Provides logging utils etc."
authors = ["Canadian Digital Service"]
license = "MIT license"
Expand Down
51 changes: 43 additions & 8 deletions tests/test_recipient_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,18 +873,18 @@ def test_ignores_leading_whitespace_in_file(character, name):
assert not recipients.has_errors


def test_error_if_too_many_email_recipients():
def test_error_if_too_many_email_recipients_for_year():
recipients = RecipientCSV(
"email address,\n[email protected],\n[email protected],\n[email protected],",
placeholders=["email_address"],
template_type="email",
remaining_messages=2,
remaining_annual_messages=2,
)
assert recipients.has_errors
assert recipients.more_rows_than_can_send
assert recipients.more_rows_than_can_send_this_year


def test_error_if_too_many_sms_recipients():
def test_error_if_too_many_sms_recipients_for_year():
recipients = RecipientCSV(
"phone number,\n6502532222,\n6502532222,\n6502532222,",
placeholders=["phone_number"],
Expand All @@ -894,18 +894,53 @@ def test_error_if_too_many_sms_recipients():
sender=None,
prefix=None,
),
remaining_messages=2,
remaining_annual_messages=2,
)
assert recipients.has_errors
assert recipients.more_rows_than_can_send
assert recipients.more_rows_than_can_send_this_year


def test_dont_error_if_too_many_recipients_not_specified():
def test_dont_error_if_too_many_recipients_not_specified_for_year():
recipients = RecipientCSV(
"phone number,\n6502532222,\n6502532222,\n6502532222,", placeholders=["phone_number"], template_type="sms"
)
assert not recipients.has_errors
assert not recipients.more_rows_than_can_send
assert not recipients.more_rows_than_can_send_this_year


def test_error_if_too_many_email_recipients_for_today():
recipients = RecipientCSV(
"email address,\n[email protected],\n[email protected],\n[email protected],",
placeholders=["email_address"],
template_type="email",
remaining_daily_messages=2,
)
assert recipients.has_errors
assert recipients.more_rows_than_can_send_today


def test_error_if_too_many_sms_recipients_for_today():
recipients = RecipientCSV(
"phone number,\n6502532222,\n6502532222,\n6502532222,",
placeholders=["phone_number"],
template_type="sms",
template=SMSMessageTemplate(
{"content": "test message", "template_type": "sms"},
sender=None,
prefix=None,
),
remaining_daily_messages=2,
)
assert recipients.has_errors
assert recipients.more_rows_than_can_send_today


def test_dont_error_if_too_many_recipients_not_specified_for_today():
recipients = RecipientCSV(
"phone number,\n6502532222,\n6502532222,\n6502532222,", placeholders=["phone_number"], template_type="sms"
)
assert not recipients.has_errors
assert not recipients.more_rows_than_can_send_today


@pytest.mark.parametrize(
Expand Down

0 comments on commit 5fdb753

Please sign in to comment.