Skip to content

Commit

Permalink
Merge pull request #54 from cds-snc/max-rows
Browse files Browse the repository at this point in the history
Allow max rows to be set from the outside
  • Loading branch information
smcmurtry committed May 27, 2020
2 parents b853e3e + d383758 commit 7fe6803
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions notifications_utils/recipients.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@

class RecipientCSV():

max_rows = 50000

def __init__(
self,
file_data,
Expand All @@ -61,6 +59,7 @@ def __init__(
template=None,
remaining_messages=sys.maxsize,
international_sms=False,
max_rows=50000,
):
self.file_data = strip_whitespace(file_data, extra_characters=',')
self.template_type = template_type
Expand All @@ -72,6 +71,7 @@ def __init__(
self.international_sms = international_sms
self.remaining_messages = remaining_messages
self.rows_as_list = None
self.max_rows = max_rows

def __len__(self):
if not hasattr(self, '_len'):
Expand Down
2 changes: 1 addition & 1 deletion notifications_utils/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '42.1.3'
__version__ = '42.1.4'
# GDS version '34.0.1'
10 changes: 5 additions & 5 deletions tests/test_recipient_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def test_big_list_validates_right_through(template_type, row_count, header, fill

def test_big_list():
big_csv = RecipientCSV(
"email address,name\n" + ("a@b.com\n" * RecipientCSV.max_rows),
"email address,name\n" + ("a@b.com\n" * 50000),
template_type='email',
placeholders=['name'],
max_errors_shown=100,
Expand All @@ -327,13 +327,13 @@ def test_big_list():
)
assert len(list(big_csv.initial_rows)) == 3
assert len(list(big_csv.initial_rows_with_errors)) == 100
assert len(list(big_csv.rows)) == RecipientCSV.max_rows
assert len(list(big_csv.rows)) == big_csv.max_rows
assert big_csv.has_errors


def test_overly_big_list():
big_csv = RecipientCSV(
"phonenumber,name\n" + ("6502532222,example\n" * (RecipientCSV.max_rows + 1)),
"phonenumber,name\n" + ("6502532222,example\n" * 50001),
template_type='sms',
placeholders=['name'],
)
Expand Down Expand Up @@ -644,10 +644,10 @@ def test_international_recipients(file_contents, rows_with_bad_recipients):

def test_errors_when_too_many_rows():
recipients = RecipientCSV(
"email address\n" + ("a@b.com\n" * (RecipientCSV.max_rows + 1)),
"email address\n" + ("a@b.com\n" * (50001)),
template_type='email'
)
assert RecipientCSV.max_rows == 50000
assert recipients.max_rows == 50000
assert recipients.too_many_rows is True
assert recipients.has_errors is True
assert recipients.rows[49000]['email_address'].data == 'a@b.com'
Expand Down

0 comments on commit 7fe6803

Please sign in to comment.