mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 01:11:38 -05:00
As it turns out the s3ftp used to mount the s3 bucket to our ftp server puts the file on s3 more than once. So the SNS topic is triggered more than once.
We need to deal with this, it's ok when updating a notification status from delivered to delivered. But the DailySortedLetter counts are being doubled. Adding the file_name to the table as a unique key to get around this issue. It will mean we have multiple rows for each billing_day, but that's ok we can aggregate that. This will also give us a way to see which file created which count.
This commit is contained in:
@@ -208,7 +208,9 @@ def test_update_letter_notifications_statuses_persists_daily_sorted_letter_count
|
||||
|
||||
update_letter_notifications_statuses(filename='NOTIFY-20170823160812-RSP.TXT')
|
||||
|
||||
persist_letter_count_mock.assert_called_once_with(date(2017, 8, 23), {'Unsorted': 1, 'Sorted': 1})
|
||||
persist_letter_count_mock.assert_called_once_with(day=date(2017, 8, 23),
|
||||
file_name='NOTIFY-20170823160812-RSP.TXT',
|
||||
sorted_letter_counts={'Unsorted': 1, 'Sorted': 1})
|
||||
|
||||
|
||||
def test_update_letter_notifications_statuses_persists_daily_sorted_letter_count_with_no_sorted_values(
|
||||
@@ -329,7 +331,7 @@ def test_get_billing_date_in_bst_from_filename(filename_date, billing_date):
|
||||
@freeze_time("2018-01-11 09:00:00")
|
||||
def test_persist_daily_sorted_letter_counts_saves_sorted_and_unsorted_values(client, notify_db_session):
|
||||
letter_counts = defaultdict(int, **{'Unsorted': 5, 'Sorted': 1})
|
||||
persist_daily_sorted_letter_counts(date.today(), letter_counts)
|
||||
persist_daily_sorted_letter_counts(date.today(), "test.txt", letter_counts)
|
||||
day = dao_get_daily_sorted_letter_by_billing_day(date.today())
|
||||
|
||||
assert day.unsorted_count == 5
|
||||
|
||||
@@ -20,7 +20,10 @@ def test_dao_get_daily_sorted_letter_by_billing_day(notify_db, notify_db_session
|
||||
|
||||
def test_dao_create_or_update_daily_sorted_letter_creates_a_new_entry(notify_db, notify_db_session):
|
||||
billing_day = date(2018, 2, 1)
|
||||
dsl = DailySortedLetter(billing_day=billing_day, unsorted_count=2, sorted_count=0)
|
||||
dsl = DailySortedLetter(billing_day=billing_day,
|
||||
file_name="Notify-201802011234.rs.txt",
|
||||
unsorted_count=2,
|
||||
sorted_count=0)
|
||||
dao_create_or_update_daily_sorted_letter(dsl)
|
||||
|
||||
daily_sorted_letter = dao_get_daily_sorted_letter_by_billing_day(billing_day)
|
||||
@@ -35,13 +38,19 @@ def test_dao_create_or_update_daily_sorted_letter_updates_an_existing_entry(
|
||||
notify_db,
|
||||
notify_db_session
|
||||
):
|
||||
create_daily_sorted_letter(unsorted_count=2, sorted_count=3)
|
||||
create_daily_sorted_letter(billing_day=date(2018, 1, 18),
|
||||
file_name="Notify-20180118123.rs.txt",
|
||||
unsorted_count=2,
|
||||
sorted_count=3)
|
||||
|
||||
dsl = DailySortedLetter(billing_day=date(2018, 1, 18), unsorted_count=5, sorted_count=17)
|
||||
dsl = DailySortedLetter(billing_day=date(2018, 1, 18),
|
||||
file_name="Notify-20180118123.rs.txt",
|
||||
unsorted_count=5,
|
||||
sorted_count=17)
|
||||
dao_create_or_update_daily_sorted_letter(dsl)
|
||||
|
||||
daily_sorted_letter = dao_get_daily_sorted_letter_by_billing_day(dsl.billing_day)
|
||||
|
||||
assert daily_sorted_letter.unsorted_count == 7
|
||||
assert daily_sorted_letter.sorted_count == 20
|
||||
assert daily_sorted_letter.unsorted_count == 5
|
||||
assert daily_sorted_letter.sorted_count == 17
|
||||
assert daily_sorted_letter.updated_at
|
||||
|
||||
@@ -509,9 +509,13 @@ def create_invited_org_user(organisation, invited_by, email_address='invite@exam
|
||||
return invited_org_user
|
||||
|
||||
|
||||
def create_daily_sorted_letter(billing_day=date(2018, 1, 18), unsorted_count=0, sorted_count=0):
|
||||
def create_daily_sorted_letter(billing_day=date(2018, 1, 18),
|
||||
file_name="Notify-20180118123.rs.txt",
|
||||
unsorted_count=0,
|
||||
sorted_count=0):
|
||||
daily_sorted_letter = DailySortedLetter(
|
||||
billing_day=billing_day,
|
||||
file_name=file_name,
|
||||
unsorted_count=unsorted_count,
|
||||
sorted_count=sorted_count
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user