def persist_daily_sorted_letter_counts(day, file_name, sorted_letter_counts): daily_letter_count = DailySortedLetter( billing_day=day, file_name=file_name, unsorted_count=sorted_letter_counts['unsorted'], sorted_count=sorted_letter_counts['sorted']) dao_create_or_update_daily_sorted_letter(daily_letter_count)
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) db.session.add(daily_sorted_letter) db.session.commit() return daily_sorted_letter
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, 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) assert daily_sorted_letter.billing_day == billing_day assert daily_sorted_letter.unsorted_count == 2 assert daily_sorted_letter.sorted_count == 0 assert not daily_sorted_letter.updated_at
def test_dao_create_or_update_daily_sorted_letter_updates_an_existing_entry( notify_db, notify_db_session): 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), 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 == 5 assert daily_sorted_letter.sorted_count == 17 assert daily_sorted_letter.updated_at