From 9e7ee1c0f8546a894bfb297dc326c6cf72968ace Mon Sep 17 00:00:00 2001 From: stvnrlly Date: Mon, 21 Nov 2022 11:49:59 -0500 Subject: [PATCH] migrate bst_date to local_date --- app/celery/nightly_tasks.py | 2 +- app/dao/fact_billing_dao.py | 100 +++++++------- app/dao/fact_notification_status_dao.py | 58 ++++---- app/dao/fact_processing_time_dao.py | 12 +- app/dao/notifications_dao.py | 4 +- app/dao/provider_details_dao.py | 2 +- app/dao/services_dao.py | 4 +- app/letters/utils.py | 4 +- app/models.py | 6 +- app/performance_dashboard/rest.py | 2 +- app/performance_platform/processing_time.py | 10 +- app/platform_stats/rest.py | 4 +- migrations/versions/0174_add_billing_facts.py | 16 +-- .../versions/0179_billing_primary_const.py | 4 +- .../versions/0181_billing_primary_key.py | 4 +- migrations/versions/0183_alter_primary_key.py | 8 +- .../versions/0184_alter_primary_key_1.py | 4 +- .../0188_add_ft_notification_status.py | 8 +- migrations/versions/0191_ft_billing_pkey.py | 4 +- migrations/versions/0235_add_postage_to_pk.py | 4 +- .../versions/0307_delete_dm_datetime.py | 8 +- .../versions/0349_add_ft_processing_time.py | 8 +- .../versions/0371_fix_apr_2022_sms_rate.py | 4 +- tests/app/billing/test_rest.py | 12 +- tests/app/celery/test_nightly_tasks.py | 4 +- tests/app/celery/test_reporting_tasks.py | 34 ++--- .../notification_dao/test_notification_dao.py | 2 +- .../test_notification_dao_template_usage.py | 6 +- tests/app/dao/test_fact_billing_dao.py | 126 +++++++++--------- .../dao/test_fact_notification_status_dao.py | 32 ++--- .../app/dao/test_fact_processing_time_dao.py | 18 +-- tests/app/dao/test_services_dao.py | 12 +- tests/app/db.py | 48 +++---- tests/app/job/test_rest.py | 2 +- tests/app/organisation/test_rest.py | 4 +- tests/app/performance_dashboard/test_rest.py | 32 ++--- tests/app/service/test_rest.py | 10 +- tests/app/service/test_statistics_rest.py | 6 +- tests/app/template_statistics/test_rest.py | 2 +- 39 files changed, 315 insertions(+), 315 deletions(-) diff --git a/app/celery/nightly_tasks.py b/app/celery/nightly_tasks.py index 5437422c0..743bceb82 100644 --- a/app/celery/nightly_tasks.py +++ b/app/celery/nightly_tasks.py @@ -304,7 +304,7 @@ def save_daily_notification_processing_time(est_date=None): result = dao_get_notifications_processing_time_stats(start_time, end_time) insert_update_processing_time( FactProcessingTime( - bst_date=est_date, + local_date=est_date, messages_total=result.messages_total, messages_within_10_secs=result.messages_within_10_secs ) diff --git a/app/dao/fact_billing_dao.py b/app/dao/fact_billing_dao.py index 32c9ed450..3175665e1 100644 --- a/app/dao/fact_billing_dao.py +++ b/app/dao/fact_billing_dao.py @@ -51,8 +51,8 @@ def fetch_sms_free_allowance_remainder_until_date(end_date): # free_sms_fragment_limit) FactBilling, and_( AnnualBilling.service_id == FactBilling.service_id, - FactBilling.bst_date >= start_of_year, - FactBilling.bst_date < end_date, + FactBilling.local_date >= start_of_year, + FactBilling.local_date < end_date, FactBilling.notification_type == SMS_TYPE, ) ).filter( @@ -101,8 +101,8 @@ def fetch_sms_billing_for_all_services(start_date, end_date): ).join( FactBilling, FactBilling.service_id == Service.id, ).filter( - FactBilling.bst_date >= start_date, - FactBilling.bst_date <= end_date, + FactBilling.local_date >= start_date, + FactBilling.local_date <= end_date, FactBilling.notification_type == SMS_TYPE, ).group_by( Organisation.name, @@ -136,8 +136,8 @@ def fetch_letter_costs_and_totals_for_all_services(start_date, end_date): FactBilling, FactBilling.service_id == Service.id, ).filter( FactBilling.service_id == Service.id, - FactBilling.bst_date >= start_date, - FactBilling.bst_date <= end_date, + FactBilling.local_date >= start_date, + FactBilling.local_date <= end_date, FactBilling.notification_type == LETTER_TYPE, ).group_by( Organisation.name, @@ -179,8 +179,8 @@ def fetch_letter_line_items_for_all_services(start_date, end_date): ).join( FactBilling, FactBilling.service_id == Service.id, ).filter( - FactBilling.bst_date >= start_date, - FactBilling.bst_date <= end_date, + FactBilling.local_date >= start_date, + FactBilling.local_date <= end_date, FactBilling.notification_type == LETTER_TYPE, ).group_by( Organisation.name, @@ -277,7 +277,7 @@ def fetch_monthly_billing_for_year(service_id, year): query.c.rate.label("rate"), query.c.notification_type.label("notification_type"), query.c.postage.label("postage"), - func.date_trunc('month', query.c.bst_date).cast(Date).label("month"), + func.date_trunc('month', query.c.local_date).cast(Date).label("month"), func.sum(query.c.notifications_sent).label("notifications_sent"), func.sum(query.c.chargeable_units).label("chargeable_units"), @@ -307,7 +307,7 @@ def query_service_email_usage_for_year(service_id, year): year_start, year_end = get_financial_year_dates(year) return db.session.query( - FactBilling.bst_date, + FactBilling.local_date, FactBilling.postage, # should always be "none" FactBilling.notifications_sent, FactBilling.billable_units.label("chargeable_units"), @@ -318,8 +318,8 @@ def query_service_email_usage_for_year(service_id, year): FactBilling.billable_units.label("charged_units"), ).filter( FactBilling.service_id == service_id, - FactBilling.bst_date >= year_start, - FactBilling.bst_date <= year_end, + FactBilling.local_date >= year_start, + FactBilling.local_date <= year_end, FactBilling.notification_type == EMAIL_TYPE ) @@ -328,7 +328,7 @@ def query_service_letter_usage_for_year(service_id, year): year_start, year_end = get_financial_year_dates(year) return db.session.query( - FactBilling.bst_date, + FactBilling.local_date, FactBilling.postage, FactBilling.notifications_sent, # We can't use billable_units here as it represents the @@ -342,8 +342,8 @@ def query_service_letter_usage_for_year(service_id, year): FactBilling.notifications_sent.label("charged_units"), ).filter( FactBilling.service_id == service_id, - FactBilling.bst_date >= year_start, - FactBilling.bst_date <= year_end, + FactBilling.local_date >= year_start, + FactBilling.local_date <= year_end, FactBilling.notification_type == LETTER_TYPE ) @@ -354,7 +354,7 @@ def query_service_sms_usage_for_year(service_id, year): incorporating the SMS free allowance e.g. ( - bst_date=2022-04-27, + local_date=2022-04-27, notifications_sent=12, chargeable_units=12, rate=0.0165, @@ -365,7 +365,7 @@ def query_service_sms_usage_for_year(service_id, year): ) In order to calculate how much free allowance is left, we need to work out - how much was used for previous bst_dates - cumulative_chargeable_units - + how much was used for previous local_dates - cumulative_chargeable_units - which we then subtract from the free allowance for the year. cumulative_chargeable_units is calculated using a "window" clause, which has @@ -375,7 +375,7 @@ def query_service_sms_usage_for_year(service_id, year): https://www.postgresql.org/docs/current/tutorial-window.html ASSUMPTION: rates always change at midnight i.e. there can only be one rate - on a given bst_date. This means we don't need to worry about how to assign + on a given local_date. This means we don't need to worry about how to assign free allowance if it happens to run out when a rate changes. """ year_start, year_end = get_financial_year_dates(year) @@ -388,7 +388,7 @@ def query_service_sms_usage_for_year(service_id, year): chargeable_units_used_before_this_row = func.coalesce( func.sum(this_rows_chargeable_units).over( # order is "ASC" by default - order_by=[FactBilling.bst_date], + order_by=[FactBilling.local_date], # first row to previous row rows=(None, -1) ).cast(Integer), @@ -409,7 +409,7 @@ def query_service_sms_usage_for_year(service_id, year): free_allowance_used = func.least(remaining_free_allowance_before_this_row, this_rows_chargeable_units) return db.session.query( - FactBilling.bst_date, + FactBilling.local_date, FactBilling.postage, # should always be "none" FactBilling.notifications_sent, this_rows_chargeable_units.label("chargeable_units"), @@ -423,8 +423,8 @@ def query_service_sms_usage_for_year(service_id, year): AnnualBilling.service_id == service_id ).filter( FactBilling.service_id == service_id, - FactBilling.bst_date >= year_start, - FactBilling.bst_date <= year_end, + FactBilling.local_date >= year_start, + FactBilling.local_date <= year_end, FactBilling.notification_type == SMS_TYPE, AnnualBilling.financial_year_start == year, ) @@ -432,12 +432,12 @@ def query_service_sms_usage_for_year(service_id, year): def delete_billing_data_for_service_for_day(process_day, service_id): """ - Delete all ft_billing data for a given service on a given bst_date + Delete all ft_billing data for a given service on a given local_date Returns how many rows were deleted """ return FactBilling.query.filter( - FactBilling.bst_date == process_day, + FactBilling.local_date == process_day, FactBilling.service_id == service_id ).delete() @@ -628,7 +628,7 @@ def update_fact_billing(data, process_day): http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#insert-on-conflict-upsert ''' stmt = insert(table).values( - bst_date=billing_record.bst_date, + local_date=billing_record.local_date, template_id=billing_record.template_id, service_id=billing_record.service_id, provider=billing_record.provider, @@ -654,7 +654,7 @@ def update_fact_billing(data, process_day): def create_billing_record(data, rate, process_day): billing_record = FactBilling( - bst_date=process_day, + local_date=process_day, template_id=data.template_id, service_id=data.service_id, notification_type=data.notification_type, @@ -679,8 +679,8 @@ def fetch_letter_costs_for_organisation(organisation_id, start_date, end_date): ).join( FactBilling, FactBilling.service_id == Service.id, ).filter( - FactBilling.bst_date >= start_date, - FactBilling.bst_date <= end_date, + FactBilling.local_date >= start_date, + FactBilling.local_date <= end_date, FactBilling.notification_type == LETTER_TYPE, Service.organisation_id == organisation_id, Service.restricted.is_(False) @@ -704,8 +704,8 @@ def fetch_email_usage_for_organisation(organisation_id, start_date, end_date): ).join( FactBilling, FactBilling.service_id == Service.id, ).filter( - FactBilling.bst_date >= start_date, - FactBilling.bst_date <= end_date, + FactBilling.local_date >= start_date, + FactBilling.local_date <= end_date, FactBilling.notification_type == EMAIL_TYPE, Service.organisation_id == organisation_id, Service.restricted.is_(False) @@ -773,7 +773,7 @@ def query_organisation_sms_usage_for_year(organisation_id, year): chargeable_units_used_before_this_row = func.coalesce( func.sum(this_rows_chargeable_units).over( # order is "ASC" by default - order_by=[FactBilling.bst_date], + order_by=[FactBilling.local_date], # partition by service id partition_by=FactBilling.service_id, @@ -797,7 +797,7 @@ def query_organisation_sms_usage_for_year(organisation_id, year): return db.session.query( Service.id.label('service_id'), - FactBilling.bst_date, + FactBilling.local_date, this_rows_chargeable_units.label("chargeable_units"), (charged_units * FactBilling.rate).label("cost"), charged_units.label("charged_units"), @@ -808,8 +808,8 @@ def query_organisation_sms_usage_for_year(organisation_id, year): FactBilling, and_( Service.id == FactBilling.service_id, - FactBilling.bst_date >= year_start, - FactBilling.bst_date <= year_end, + FactBilling.local_date >= year_start, + FactBilling.local_date <= year_end, FactBilling.notification_type == SMS_TYPE, ) ).filter( @@ -889,7 +889,7 @@ def fetch_daily_volumes_for_platform(start_date, end_date): # query to return the total notifications sent per day for each channel. NB start and end dates are inclusive daily_volume_stats = db.session.query( - FactBilling.bst_date, + FactBilling.local_date, func.sum(case( [ (FactBilling.notification_type == SMS_TYPE, FactBilling.notifications_sent) @@ -921,15 +921,15 @@ def fetch_daily_volumes_for_platform(start_date, end_date): ], else_=0 )).label('letter_sheet_totals') ).filter( - FactBilling.bst_date >= start_date, - FactBilling.bst_date <= end_date + FactBilling.local_date >= start_date, + FactBilling.local_date <= end_date ).group_by( - FactBilling.bst_date, + FactBilling.local_date, FactBilling.notification_type ).subquery() aggregated_totals = db.session.query( - daily_volume_stats.c.bst_date.cast(db.Text).label('bst_date'), + daily_volume_stats.c.local_date.cast(db.Text).label('local_date'), func.sum(daily_volume_stats.c.sms_totals).label('sms_totals'), func.sum(daily_volume_stats.c.sms_fragment_totals).label('sms_fragment_totals'), func.sum( @@ -938,9 +938,9 @@ def fetch_daily_volumes_for_platform(start_date, end_date): func.sum(daily_volume_stats.c.letter_totals).label('letter_totals'), func.sum(daily_volume_stats.c.letter_sheet_totals).label('letter_sheet_totals') ).group_by( - daily_volume_stats.c.bst_date + daily_volume_stats.c.local_date ).order_by( - daily_volume_stats.c.bst_date + daily_volume_stats.c.local_date ).all() return aggregated_totals @@ -950,7 +950,7 @@ def fetch_daily_sms_provider_volumes_for_platform(start_date, end_date): # query to return the total notifications sent per day for each channel. NB start and end dates are inclusive daily_volume_stats = db.session.query( - FactBilling.bst_date, + FactBilling.local_date, FactBilling.provider, func.sum(FactBilling.notifications_sent).label('sms_totals'), func.sum(FactBilling.billable_units).label('sms_fragment_totals'), @@ -958,13 +958,13 @@ def fetch_daily_sms_provider_volumes_for_platform(start_date, end_date): func.sum(FactBilling.billable_units * FactBilling.rate_multiplier * FactBilling.rate).label('sms_cost'), ).filter( FactBilling.notification_type == SMS_TYPE, - FactBilling.bst_date >= start_date, - FactBilling.bst_date <= end_date, + FactBilling.local_date >= start_date, + FactBilling.local_date <= end_date, ).group_by( - FactBilling.bst_date, + FactBilling.local_date, FactBilling.provider, ).order_by( - FactBilling.bst_date, + FactBilling.local_date, FactBilling.provider, ).all() @@ -977,7 +977,7 @@ def fetch_volumes_by_service(start_date, end_date): year_end_date = int(end_date.strftime('%Y')) volume_stats = db.session.query( - FactBilling.bst_date, + FactBilling.local_date, FactBilling.service_id, func.sum(case([ (FactBilling.notification_type == SMS_TYPE, FactBilling.notifications_sent) @@ -1000,10 +1000,10 @@ def fetch_volumes_by_service(start_date, end_date): ], else_=0 )).label('letter_sheet_totals') ).filter( - FactBilling.bst_date >= start_date, - FactBilling.bst_date <= end_date + FactBilling.local_date >= start_date, + FactBilling.local_date <= end_date ).group_by( - FactBilling.bst_date, + FactBilling.local_date, FactBilling.service_id, FactBilling.notification_type ).subquery() diff --git a/app/dao/fact_notification_status_dao.py b/app/dao/fact_notification_status_dao.py index e5578d961..ed1647802 100644 --- a/app/dao/fact_notification_status_dao.py +++ b/app/dao/fact_notification_status_dao.py @@ -41,7 +41,7 @@ def update_fact_notification_status(process_day, notification_type, service_id): # delete any existing rows in case some no longer exist e.g. if all messages are sent FactNotificationStatus.query.filter( - FactNotificationStatus.bst_date == process_day, + FactNotificationStatus.local_date == process_day, FactNotificationStatus.notification_type == notification_type, FactNotificationStatus.service_id == service_id, ).delete() @@ -72,7 +72,7 @@ def update_fact_notification_status(process_day, notification_type, service_id): db.session.connection().execute( insert(FactNotificationStatus.__table__).from_select( [ - FactNotificationStatus.bst_date, + FactNotificationStatus.local_date, FactNotificationStatus.template_id, FactNotificationStatus.service_id, FactNotificationStatus.job_id, @@ -88,17 +88,17 @@ def update_fact_notification_status(process_day, notification_type, service_id): def fetch_notification_status_for_service_by_month(start_date, end_date, service_id): return db.session.query( - func.date_trunc('month', FactNotificationStatus.bst_date).label('month'), + func.date_trunc('month', FactNotificationStatus.local_date).label('month'), FactNotificationStatus.notification_type, FactNotificationStatus.notification_status, func.sum(FactNotificationStatus.notification_count).label('count') ).filter( FactNotificationStatus.service_id == service_id, - FactNotificationStatus.bst_date >= start_date, - FactNotificationStatus.bst_date < end_date, + FactNotificationStatus.local_date >= start_date, + FactNotificationStatus.local_date < end_date, FactNotificationStatus.key_type != KEY_TYPE_TEST ).group_by( - func.date_trunc('month', FactNotificationStatus.bst_date).label('month'), + func.date_trunc('month', FactNotificationStatus.local_date).label('month'), FactNotificationStatus.notification_type, FactNotificationStatus.notification_status ).all() @@ -132,7 +132,7 @@ def fetch_notification_status_for_service_for_today_and_7_previous_days(service_ FactNotificationStatus.notification_count.label('count') ).filter( FactNotificationStatus.service_id == service_id, - FactNotificationStatus.bst_date >= start_date, + FactNotificationStatus.local_date >= start_date, FactNotificationStatus.key_type != KEY_TYPE_TEST ) @@ -181,8 +181,8 @@ def fetch_notification_status_totals_for_all_services(start_date, end_date): FactNotificationStatus.key_type.label('key_type'), func.sum(FactNotificationStatus.notification_count).label('count') ).filter( - FactNotificationStatus.bst_date >= start_date, - FactNotificationStatus.bst_date <= end_date + FactNotificationStatus.local_date >= start_date, + FactNotificationStatus.local_date <= end_date ).group_by( FactNotificationStatus.notification_type, FactNotificationStatus.notification_status, @@ -245,8 +245,8 @@ def fetch_stats_for_all_services_by_date_range(start_date, end_date, include_fro FactNotificationStatus.notification_status.label('status'), func.sum(FactNotificationStatus.notification_count).label('count') ).filter( - FactNotificationStatus.bst_date >= start_date, - FactNotificationStatus.bst_date <= end_date, + FactNotificationStatus.local_date >= start_date, + FactNotificationStatus.local_date <= end_date, FactNotificationStatus.service_id == Service.id, ).group_by( FactNotificationStatus.service_id.label('service_id'), @@ -334,15 +334,15 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id): Template.name.label('name'), Template.template_type.label('template_type'), Template.is_precompiled_letter.label('is_precompiled_letter'), - extract('month', FactNotificationStatus.bst_date).label('month'), - extract('year', FactNotificationStatus.bst_date).label('year'), + extract('month', FactNotificationStatus.local_date).label('month'), + extract('year', FactNotificationStatus.local_date).label('year'), func.sum(FactNotificationStatus.notification_count).label('count') ).join( Template, FactNotificationStatus.template_id == Template.id ).filter( FactNotificationStatus.service_id == service_id, - FactNotificationStatus.bst_date >= start_date, - FactNotificationStatus.bst_date <= end_date, + FactNotificationStatus.local_date >= start_date, + FactNotificationStatus.local_date <= end_date, FactNotificationStatus.key_type != KEY_TYPE_TEST, FactNotificationStatus.notification_status != NOTIFICATION_CANCELLED, ).group_by( @@ -350,11 +350,11 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id): Template.name, Template.template_type, Template.is_precompiled_letter, - extract('month', FactNotificationStatus.bst_date).label('month'), - extract('year', FactNotificationStatus.bst_date).label('year'), + extract('month', FactNotificationStatus.local_date).label('month'), + extract('year', FactNotificationStatus.local_date).label('year'), ).order_by( - extract('year', FactNotificationStatus.bst_date), - extract('month', FactNotificationStatus.bst_date), + extract('year', FactNotificationStatus.local_date), + extract('month', FactNotificationStatus.local_date), Template.name ) @@ -413,7 +413,7 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id): def get_total_notifications_for_date_range(start_date, end_date): query = db.session.query( - FactNotificationStatus.bst_date.cast(db.Text).label("bst_date"), + FactNotificationStatus.local_date.cast(db.Text).label("local_date"), func.sum(case( [ (FactNotificationStatus.notification_type == 'email', FactNotificationStatus.notification_count) @@ -432,21 +432,21 @@ def get_total_notifications_for_date_range(start_date, end_date): ).filter( FactNotificationStatus.key_type != KEY_TYPE_TEST, ).group_by( - FactNotificationStatus.bst_date + FactNotificationStatus.local_date ).order_by( - FactNotificationStatus.bst_date + FactNotificationStatus.local_date ) if start_date and end_date: query = query.filter( - FactNotificationStatus.bst_date >= start_date, - FactNotificationStatus.bst_date <= end_date + FactNotificationStatus.local_date >= start_date, + FactNotificationStatus.local_date <= end_date ) return query.all() def fetch_monthly_notification_statuses_per_service(start_date, end_date): return db.session.query( - func.date_trunc('month', FactNotificationStatus.bst_date).cast(Date).label('date_created'), + func.date_trunc('month', FactNotificationStatus.local_date).cast(Date).label('date_created'), Service.id.label('service_id'), Service.name.label('service_name'), FactNotificationStatus.notification_type, @@ -494,15 +494,15 @@ def fetch_monthly_notification_statuses_per_service(start_date, end_date): FactNotificationStatus.key_type != KEY_TYPE_TEST, Service.research_mode.is_(False), Service.restricted.is_(False), - FactNotificationStatus.bst_date >= start_date, - FactNotificationStatus.bst_date <= end_date, + FactNotificationStatus.local_date >= start_date, + FactNotificationStatus.local_date <= end_date, ).group_by( Service.id, Service.name, - func.date_trunc('month', FactNotificationStatus.bst_date).cast(Date), + func.date_trunc('month', FactNotificationStatus.local_date).cast(Date), FactNotificationStatus.notification_type, ).order_by( - func.date_trunc('month', FactNotificationStatus.bst_date).cast(Date), + func.date_trunc('month', FactNotificationStatus.local_date).cast(Date), Service.id, FactNotificationStatus.notification_type, ).all() diff --git a/app/dao/fact_processing_time_dao.py b/app/dao/fact_processing_time_dao.py index ddb4c4bf8..7fc62fd30 100644 --- a/app/dao/fact_processing_time_dao.py +++ b/app/dao/fact_processing_time_dao.py @@ -18,12 +18,12 @@ def insert_update_processing_time(processing_time): ''' table = FactProcessingTime.__table__ stmt = insert(table).values( - bst_date=processing_time.bst_date, + local_date=processing_time.local_date, messages_total=processing_time.messages_total, messages_within_10_secs=processing_time.messages_within_10_secs ) stmt = stmt.on_conflict_do_update( - index_elements=[table.c.bst_date], + index_elements=[table.c.local_date], set_={ 'messages_total': stmt.excluded.messages_total, 'messages_within_10_secs': stmt.excluded.messages_within_10_secs, @@ -35,7 +35,7 @@ def insert_update_processing_time(processing_time): def get_processing_time_percentage_for_date_range(start_date, end_date): query = db.session.query( - FactProcessingTime.bst_date.cast(db.Text).label("date"), + FactProcessingTime.local_date.cast(db.Text).label("date"), FactProcessingTime.messages_total, FactProcessingTime.messages_within_10_secs, case([ @@ -46,8 +46,8 @@ def get_processing_time_percentage_for_date_range(start_date, end_date): (FactProcessingTime.messages_total == 0, 100.0) ]).label("percentage") ).filter( - FactProcessingTime.bst_date >= start_date, - FactProcessingTime.bst_date <= end_date - ).order_by(FactProcessingTime.bst_date) + FactProcessingTime.local_date >= start_date, + FactProcessingTime.local_date <= end_date + ).order_by(FactProcessingTime.local_date) return query.all() diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index cae614a7d..de0780c8d 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -66,7 +66,7 @@ def dao_get_last_date_template_was_used(template_id, service_id): return last_date_from_notifications last_date = db.session.query( - functions.max(FactNotificationStatus.bst_date) + functions.max(FactNotificationStatus.local_date) ).filter( FactNotificationStatus.template_id == template_id, FactNotificationStatus.key_type != KEY_TYPE_TEST @@ -806,7 +806,7 @@ def get_service_ids_with_notifications_on_date(notification_type, date): FactNotificationStatus.service_id.label('service_id') ).filter( FactNotificationStatus.notification_type == notification_type, - FactNotificationStatus.bst_date == date, + FactNotificationStatus.local_date == date, ) return { diff --git a/app/dao/provider_details_dao.py b/app/dao/provider_details_dao.py index 58ca66d0c..15ed99505 100644 --- a/app/dao/provider_details_dao.py +++ b/app/dao/provider_details_dao.py @@ -165,7 +165,7 @@ def dao_get_provider_stats(): func.sum(FactBilling.billable_units * FactBilling.rate_multiplier).label('current_month_billable_sms') ).filter( FactBilling.notification_type == SMS_TYPE, - FactBilling.bst_date >= first_day_of_the_month + FactBilling.local_date >= first_day_of_the_month ).group_by( FactBilling.provider ).subquery() diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index af4c60d46..eda383edb 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -97,8 +97,8 @@ def dao_fetch_live_services_data(): ).subquery() this_year_ft_billing = FactBilling.query.filter( - FactBilling.bst_date >= year_start_date, - FactBilling.bst_date <= year_end_date, + FactBilling.local_date >= year_start_date, + FactBilling.local_date <= year_end_date, ).subquery() data = db.session.query( diff --git a/app/letters/utils.py b/app/letters/utils.py index 56ddf932f..564549eb9 100644 --- a/app/letters/utils.py +++ b/app/letters/utils.py @@ -214,9 +214,9 @@ def letter_print_day(created_at): bst_print_datetime = convert_utc_to_local_timezone(created_at) + timedelta(hours=6, minutes=30) bst_print_date = bst_print_datetime.date() - current_bst_date = convert_utc_to_local_timezone(datetime.utcnow()).date() + current_local_date = convert_utc_to_local_timezone(datetime.utcnow()).date() - if bst_print_date >= current_bst_date: + if bst_print_date >= current_local_date: return 'today' else: print_date = bst_print_datetime.strftime('%d %B').lstrip('0') diff --git a/app/models.py b/app/models.py index ac12016dc..e2c5c5bed 100644 --- a/app/models.py +++ b/app/models.py @@ -2076,7 +2076,7 @@ class DailySortedLetter(db.Model): class FactBilling(db.Model): __tablename__ = "ft_billing" - bst_date = db.Column(db.Date, nullable=False, primary_key=True, index=True) + local_date = db.Column(db.Date, nullable=False, primary_key=True, index=True) template_id = db.Column(UUID(as_uuid=True), nullable=False, primary_key=True, index=True) service_id = db.Column(UUID(as_uuid=True), nullable=False, primary_key=True, index=True) notification_type = db.Column(db.Text, nullable=False, primary_key=True) @@ -2094,7 +2094,7 @@ class FactBilling(db.Model): class FactNotificationStatus(db.Model): __tablename__ = "ft_notification_status" - bst_date = db.Column(db.Date, index=True, primary_key=True, nullable=False) + local_date = db.Column(db.Date, index=True, primary_key=True, nullable=False) template_id = db.Column(UUID(as_uuid=True), primary_key=True, index=True, nullable=False) service_id = db.Column(UUID(as_uuid=True), primary_key=True, index=True, nullable=False, ) job_id = db.Column(UUID(as_uuid=True), primary_key=True, index=True, nullable=False) @@ -2109,7 +2109,7 @@ class FactNotificationStatus(db.Model): class FactProcessingTime(db.Model): __tablename__ = "ft_processing_time" - bst_date = db.Column(db.Date, index=True, primary_key=True, nullable=False) + local_date = db.Column(db.Date, index=True, primary_key=True, nullable=False) messages_total = db.Column(db.Integer(), nullable=False) messages_within_10_secs = db.Column(db.Integer(), nullable=False) created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) diff --git a/app/performance_dashboard/rest.py b/app/performance_dashboard/rest.py index cef701f6e..463961651 100644 --- a/app/performance_dashboard/rest.py +++ b/app/performance_dashboard/rest.py @@ -71,7 +71,7 @@ def transform_results_into_totals(total_notifications_results): def transform_into_notification_by_type_json(total_notifications): j = [] for x in total_notifications: - j.append({"date": x.bst_date, "emails": x.emails, "sms": x.sms, "letters": x.letters}) + j.append({"date": x.local_date, "emails": x.emails, "sms": x.sms, "letters": x.letters}) return j diff --git a/app/performance_platform/processing_time.py b/app/performance_platform/processing_time.py index 89de8ba5c..f58c94d43 100644 --- a/app/performance_platform/processing_time.py +++ b/app/performance_platform/processing_time.py @@ -9,14 +9,14 @@ from app.dao.notifications_dao import ( from app.utils import get_local_midnight_in_utc -def send_processing_time_to_performance_platform(bst_date): - start_time = get_local_midnight_in_utc(bst_date) - end_time = get_local_midnight_in_utc(bst_date + timedelta(days=1)) +def send_processing_time_to_performance_platform(local_date): + start_time = get_local_midnight_in_utc(local_date) + end_time = get_local_midnight_in_utc(local_date + timedelta(days=1)) - send_processing_time_for_start_and_end(start_time, end_time, bst_date) + send_processing_time_for_start_and_end(start_time, end_time, local_date) -def send_processing_time_for_start_and_end(start_time, end_time, bst_date): +def send_processing_time_for_start_and_end(start_time, end_time, local_date): result = dao_get_total_notifications_sent_per_day_for_performance_platform(start_time, end_time) current_app.logger.info( diff --git a/app/platform_stats/rest.py b/app/platform_stats/rest.py index 7350e74ad..ff5a44b28 100644 --- a/app/platform_stats/rest.py +++ b/app/platform_stats/rest.py @@ -151,7 +151,7 @@ def daily_volumes_report(): for row in daily_volumes: report.append({ - "day": row.bst_date, + "day": row.local_date, "sms_totals": int(row.sms_totals), "sms_fragment_totals": int(row.sms_fragment_totals), "sms_chargeable_units": int(row.sms_chargeable_units), @@ -172,7 +172,7 @@ def daily_sms_provider_volumes_report(): for row in daily_volumes: report.append({ - 'day': row.bst_date.isoformat(), + 'day': row.local_date.isoformat(), 'provider': row.provider, 'sms_totals': int(row.sms_totals), 'sms_fragment_totals': int(row.sms_fragment_totals), diff --git a/migrations/versions/0174_add_billing_facts.py b/migrations/versions/0174_add_billing_facts.py index ab108e3a8..9b3878b1d 100644 --- a/migrations/versions/0174_add_billing_facts.py +++ b/migrations/versions/0174_add_billing_facts.py @@ -16,7 +16,7 @@ down_revision = '0173_create_daily_sorted_letter' def upgrade(): # Create notifications_for_today table op.create_table('ft_billing', - sa.Column('bst_date', sa.Date(), nullable=True), + sa.Column('local_date', sa.Date(), nullable=True), sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=True), sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=True), sa.Column('organisation_id', postgresql.UUID(as_uuid=True), nullable=True), @@ -29,15 +29,15 @@ def upgrade(): sa.Column('rate', sa.Numeric(), nullable=True), sa.Column('billable_units', sa.Numeric(), nullable=True), sa.Column('notifications_sent', sa.Integer(), nullable=True), - sa.PrimaryKeyConstraint('bst_date', 'template_id') + sa.PrimaryKeyConstraint('local_date', 'template_id') ) # Set indexes - op.create_index(op.f('ix_ft_billing_bst_date'), 'ft_billing', ['bst_date'], unique=False) + op.create_index(op.f('ix_ft_billing_local_date'), 'ft_billing', ['local_date'], unique=False) op.create_index(op.f('ix_ft_billing_service_id'), 'ft_billing', ['service_id'], unique=False) # Create dm_datetime table op.create_table('dm_datetime', - sa.Column('bst_date', sa.Date(), nullable=False), + sa.Column('local_date', sa.Date(), nullable=False), sa.Column('year', sa.Integer(), nullable=False), sa.Column('month', sa.Integer(), nullable=False), sa.Column('month_name', sa.String(), nullable=False), @@ -53,18 +53,18 @@ def upgrade(): sa.Column('financial_year', sa.Integer(), nullable=True), sa.Column('utc_daytime_start', sa.DateTime(), nullable=False), sa.Column('utc_daytime_end', sa.DateTime(), nullable=False), - sa.PrimaryKeyConstraint('bst_date') + sa.PrimaryKeyConstraint('local_date') ) # Set indexes op.create_index(op.f('ix_dm_datetime_yearmonth'), 'dm_datetime', ['year', 'month'], unique=False) - op.create_index(op.f('ix_dm_datetime_bst_date'), 'dm_datetime', ['bst_date'], unique=False) + op.create_index(op.f('ix_dm_datetime_local_date'), 'dm_datetime', ['local_date'], unique=False) # Insert data into table op.execute( """ INSERT into dm_datetime ( SELECT - datum AS bst_date, + datum AS local_date, EXTRACT(YEAR FROM datum) AS year, EXTRACT(MONTH FROM datum) AS month, -- Localized month name @@ -91,7 +91,7 @@ def upgrade(): FROM generate_series(0,365*50+10) AS SEQUENCE(DAY) GROUP BY SEQUENCE.day ) DQ - ORDER BY bst_date + ORDER BY local_date ); """ ) diff --git a/migrations/versions/0179_billing_primary_const.py b/migrations/versions/0179_billing_primary_const.py index ab5b49739..9356b5fc9 100644 --- a/migrations/versions/0179_billing_primary_const.py +++ b/migrations/versions/0179_billing_primary_const.py @@ -20,7 +20,7 @@ def upgrade(): op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary') # These are the orthogonal dimensions that define a row (except international). # These entries define a unique record. - op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date', + op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date', 'template_id', 'rate_multiplier', 'provider', @@ -32,5 +32,5 @@ def downgrade(): op.add_column('ft_billing', sa.Column('annual_billing_id', postgresql.UUID(), autoincrement=False, nullable=True)) op.add_column('ft_billing', sa.Column('crown', sa.TEXT(), autoincrement=False, nullable=True)) op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary') - op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date', + op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date', 'template_id']) diff --git a/migrations/versions/0181_billing_primary_key.py b/migrations/versions/0181_billing_primary_key.py index eec3c4950..dea8eeafc 100644 --- a/migrations/versions/0181_billing_primary_key.py +++ b/migrations/versions/0181_billing_primary_key.py @@ -19,7 +19,7 @@ def upgrade(): nullable=False) op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary') - op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date', + op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date', 'template_id', 'rate_multiplier', 'provider', @@ -34,7 +34,7 @@ def downgrade(): op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary') - op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date', + op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date', 'template_id', 'rate_multiplier', 'provider', diff --git a/migrations/versions/0183_alter_primary_key.py b/migrations/versions/0183_alter_primary_key.py index a183f9562..ad26e4081 100644 --- a/migrations/versions/0183_alter_primary_key.py +++ b/migrations/versions/0183_alter_primary_key.py @@ -24,7 +24,7 @@ def upgrade(): """ INSERT into dm_datetime ( SELECT - datum AS bst_date, + datum AS local_date, EXTRACT(YEAR FROM datum) AS year, EXTRACT(MONTH FROM datum) AS month, -- Localized month name @@ -51,14 +51,14 @@ def upgrade(): FROM generate_series(0,365*50+10) AS SEQUENCE(DAY) GROUP BY SEQUENCE.day ) DQ - ORDER BY bst_date + ORDER BY local_date ); """ ) op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary') - op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date', + op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date', 'template_id', 'service_id', 'rate_multiplier', @@ -70,7 +70,7 @@ def downgrade(): # We don't downgrade populated data op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary') - op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date', + op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date', 'template_id', 'rate_multiplier', 'provider', diff --git a/migrations/versions/0184_alter_primary_key_1.py b/migrations/versions/0184_alter_primary_key_1.py index 0dc343f45..0837995a7 100644 --- a/migrations/versions/0184_alter_primary_key_1.py +++ b/migrations/versions/0184_alter_primary_key_1.py @@ -16,7 +16,7 @@ down_revision = '0183_alter_primary_key' def upgrade(): op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary') - op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date', + op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date', 'template_id', 'service_id', 'rate_multiplier', @@ -28,7 +28,7 @@ def upgrade(): def downgrade(): op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary') - op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date', + op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date', 'template_id', 'service_id', 'rate_multiplier', diff --git a/migrations/versions/0188_add_ft_notification_status.py b/migrations/versions/0188_add_ft_notification_status.py index 403735837..97432d6eb 100644 --- a/migrations/versions/0188_add_ft_notification_status.py +++ b/migrations/versions/0188_add_ft_notification_status.py @@ -15,7 +15,7 @@ down_revision = '0187_another_letter_org' def upgrade(): op.create_table('ft_notification_status', - sa.Column('bst_date', sa.Date(), nullable=False), + sa.Column('local_date', sa.Date(), nullable=False), sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=False), sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False), sa.Column('job_id', postgresql.UUID(as_uuid=True), nullable=False), @@ -23,16 +23,16 @@ def upgrade(): sa.Column('key_type', sa.Text(), nullable=False), sa.Column('notification_status', sa.Text(), nullable=False), sa.Column('notification_count', sa.Integer(), nullable=False), - sa.PrimaryKeyConstraint('bst_date', 'template_id', 'service_id', 'job_id', 'notification_type', 'key_type', 'notification_status') + sa.PrimaryKeyConstraint('local_date', 'template_id', 'service_id', 'job_id', 'notification_type', 'key_type', 'notification_status') ) - op.create_index(op.f('ix_ft_notification_status_bst_date'), 'ft_notification_status', ['bst_date'], unique=False) + op.create_index(op.f('ix_ft_notification_status_local_date'), 'ft_notification_status', ['local_date'], unique=False) op.create_index(op.f('ix_ft_notification_status_job_id'), 'ft_notification_status', ['job_id'], unique=False) op.create_index(op.f('ix_ft_notification_status_service_id'), 'ft_notification_status', ['service_id'], unique=False) op.create_index(op.f('ix_ft_notification_status_template_id'), 'ft_notification_status', ['template_id'], unique=False) def downgrade(): - op.drop_index(op.f('ix_ft_notification_status_bst_date'), table_name='ft_notification_status') + op.drop_index(op.f('ix_ft_notification_status_local_date'), table_name='ft_notification_status') op.drop_index(op.f('ix_ft_notification_status_template_id'), table_name='ft_notification_status') op.drop_index(op.f('ix_ft_notification_status_service_id'), table_name='ft_notification_status') op.drop_index(op.f('ix_ft_notification_status_job_id'), table_name='ft_notification_status') diff --git a/migrations/versions/0191_ft_billing_pkey.py b/migrations/versions/0191_ft_billing_pkey.py index 80093083c..b3ad5d839 100644 --- a/migrations/versions/0191_ft_billing_pkey.py +++ b/migrations/versions/0191_ft_billing_pkey.py @@ -16,7 +16,7 @@ def upgrade(): op.execute("ALTER TABLE ft_billing DROP CONSTRAINT ft_billing_pkey") sql = """ALTER TABLE ft_billing ADD CONSTRAINT ft_billing_pkey PRIMARY KEY - (bst_date, template_id, service_id, rate_multiplier, provider, notification_type, international, rate)""" + (local_date, template_id, service_id, rate_multiplier, provider, notification_type, international, rate)""" op.execute(sql) @@ -25,5 +25,5 @@ def downgrade(): op.execute("ALTER TABLE ft_billing DROP CONSTRAINT ft_billing_pkey") sql = """ALTER TABLE ft_billing ADD CONSTRAINT ft_billing_pkey PRIMARY KEY - (bst_date, template_id, service_id, rate_multiplier, provider, notification_type, international)""" + (local_date, template_id, service_id, rate_multiplier, provider, notification_type, international)""" op.execute(sql) \ No newline at end of file diff --git a/migrations/versions/0235_add_postage_to_pk.py b/migrations/versions/0235_add_postage_to_pk.py index 072f2646e..13506a081 100644 --- a/migrations/versions/0235_add_postage_to_pk.py +++ b/migrations/versions/0235_add_postage_to_pk.py @@ -15,7 +15,7 @@ down_revision = '0234_ft_billing_postage' def upgrade(): op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary') - op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date', + op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date', 'template_id', 'service_id', 'notification_type', @@ -29,7 +29,7 @@ def upgrade(): def downgrade(): op.drop_constraint('ft_billing_pkey', 'ft_billing', type_='primary') op.alter_column('ft_billing', 'postage', nullable=True) - op.create_primary_key('ft_billing_pkey', 'ft_billing', ['bst_date', + op.create_primary_key('ft_billing_pkey', 'ft_billing', ['local_date', 'template_id', 'service_id', 'notification_type', diff --git a/migrations/versions/0307_delete_dm_datetime.py b/migrations/versions/0307_delete_dm_datetime.py index a4b664920..5fdc79bb6 100644 --- a/migrations/versions/0307_delete_dm_datetime.py +++ b/migrations/versions/0307_delete_dm_datetime.py @@ -14,14 +14,14 @@ down_revision = '0306_letter_rates_price_rise' def upgrade(): - op.drop_index('ix_dm_datetime_bst_date', table_name='dm_datetime') + op.drop_index('ix_dm_datetime_local_date', table_name='dm_datetime') op.drop_index('ix_dm_datetime_yearmonth', table_name='dm_datetime') op.drop_table('dm_datetime') def downgrade(): op.create_table('dm_datetime', - sa.Column('bst_date', sa.DATE(), autoincrement=False, nullable=False), + sa.Column('local_date', sa.DATE(), autoincrement=False, nullable=False), sa.Column('year', sa.INTEGER(), autoincrement=False, nullable=False), sa.Column('month', sa.INTEGER(), autoincrement=False, nullable=False), sa.Column('month_name', sa.VARCHAR(), autoincrement=False, nullable=False), @@ -37,7 +37,7 @@ def downgrade(): sa.Column('financial_year', sa.INTEGER(), autoincrement=False, nullable=False), sa.Column('utc_daytime_start', postgresql.TIMESTAMP(), autoincrement=False, nullable=False), sa.Column('utc_daytime_end', postgresql.TIMESTAMP(), autoincrement=False, nullable=False), - sa.PrimaryKeyConstraint('bst_date', name='dm_datetime_pkey') + sa.PrimaryKeyConstraint('local_date', name='dm_datetime_pkey') ) op.create_index('ix_dm_datetime_yearmonth', 'dm_datetime', ['year', 'month'], unique=False) - op.create_index('ix_dm_datetime_bst_date', 'dm_datetime', ['bst_date'], unique=False) + op.create_index('ix_dm_datetime_local_date', 'dm_datetime', ['local_date'], unique=False) diff --git a/migrations/versions/0349_add_ft_processing_time.py b/migrations/versions/0349_add_ft_processing_time.py index df0a613cd..5a938f9e2 100644 --- a/migrations/versions/0349_add_ft_processing_time.py +++ b/migrations/versions/0349_add_ft_processing_time.py @@ -15,16 +15,16 @@ down_revision = '0348_migrate_broadcast_settings' def upgrade(): op.create_table('ft_processing_time', - sa.Column('bst_date', sa.Date(), nullable=False), + sa.Column('local_date', sa.Date(), nullable=False), sa.Column('messages_total', sa.Integer(), nullable=False), sa.Column('messages_within_10_secs', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=True), - sa.PrimaryKeyConstraint('bst_date') + sa.PrimaryKeyConstraint('local_date') ) - op.create_index(op.f('ix_ft_processing_time_bst_date'), 'ft_processing_time', ['bst_date'], unique=False) + op.create_index(op.f('ix_ft_processing_time_local_date'), 'ft_processing_time', ['local_date'], unique=False) def downgrade(): - op.drop_index(op.f('ix_ft_processing_time_bst_date'), table_name='ft_processing_time') + op.drop_index(op.f('ix_ft_processing_time_local_date'), table_name='ft_processing_time') op.drop_table('ft_processing_time') diff --git a/migrations/versions/0371_fix_apr_2022_sms_rate.py b/migrations/versions/0371_fix_apr_2022_sms_rate.py index 62c9fe980..144a7c76d 100644 --- a/migrations/versions/0371_fix_apr_2022_sms_rate.py +++ b/migrations/versions/0371_fix_apr_2022_sms_rate.py @@ -24,8 +24,8 @@ def upgrade(): SET rate = 0.0161 WHERE notification_type = 'sms' AND - bst_date >= '2022-04-01' AND - bst_date < '2022-05-01' + local_date >= '2022-04-01' AND + local_date < '2022-05-01' """ ) diff --git a/tests/app/billing/test_rest.py b/tests/app/billing/test_rest.py index b4213a8f7..b299ff8df 100644 --- a/tests/app/billing/test_rest.py +++ b/tests/app/billing/test_rest.py @@ -130,9 +130,9 @@ def test_get_yearly_usage_by_monthly_from_ft_billing(admin_request, notify_db_se letter_template = create_template(service=service, template_type="letter") for dt in (date(2016, 4, 28), date(2016, 11, 10), date(2017, 2, 26)): - create_ft_billing(bst_date=dt, template=sms_template, rate=0.0162) - create_ft_billing(bst_date=dt, template=email_template, billable_unit=0, rate=0) - create_ft_billing(bst_date=dt, template=letter_template, rate=0.33, postage='second') + create_ft_billing(local_date=dt, template=sms_template, rate=0.0162) + create_ft_billing(local_date=dt, template=email_template, billable_unit=0, rate=0) + create_ft_billing(local_date=dt, template=letter_template, rate=0.33, postage='second') json_response = admin_request.get( 'billing.get_yearly_usage_by_monthly_from_ft_billing', @@ -201,9 +201,9 @@ def test_get_yearly_billing_usage_summary_from_ft_billing(admin_request, notify_ letter_template = create_template(service=service, template_type="letter") for dt in (date(2016, 4, 28), date(2016, 11, 10), date(2017, 2, 26)): - create_ft_billing(bst_date=dt, template=sms_template, rate=0.0162) - create_ft_billing(bst_date=dt, template=email_template, billable_unit=0, rate=0) - create_ft_billing(bst_date=dt, template=letter_template, rate=0.33, postage='second') + create_ft_billing(local_date=dt, template=sms_template, rate=0.0162) + create_ft_billing(local_date=dt, template=email_template, billable_unit=0, rate=0) + create_ft_billing(local_date=dt, template=letter_template, rate=0.33, postage='second') json_response = admin_request.get( 'billing.get_yearly_billing_usage_summary_from_ft_billing', diff --git a/tests/app/celery/test_nightly_tasks.py b/tests/app/celery/test_nightly_tasks.py index 4105a4c49..5849038cd 100644 --- a/tests/app/celery/test_nightly_tasks.py +++ b/tests/app/celery/test_nightly_tasks.py @@ -402,7 +402,7 @@ def test_save_daily_notification_processing_time(mocker, sample_template, date_p persisted_to_db = FactProcessingTime.query.all() assert len(persisted_to_db) == 1 - assert persisted_to_db[0].bst_date == date(2021, 1, 17) + assert persisted_to_db[0].local_date == date(2021, 1, 17) assert persisted_to_db[0].messages_total == 2 assert persisted_to_db[0].messages_within_10_secs == 1 @@ -439,7 +439,7 @@ def test_save_daily_notification_processing_time_when_in_est(mocker, sample_temp persisted_to_db = FactProcessingTime.query.all() assert len(persisted_to_db) == 1 - assert persisted_to_db[0].bst_date == date(2021, 4, 17) + assert persisted_to_db[0].local_date == date(2021, 4, 17) assert persisted_to_db[0].messages_total == 2 assert persisted_to_db[0].messages_within_10_secs == 2 diff --git a/tests/app/celery/test_reporting_tasks.py b/tests/app/celery/test_reporting_tasks.py index 2150bd3c0..6c1e8ded2 100644 --- a/tests/app/celery/test_reporting_tasks.py +++ b/tests/app/celery/test_reporting_tasks.py @@ -36,7 +36,7 @@ from tests.app.db import ( def mocker_get_rate( - non_letter_rates, letter_rates, notification_type, bst_date, crown=None, rate_multiplier=None, post_class="second" + non_letter_rates, letter_rates, notification_type, local_date, crown=None, rate_multiplier=None, post_class="second" ): if notification_type == LETTER_TYPE: return Decimal(2.1) @@ -193,7 +193,7 @@ def test_create_nightly_billing_for_day_sms_rate_multiplier( assert len(records) == records_num for i, record in enumerate(records): - assert record.bst_date == datetime.date(yesterday) + assert record.local_date == datetime.date(yesterday) assert record.rate == Decimal(1.33) assert record.billable_units == billable_units assert record.rate_multiplier == multiplier[i] @@ -240,7 +240,7 @@ def test_create_nightly_billing_for_day_different_templates( rate = [0, Decimal(1.33)] for i, record in enumerate(records): - assert record.bst_date == datetime.date(yesterday) + assert record.local_date == datetime.date(yesterday) assert record.rate == rate[i] assert record.billable_units == billable_units[i] assert record.rate_multiplier == multiplier[i] @@ -285,7 +285,7 @@ def test_create_nightly_billing_for_day_different_sent_by( assert len(records) == 2 for _, record in enumerate(records): - assert record.bst_date == datetime.date(yesterday) + assert record.local_date == datetime.date(yesterday) assert record.rate == Decimal(1.33) assert record.billable_units == 1 assert record.rate_multiplier == 1.0 @@ -342,25 +342,25 @@ def test_create_nightly_billing_for_day_different_letter_postage( assert len(records) == 4 assert records[0].notification_type == LETTER_TYPE - assert records[0].bst_date == datetime.date(yesterday) + assert records[0].local_date == datetime.date(yesterday) assert records[0].postage == 'europe' assert records[0].notifications_sent == 1 assert records[0].billable_units == 1 assert records[1].notification_type == LETTER_TYPE - assert records[1].bst_date == datetime.date(yesterday) + assert records[1].local_date == datetime.date(yesterday) assert records[1].postage == 'first' assert records[1].notifications_sent == 2 assert records[1].billable_units == 4 assert records[2].notification_type == LETTER_TYPE - assert records[2].bst_date == datetime.date(yesterday) + assert records[2].local_date == datetime.date(yesterday) assert records[2].postage == 'rest-of-world' assert records[2].notifications_sent == 1 assert records[2].billable_units == 3 assert records[3].notification_type == LETTER_TYPE - assert records[3].bst_date == datetime.date(yesterday) + assert records[3].local_date == datetime.date(yesterday) assert records[3].postage == 'second' assert records[3].notifications_sent == 1 assert records[3].billable_units == 2 @@ -395,7 +395,7 @@ def test_create_nightly_billing_for_day_letter( record = records[0] assert record.notification_type == LETTER_TYPE - assert record.bst_date == datetime.date(yesterday) + assert record.local_date == datetime.date(yesterday) assert record.rate == Decimal(2.1) assert record.billable_units == 2 assert record.rate_multiplier == 2.0 @@ -429,7 +429,7 @@ def test_create_nightly_billing_for_day_null_sent_by_sms( assert len(records) == 1 record = records[0] - assert record.bst_date == datetime.date(yesterday) + assert record.local_date == datetime.date(yesterday) assert record.rate == Decimal(1.33) assert record.billable_units == 1 assert record.rate_multiplier == 1 @@ -510,10 +510,10 @@ def test_create_nightly_billing_for_day_use_BST( assert FactBilling.query.count() == 0 create_nightly_billing_for_day('2018-03-25') - records = FactBilling.query.order_by(FactBilling.bst_date).all() + records = FactBilling.query.order_by(FactBilling.local_date).all() assert len(records) == 1 - assert records[0].bst_date == date(2018, 3, 25) + assert records[0].local_date == date(2018, 3, 25) assert records[0].billable_units == 2 @@ -539,10 +539,10 @@ def test_create_nightly_billing_for_day_update_when_record_exists( assert len(records) == 0 create_nightly_billing_for_day('2018-01-14') - records = FactBilling.query.order_by(FactBilling.bst_date).all() + records = FactBilling.query.order_by(FactBilling.local_date).all() assert len(records) == 1 - assert records[0].bst_date == date(2018, 1, 14) + assert records[0].local_date == date(2018, 1, 14) assert records[0].billable_units == 1 assert not records[0].updated_at @@ -604,7 +604,7 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio assert len(new_fact_data) == 4 email_failure_row = new_fact_data[0] - assert email_failure_row.bst_date == process_day + assert email_failure_row.local_date == process_day assert email_failure_row.template_id == second_template.id assert email_failure_row.service_id == second_service.id assert email_failure_row.job_id == UUID('00000000-0000-0000-0000-000000000000') @@ -682,8 +682,8 @@ def test_create_nightly_notification_status_for_service_and_day_respects_bst(sam create_nightly_notification_status_for_service_and_day('2019-04-01', sample_template.service_id, 'sms') - noti_status = FactNotificationStatus.query.order_by(FactNotificationStatus.bst_date).all() + noti_status = FactNotificationStatus.query.order_by(FactNotificationStatus.local_date).all() assert len(noti_status) == 1 - assert noti_status[0].bst_date == date(2019, 4, 1) + assert noti_status[0].local_date == date(2019, 4, 1) assert noti_status[0].notification_status == 'created' diff --git a/tests/app/dao/notification_dao/test_notification_dao.py b/tests/app/dao/notification_dao/test_notification_dao.py index 9823b068e..dc217a5c0 100644 --- a/tests/app/dao/notification_dao/test_notification_dao.py +++ b/tests/app/dao/notification_dao/test_notification_dao.py @@ -1762,7 +1762,7 @@ def test_get_service_ids_with_notifications_on_date_checks_ft_status( sample_template, ): create_notification(template=sample_template, created_at='2022-01-01T09:30') - create_ft_notification_status(template=sample_template, bst_date='2022-01-02') + create_ft_notification_status(template=sample_template, local_date='2022-01-02') assert len(get_service_ids_with_notifications_on_date(SMS_TYPE, date(2022, 1, 1))) == 1 assert len(get_service_ids_with_notifications_on_date(SMS_TYPE, date(2022, 1, 2))) == 1 diff --git a/tests/app/dao/notification_dao/test_notification_dao_template_usage.py b/tests/app/dao/notification_dao/test_notification_dao_template_usage.py index d3d883877..dfd2c3d26 100644 --- a/tests/app/dao/notification_dao/test_notification_dao_template_usage.py +++ b/tests/app/dao/notification_dao/test_notification_dao_template_usage.py @@ -4,11 +4,11 @@ from app.dao.notifications_dao import dao_get_last_date_template_was_used from tests.app.db import create_ft_notification_status, create_notification -def test_dao_get_last_date_template_was_used_returns_bst_date_from_stats_table( +def test_dao_get_last_date_template_was_used_returns_local_date_from_stats_table( sample_template ): last_status_date = (datetime.utcnow() - timedelta(days=2)).date() - create_ft_notification_status(bst_date=last_status_date, + create_ft_notification_status(local_date=last_status_date, template=sample_template) last_used_date = dao_get_last_date_template_was_used(template_id=sample_template.id, @@ -23,7 +23,7 @@ def test_dao_get_last_date_template_was_used_returns_created_at_from_notificatio create_notification(template=sample_template, created_at=last_notification_date) last_status_date = (datetime.utcnow() - timedelta(days=2)).date() - create_ft_notification_status(bst_date=last_status_date, template=sample_template) + create_ft_notification_status(local_date=last_status_date, template=sample_template) last_used_date = dao_get_last_date_template_was_used(template_id=sample_template.id, service_id=sample_template.service_id) assert last_used_date == last_notification_date diff --git a/tests/app/dao/test_fact_billing_dao.py b/tests/app/dao/test_fact_billing_dao.py index f1d22bd15..1a50649bf 100644 --- a/tests/app/dao/test_fact_billing_dao.py +++ b/tests/app/dao/test_fact_billing_dao.py @@ -49,16 +49,16 @@ def set_up_yearly_data(): # use different rates for adjacent financial years to make sure the query # doesn't accidentally bleed over into them for dt in (date(2016, 3, 31), date(2017, 4, 1)): - create_ft_billing(bst_date=dt, template=sms_template, rate=0.163) - create_ft_billing(bst_date=dt, template=email_template, rate=0, billable_unit=0) - create_ft_billing(bst_date=dt, template=letter_template, rate=0.31, postage='second') + create_ft_billing(local_date=dt, template=sms_template, rate=0.163) + create_ft_billing(local_date=dt, template=email_template, rate=0, billable_unit=0) + create_ft_billing(local_date=dt, template=letter_template, rate=0.31, postage='second') # a selection of dates that represent the extreme ends of the financial year # and some arbitrary dates in between for dt in (date(2016, 4, 1), date(2016, 4, 29), date(2017, 2, 6), date(2017, 3, 31)): - create_ft_billing(bst_date=dt, template=sms_template, rate=0.162) - create_ft_billing(bst_date=dt, template=email_template, rate=0, billable_unit=0) - create_ft_billing(bst_date=dt, template=letter_template, rate=0.30, postage='second') + create_ft_billing(local_date=dt, template=sms_template, rate=0.162) + create_ft_billing(local_date=dt, template=email_template, rate=0, billable_unit=0) + create_ft_billing(local_date=dt, template=letter_template, rate=0.30, postage='second') return service @@ -68,13 +68,13 @@ def set_up_yearly_data_variable_rates(): sms_template = create_template(service=service, template_type="sms") letter_template = create_template(service=service, template_type="letter") - create_ft_billing(bst_date='2018-05-16', template=sms_template, rate=0.162) - create_ft_billing(bst_date='2018-05-17', template=sms_template, rate_multiplier=2, rate=0.0150, billable_unit=2) - create_ft_billing(bst_date='2018-05-16', template=sms_template, rate_multiplier=2, rate=0.162, billable_unit=2) - create_ft_billing(bst_date='2018-05-16', template=letter_template, rate=0.33, postage='second') + create_ft_billing(local_date='2018-05-16', template=sms_template, rate=0.162) + create_ft_billing(local_date='2018-05-17', template=sms_template, rate_multiplier=2, rate=0.0150, billable_unit=2) + create_ft_billing(local_date='2018-05-16', template=sms_template, rate_multiplier=2, rate=0.162, billable_unit=2) + create_ft_billing(local_date='2018-05-16', template=letter_template, rate=0.33, postage='second') create_ft_billing( - bst_date='2018-05-17', + local_date='2018-05-17', template=letter_template, rate=0.36, notifications_sent=2, @@ -516,14 +516,14 @@ def test_fetch_monthly_billing_for_year_adds_data_for_today(notify_db_session): create_annual_billing(service_id=service.id, free_sms_fragment_limit=1000, financial_year_start=2018) for i in range(1, 32): - create_ft_billing(bst_date='2018-07-{}'.format(i), template=template) + create_ft_billing(local_date='2018-07-{}'.format(i), template=template) create_notification(template=template, status='delivered') - assert db.session.query(FactBilling.bst_date).count() == 31 + assert db.session.query(FactBilling.local_date).count() == 31 results = fetch_monthly_billing_for_year(service_id=service.id, year=2018) - assert db.session.query(FactBilling.bst_date).count() == 32 + assert db.session.query(FactBilling.local_date).count() == 32 assert len(results) == 2 @@ -642,17 +642,17 @@ def test_fetch_sms_free_allowance_remainder_until_date_with_two_services(notify_ org = create_organisation(name="Org for {}".format(service.name)) dao_add_service_to_organisation(service=service, organisation_id=org.id) create_annual_billing(service_id=service.id, free_sms_fragment_limit=10, financial_year_start=2016) - create_ft_billing(template=template, bst_date=datetime(2016, 4, 20), billable_unit=2, rate=0.11) - create_ft_billing(template=template, bst_date=datetime(2016, 5, 20), billable_unit=3, rate=0.11) + create_ft_billing(template=template, local_date=datetime(2016, 4, 20), billable_unit=2, rate=0.11) + create_ft_billing(template=template, local_date=datetime(2016, 5, 20), billable_unit=3, rate=0.11) service_2 = create_service(service_name='used free allowance') template_2 = create_template(service=service_2) org_2 = create_organisation(name="Org for {}".format(service_2.name)) dao_add_service_to_organisation(service=service_2, organisation_id=org_2.id) create_annual_billing(service_id=service_2.id, free_sms_fragment_limit=20, financial_year_start=2016) - create_ft_billing(template=template_2, bst_date=datetime(2016, 4, 20), billable_unit=12, rate=0.11) - create_ft_billing(template=template_2, bst_date=datetime(2016, 4, 22), billable_unit=10, rate=0.11) - create_ft_billing(template=template_2, bst_date=datetime(2016, 5, 20), billable_unit=3, rate=0.11) + create_ft_billing(template=template_2, local_date=datetime(2016, 4, 20), billable_unit=12, rate=0.11) + create_ft_billing(template=template_2, local_date=datetime(2016, 4, 22), billable_unit=10, rate=0.11) + create_ft_billing(template=template_2, local_date=datetime(2016, 5, 20), billable_unit=3, rate=0.11) results = fetch_sms_free_allowance_remainder_until_date(datetime(2016, 5, 1)).all() assert len(results) == 2 @@ -669,7 +669,7 @@ def test_fetch_sms_billing_for_all_services_for_first_quarter(notify_db_session) org = create_organisation(name="Org for {}".format(service.name)) dao_add_service_to_organisation(service=service, organisation_id=org.id) create_annual_billing(service_id=service.id, free_sms_fragment_limit=25000, financial_year_start=2019) - create_ft_billing(template=template, bst_date=datetime(2019, 4, 20, 12), billable_unit=44, rate=0.11) + create_ft_billing(template=template, local_date=datetime(2019, 4, 20, 12), billable_unit=44, rate=0.11) results = fetch_sms_billing_for_all_services(datetime(2019, 4, 1, 12), datetime(2019, 5, 30, 12)) assert len(results) == 1 assert results[0] == (org.name, org.id, service.name, service.id, 25000, Decimal('0.11'), 24956, 44, 0, @@ -682,32 +682,32 @@ def test_fetch_sms_billing_for_all_services_with_remainder(notify_db_session): org = create_organisation(name="Org for {}".format(service_1.name)) dao_add_service_to_organisation(service=service_1, organisation_id=org.id) create_annual_billing(service_id=service_1.id, free_sms_fragment_limit=10, financial_year_start=2019) - create_ft_billing(template=template, bst_date=datetime(2019, 4, 20), billable_unit=2, rate=0.11) - create_ft_billing(template=template, bst_date=datetime(2019, 5, 20), billable_unit=2, rate=0.11) - create_ft_billing(template=template, bst_date=datetime(2019, 5, 22), billable_unit=1, rate=0.11) + create_ft_billing(template=template, local_date=datetime(2019, 4, 20), billable_unit=2, rate=0.11) + create_ft_billing(template=template, local_date=datetime(2019, 5, 20), billable_unit=2, rate=0.11) + create_ft_billing(template=template, local_date=datetime(2019, 5, 22), billable_unit=1, rate=0.11) service_2 = create_service(service_name='b - used free allowance') template_2 = create_template(service=service_2) org_2 = create_organisation(name="Org for {}".format(service_2.name)) dao_add_service_to_organisation(service=service_2, organisation_id=org_2.id) create_annual_billing(service_id=service_2.id, free_sms_fragment_limit=10, financial_year_start=2019) - create_ft_billing(template=template_2, bst_date=datetime(2019, 4, 20), billable_unit=12, rate=0.11) - create_ft_billing(template=template_2, bst_date=datetime(2019, 5, 20), billable_unit=3, rate=0.11) + create_ft_billing(template=template_2, local_date=datetime(2019, 4, 20), billable_unit=12, rate=0.11) + create_ft_billing(template=template_2, local_date=datetime(2019, 5, 20), billable_unit=3, rate=0.11) service_3 = create_service(service_name='c - partial allowance') template_3 = create_template(service=service_3) org_3 = create_organisation(name="Org for {}".format(service_3.name)) dao_add_service_to_organisation(service=service_3, organisation_id=org_3.id) create_annual_billing(service_id=service_3.id, free_sms_fragment_limit=10, financial_year_start=2019) - create_ft_billing(template=template_3, bst_date=datetime(2019, 4, 20), billable_unit=5, rate=0.11) - create_ft_billing(template=template_3, bst_date=datetime(2019, 5, 20), billable_unit=7, rate=0.11) + create_ft_billing(template=template_3, local_date=datetime(2019, 4, 20), billable_unit=5, rate=0.11) + create_ft_billing(template=template_3, local_date=datetime(2019, 5, 20), billable_unit=7, rate=0.11) service_4 = create_service(service_name='d - email only') email_template = create_template(service=service_4, template_type='email') org_4 = create_organisation(name="Org for {}".format(service_4.name)) dao_add_service_to_organisation(service=service_4, organisation_id=org_4.id) create_annual_billing(service_id=service_4.id, free_sms_fragment_limit=10, financial_year_start=2019) - create_ft_billing(template=email_template, bst_date=datetime(2019, 5, 22), notifications_sent=5, + create_ft_billing(template=email_template, local_date=datetime(2019, 5, 22), notifications_sent=5, billable_unit=0, rate=0) results = fetch_sms_billing_for_all_services(datetime(2019, 5, 1), datetime(2019, 5, 31)) @@ -852,7 +852,7 @@ def test_fetch_usage_year_for_organisation(notify_db_session): organisation_id=fixtures["org_1"].id ) template = create_template(service=service_with_emails_for_org, template_type='email') - create_ft_billing(bst_date=datetime(2019, 5, 1), + create_ft_billing(local_date=datetime(2019, 5, 1), template=template, notifications_sent=1100) results = fetch_usage_year_for_organisation(fixtures["org_1"].id, 2019) @@ -920,11 +920,11 @@ def test_fetch_usage_year_for_organisation_calculates_cost_from_multiple_rates(n dao_add_service_to_organisation(service=service_1, organisation_id=org.id) sms_template_1 = create_template(service=service_1) create_ft_billing( - bst_date=old_rate_date, template=sms_template_1, rate=2, + local_date=old_rate_date, template=sms_template_1, rate=2, billable_unit=4, notifications_sent=4 ) create_ft_billing( - bst_date=new_rate_date, template=sms_template_1, rate=3, + local_date=new_rate_date, template=sms_template_1, rate=3, billable_unit=2, notifications_sent=2 ) create_annual_billing(service_id=service_1.id, free_sms_fragment_limit=3, financial_year_start=current_year) @@ -974,15 +974,15 @@ def test_fetch_usage_year_for_organisation_only_queries_present_year(notify_db_s sms_template_1 = create_template(service=service_1) create_ft_billing( - bst_date=date_two_years_ago, template=sms_template_1, rate=1, + local_date=date_two_years_ago, template=sms_template_1, rate=1, billable_unit=2, notifications_sent=2 ) create_ft_billing( - bst_date=date_in_last_financial_year, template=sms_template_1, rate=1, + local_date=date_in_last_financial_year, template=sms_template_1, rate=1, billable_unit=4, notifications_sent=4 ) create_ft_billing( - bst_date=date_in_this_year, template=sms_template_1, rate=1, + local_date=date_in_this_year, template=sms_template_1, rate=1, billable_unit=8, notifications_sent=8 ) create_annual_billing(service_id=service_1.id, free_sms_fragment_limit=4, financial_year_start=last_year - 1) @@ -1008,13 +1008,13 @@ def test_fetch_usage_year_for_organisation_only_returns_data_for_live_services(n trial_letter_template = create_template(service=trial_service, template_type='letter') dao_add_service_to_organisation(service=live_service, organisation_id=org.id) dao_add_service_to_organisation(service=trial_service, organisation_id=org.id) - create_ft_billing(bst_date=datetime.utcnow().date(), template=sms_template, rate=0.0158, + create_ft_billing(local_date=datetime.utcnow().date(), template=sms_template, rate=0.0158, billable_unit=19, notifications_sent=19) - create_ft_billing(bst_date=datetime.utcnow().date(), template=email_template, billable_unit=0, + create_ft_billing(local_date=datetime.utcnow().date(), template=email_template, billable_unit=0, notifications_sent=100) - create_ft_billing(bst_date=datetime.utcnow().date(), template=trial_sms_template, billable_unit=200, rate=0.0158, + create_ft_billing(local_date=datetime.utcnow().date(), template=trial_sms_template, billable_unit=200, rate=0.0158, notifications_sent=100) - create_ft_billing(bst_date=datetime.utcnow().date(), template=trial_letter_template, billable_unit=40, rate=0.30, + create_ft_billing(local_date=datetime.utcnow().date(), template=trial_letter_template, billable_unit=40, rate=0.30, notifications_sent=20) create_annual_billing(service_id=live_service.id, free_sms_fragment_limit=0, financial_year_start=2019) create_annual_billing(service_id=trial_service.id, free_sms_fragment_limit=0, financial_year_start=2019) @@ -1038,11 +1038,11 @@ def test_query_organisation_sms_usage_for_year_handles_multiple_services(notify_ dao_add_service_to_organisation(service=service_1, organisation_id=org.id) sms_template_1 = create_template(service=service_1) create_ft_billing( - bst_date=yesterday, template=sms_template_1, rate=1, + local_date=yesterday, template=sms_template_1, rate=1, billable_unit=4, notifications_sent=4 ) create_ft_billing( - bst_date=today, template=sms_template_1, rate=1, + local_date=today, template=sms_template_1, rate=1, billable_unit=2, notifications_sent=2 ) create_annual_billing(service_id=service_1.id, free_sms_fragment_limit=5, financial_year_start=current_year) @@ -1051,11 +1051,11 @@ def test_query_organisation_sms_usage_for_year_handles_multiple_services(notify_ dao_add_service_to_organisation(service=service_2, organisation_id=org.id) sms_template_2 = create_template(service=service_2) create_ft_billing( - bst_date=yesterday, template=sms_template_2, rate=1, + local_date=yesterday, template=sms_template_2, rate=1, billable_unit=16, notifications_sent=16 ) create_ft_billing( - bst_date=today, template=sms_template_2, rate=1, + local_date=today, template=sms_template_2, rate=1, billable_unit=8, notifications_sent=8 ) create_annual_billing(service_id=service_2.id, free_sms_fragment_limit=10, financial_year_start=current_year) @@ -1072,21 +1072,21 @@ def test_query_organisation_sms_usage_for_year_handles_multiple_services(notify_ # service 1 has allowance of 5 # four fragments in total, all are used - assert service_1_rows[0]['bst_date'] == date(2022, 4, 26) + assert service_1_rows[0]['local_date'] == date(2022, 4, 26) assert service_1_rows[0]['chargeable_units'] == 4 assert service_1_rows[0]['charged_units'] == 0 # two in total - one is free, one is charged - assert service_1_rows[1]['bst_date'] == date(2022, 4, 27) + assert service_1_rows[1]['local_date'] == date(2022, 4, 27) assert service_1_rows[1]['chargeable_units'] == 2 assert service_1_rows[1]['charged_units'] == 1 # service 2 has allowance of 10 # sixteen fragments total, allowance is used and six are charged - assert service_2_rows[0]['bst_date'] == date(2022, 4, 26) + assert service_2_rows[0]['local_date'] == date(2022, 4, 26) assert service_2_rows[0]['chargeable_units'] == 16 assert service_2_rows[0]['charged_units'] == 6 # eight fragments total, all are charged - assert service_2_rows[1]['bst_date'] == date(2022, 4, 27) + assert service_2_rows[1]['local_date'] == date(2022, 4, 27) assert service_2_rows[1]['chargeable_units'] == 8 assert service_2_rows[1]['charged_units'] == 8 @@ -1107,11 +1107,11 @@ def test_query_organisation_sms_usage_for_year_handles_multiple_rates(notify_db_ dao_add_service_to_organisation(service=service_1, organisation_id=org.id) sms_template_1 = create_template(service=service_1) create_ft_billing( - bst_date=old_rate_date, template=sms_template_1, rate=2, + local_date=old_rate_date, template=sms_template_1, rate=2, billable_unit=4, notifications_sent=4 ) create_ft_billing( - bst_date=new_rate_date, template=sms_template_1, rate=3, + local_date=new_rate_date, template=sms_template_1, rate=3, billable_unit=2, notifications_sent=2 ) create_annual_billing(service_id=service_1.id, free_sms_fragment_limit=3, financial_year_start=current_year) @@ -1119,11 +1119,11 @@ def test_query_organisation_sms_usage_for_year_handles_multiple_rates(notify_db_ result = query_organisation_sms_usage_for_year(org.id, 2022).all() # al lthe free allowance is used on the first day - assert result[0]['bst_date'] == date(2022, 4, 29) + assert result[0]['local_date'] == date(2022, 4, 29) assert result[0]['charged_units'] == 1 assert result[0]['cost'] == 2 - assert result[1]['bst_date'] == date(2022, 5, 1) + assert result[1]['local_date'] == date(2022, 5, 1) assert result[1]['charged_units'] == 2 assert result[1]['cost'] == 6 @@ -1131,27 +1131,27 @@ def test_query_organisation_sms_usage_for_year_handles_multiple_rates(notify_db_ def test_fetch_daily_volumes_for_platform( notify_db_session, sample_template, sample_email_template, sample_letter_template ): - create_ft_billing(bst_date='2022-02-03', template=sample_template, + create_ft_billing(local_date='2022-02-03', template=sample_template, notifications_sent=10, billable_unit=10) - create_ft_billing(bst_date='2022-02-03', template=sample_template, + create_ft_billing(local_date='2022-02-03', template=sample_template, notifications_sent=10, billable_unit=30, international=True) - create_ft_billing(bst_date='2022-02-03', template=sample_email_template, notifications_sent=10) - create_ft_billing(bst_date='2022-02-03', template=sample_letter_template, notifications_sent=5, + create_ft_billing(local_date='2022-02-03', template=sample_email_template, notifications_sent=10) + create_ft_billing(local_date='2022-02-03', template=sample_letter_template, notifications_sent=5, billable_unit=5, rate=0.39) - create_ft_billing(bst_date='2022-02-03', template=sample_letter_template, notifications_sent=5, + create_ft_billing(local_date='2022-02-03', template=sample_letter_template, notifications_sent=5, billable_unit=10, rate=0.44) - create_ft_billing(bst_date='2022-02-04', template=sample_template, + create_ft_billing(local_date='2022-02-04', template=sample_template, notifications_sent=20, billable_unit=40) - create_ft_billing(bst_date='2022-02-04', template=sample_template, + create_ft_billing(local_date='2022-02-04', template=sample_template, notifications_sent=10, billable_unit=20, rate_multiplier=3) - create_ft_billing(bst_date='2022-02-04', template=sample_email_template, notifications_sent=50) - create_ft_billing(bst_date='2022-02-04', template=sample_letter_template, notifications_sent=20, billable_unit=40) + create_ft_billing(local_date='2022-02-04', template=sample_email_template, notifications_sent=50) + create_ft_billing(local_date='2022-02-04', template=sample_letter_template, notifications_sent=20, billable_unit=40) results = fetch_daily_volumes_for_platform(start_date='2022-02-03', end_date='2022-02-04') assert len(results) == 2 - assert results[0].bst_date == '2022-02-03' + assert results[0].local_date == '2022-02-03' assert results[0].sms_totals == 20 assert results[0].sms_fragment_totals == 40 assert results[0].sms_chargeable_units == 40 @@ -1159,7 +1159,7 @@ def test_fetch_daily_volumes_for_platform( assert results[0].letter_totals == 10 assert results[0].letter_sheet_totals == 15 - assert results[1].bst_date == '2022-02-04' + assert results[1].local_date == '2022-02-04' assert results[1].sms_totals == 30 assert results[1].sms_fragment_totals == 60 assert results[1].sms_chargeable_units == 100 @@ -1227,8 +1227,8 @@ def test_fetch_daily_sms_provider_volumes_for_platform_for_platform_searches_dat results = fetch_daily_sms_provider_volumes_for_platform(start_date='2022-02-03', end_date='2022-02-05') assert len(results) == 3 - assert results[0].bst_date == date(2022, 2, 3) - assert results[-1].bst_date == date(2022, 2, 5) + assert results[0].local_date == date(2022, 2, 3) + assert results[-1].local_date == date(2022, 2, 5) def test_fetch_daily_sms_provider_volumes_for_platform_for_platform_only_returns_sms( diff --git a/tests/app/dao/test_fact_notification_status_dao.py b/tests/app/dao/test_fact_notification_status_dao.py index b9065a149..3b5205648 100644 --- a/tests/app/dao/test_fact_notification_status_dao.py +++ b/tests/app/dao/test_fact_notification_status_dao.py @@ -374,21 +374,21 @@ def test_fetch_monthly_template_usage_for_service(sample_service): template_two = create_template(service=sample_service, template_type='email', template_name='b') template_three = create_template(service=sample_service, template_type='letter', template_name='c') - create_ft_notification_status(bst_date=date(2017, 12, 10), + create_ft_notification_status(local_date=date(2017, 12, 10), service=sample_service, template=template_two, count=3) - create_ft_notification_status(bst_date=date(2017, 12, 10), + create_ft_notification_status(local_date=date(2017, 12, 10), service=sample_service, template=template_one, count=6) - create_ft_notification_status(bst_date=date(2018, 1, 1), + create_ft_notification_status(local_date=date(2018, 1, 1), service=sample_service, template=template_one, count=4) - create_ft_notification_status(bst_date=date(2018, 3, 1), + create_ft_notification_status(local_date=date(2018, 3, 1), service=sample_service, template=template_three, count=5) @@ -438,15 +438,15 @@ def test_fetch_monthly_template_usage_for_service_does_join_to_notifications_if_ ): template_one = create_template(service=sample_service, template_type='sms', template_name='a') template_two = create_template(service=sample_service, template_type='email', template_name='b') - create_ft_notification_status(bst_date=date(2018, 2, 1), + create_ft_notification_status(local_date=date(2018, 2, 1), service=template_two.service, template=template_two, count=15) - create_ft_notification_status(bst_date=date(2018, 2, 2), + create_ft_notification_status(local_date=date(2018, 2, 2), service=template_one.service, template=template_one, count=20) - create_ft_notification_status(bst_date=date(2018, 3, 1), + create_ft_notification_status(local_date=date(2018, 3, 1), service=template_one.service, template=template_one, count=3) @@ -477,7 +477,7 @@ def test_fetch_monthly_template_usage_for_service_does_join_to_notifications_if_ def test_fetch_monthly_template_usage_for_service_does_not_include_cancelled_status( sample_template ): - create_ft_notification_status(bst_date=date(2018, 3, 1), + create_ft_notification_status(local_date=date(2018, 3, 1), service=sample_template.service, template=sample_template, notification_status='cancelled', @@ -494,7 +494,7 @@ def test_fetch_monthly_template_usage_for_service_does_not_include_cancelled_sta def test_fetch_monthly_template_usage_for_service_does_not_include_test_notifications( sample_template ): - create_ft_notification_status(bst_date=date(2018, 3, 1), + create_ft_notification_status(local_date=date(2018, 3, 1), service=sample_template.service, template=sample_template, notification_status='delivered', @@ -579,28 +579,28 @@ def test_get_total_notifications_for_date_range(sample_service): template_sms = create_template(service=sample_service, template_type='sms', template_name='a') template_email = create_template(service=sample_service, template_type='email', template_name='b') template_letter = create_template(service=sample_service, template_type='letter', template_name='c') - create_ft_notification_status(bst_date=date(2021, 2, 28), + create_ft_notification_status(local_date=date(2021, 2, 28), service=template_email.service, template=template_email, count=15) - create_ft_notification_status(bst_date=date(2021, 2, 28), + create_ft_notification_status(local_date=date(2021, 2, 28), service=template_sms.service, template=template_sms, count=20) - create_ft_notification_status(bst_date=date(2021, 2, 28), + create_ft_notification_status(local_date=date(2021, 2, 28), service=template_letter.service, template=template_letter, count=3) - create_ft_notification_status(bst_date=date(2021, 3, 1), + create_ft_notification_status(local_date=date(2021, 3, 1), service=template_email.service, template=template_email, count=15) - create_ft_notification_status(bst_date=date(2021, 3, 1), + create_ft_notification_status(local_date=date(2021, 3, 1), service=template_sms.service, template=template_sms, count=20) - create_ft_notification_status(bst_date=date(2021, 3, 1), + create_ft_notification_status(local_date=date(2021, 3, 1), service=template_letter.service, template=template_letter, count=3) @@ -633,5 +633,5 @@ def test_update_fact_notification_status_respects_gmt_bst( assert FactNotificationStatus.query.filter_by( service_id=sample_service.id, - bst_date=process_day + local_date=process_day ).count() == expected_count diff --git a/tests/app/dao/test_fact_processing_time_dao.py b/tests/app/dao/test_fact_processing_time_dao.py index 206245153..99f033be7 100644 --- a/tests/app/dao/test_fact_processing_time_dao.py +++ b/tests/app/dao/test_fact_processing_time_dao.py @@ -12,7 +12,7 @@ from tests.app.db import create_process_time def test_insert_update_processing_time(notify_db_session): data = FactProcessingTime( - bst_date=datetime(2021, 2, 22).date(), + local_date=datetime(2021, 2, 22).date(), messages_total=3, messages_within_10_secs=2 ) @@ -22,14 +22,14 @@ def test_insert_update_processing_time(notify_db_session): result = FactProcessingTime.query.all() assert len(result) == 1 - assert result[0].bst_date == datetime(2021, 2, 22).date() + assert result[0].local_date == datetime(2021, 2, 22).date() assert result[0].messages_total == 3 assert result[0].messages_within_10_secs == 2 assert result[0].created_at assert not result[0].updated_at data = FactProcessingTime( - bst_date=datetime(2021, 2, 22).date(), + local_date=datetime(2021, 2, 22).date(), messages_total=4, messages_within_10_secs=3 ) @@ -39,7 +39,7 @@ def test_insert_update_processing_time(notify_db_session): result = FactProcessingTime.query.all() assert len(result) == 1 - assert result[0].bst_date == datetime(2021, 2, 22).date() + assert result[0].local_date == datetime(2021, 2, 22).date() assert result[0].messages_total == 4 assert result[0].messages_within_10_secs == 3 assert result[0].created_at @@ -48,17 +48,17 @@ def test_insert_update_processing_time(notify_db_session): def test_get_processing_time_percentage_for_date_range(notify_db_session): create_process_time( - bst_date='2021-02-21', + local_date='2021-02-21', messages_total=5, messages_within_10_secs=4 ) create_process_time( - bst_date='2021-02-22', + local_date='2021-02-22', messages_total=3, messages_within_10_secs=2 ) create_process_time( - bst_date='2021-02-23', + local_date='2021-02-23', messages_total=4, messages_within_10_secs=3 ) @@ -74,12 +74,12 @@ def test_get_processing_time_percentage_for_date_range(notify_db_session): def test_get_processing_time_percentage_for_date_range_handles_zero_cases(notify_db_session): create_process_time( - bst_date='2021-02-21', + local_date='2021-02-21', messages_total=0, messages_within_10_secs=0 ) create_process_time( - bst_date='2021-02-22', + local_date='2021-02-22', messages_total=10, messages_within_10_secs=0 ) diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index ce119471c..899f003c4 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -461,16 +461,16 @@ def test_dao_fetch_live_services_data(sample_user): template_letter_2 = create_template(service=service_2, template_type='letter') dao_add_service_to_organisation(service=service, organisation_id=org.id) # two sms billing records for 1st service within current financial year: - create_ft_billing(bst_date='2019-04-20', template=sms_template) - create_ft_billing(bst_date='2019-04-21', template=sms_template) + create_ft_billing(local_date='2019-04-20', template=sms_template) + create_ft_billing(local_date='2019-04-21', template=sms_template) # one sms billing record for 1st service from previous financial year, should not appear in the result: - create_ft_billing(bst_date='2018-04-20', template=sms_template) + create_ft_billing(local_date='2018-04-20', template=sms_template) # one email billing record for 1st service within current financial year: - create_ft_billing(bst_date='2019-04-20', template=email_template) + create_ft_billing(local_date='2019-04-20', template=email_template) # one letter billing record for 1st service within current financial year: - create_ft_billing(bst_date='2019-04-15', template=template_letter_1) + create_ft_billing(local_date='2019-04-15', template=template_letter_1) # one letter billing record for 2nd service within current financial year: - create_ft_billing(bst_date='2019-04-16', template=template_letter_2) + create_ft_billing(local_date='2019-04-16', template=template_letter_2) # 1st service: billing from 2018 and 2019 create_annual_billing(service.id, 500, 2018) diff --git a/tests/app/db.py b/tests/app/db.py index 53c6f43fe..729ed8b29 100644 --- a/tests/app/db.py +++ b/tests/app/db.py @@ -716,7 +716,7 @@ def create_daily_sorted_letter(billing_day=None, return daily_sorted_letter -def create_ft_billing(bst_date, +def create_ft_billing(local_date, template, *, provider='test', @@ -727,7 +727,7 @@ def create_ft_billing(bst_date, notifications_sent=1, postage='none' ): - data = FactBilling(bst_date=bst_date, + data = FactBilling(local_date=local_date, service_id=template.service_id, template_id=template.id, notification_type=template.template_type, @@ -744,7 +744,7 @@ def create_ft_billing(bst_date, def create_ft_notification_status( - bst_date, + local_date, notification_type='sms', service=None, template=None, @@ -764,7 +764,7 @@ def create_ft_notification_status( template = create_template(service=service, template_type=notification_type) data = FactNotificationStatus( - bst_date=bst_date, + local_date=local_date, template_id=template.id, service_id=service.id, job_id=job.id if job else uuid.UUID(int=0), @@ -778,9 +778,9 @@ def create_ft_notification_status( return data -def create_process_time(bst_date='2021-03-01', messages_total=35, messages_within_10_secs=34): +def create_process_time(local_date='2021-03-01', messages_total=35, messages_within_10_secs=34): data = FactProcessingTime( - bst_date=bst_date, + local_date=local_date, messages_total=messages_total, messages_within_10_secs=messages_within_10_secs ) @@ -972,15 +972,15 @@ def set_up_usage_data(start_date): organisation_id=org_1.id ) - create_ft_billing(bst_date=one_week_earlier, template=sms_template_1, billable_unit=2, rate=0.11) - create_ft_billing(bst_date=start_date, template=sms_template_1, billable_unit=2, rate=0.11) - create_ft_billing(bst_date=two_days_later, template=sms_template_1, billable_unit=1, rate=0.11) + create_ft_billing(local_date=one_week_earlier, template=sms_template_1, billable_unit=2, rate=0.11) + create_ft_billing(local_date=start_date, template=sms_template_1, billable_unit=2, rate=0.11) + create_ft_billing(local_date=two_days_later, template=sms_template_1, billable_unit=1, rate=0.11) - create_ft_billing(bst_date=one_week_later, template=letter_template_1, + create_ft_billing(local_date=one_week_later, template=letter_template_1, notifications_sent=2, billable_unit=2, rate=.35, postage='first') - create_ft_billing(bst_date=one_month_later, template=letter_template_1, + create_ft_billing(local_date=one_month_later, template=letter_template_1, notifications_sent=4, billable_unit=8, rate=.45, postage='second') - create_ft_billing(bst_date=one_week_later, template=letter_template_1, + create_ft_billing(local_date=one_week_later, template=letter_template_1, notifications_sent=2, billable_unit=4, rate=.45, postage='second') # service with emails only: @@ -992,7 +992,7 @@ def set_up_usage_data(start_date): dao_add_service_to_organisation(service=service_with_emails, organisation_id=org_2.id) create_annual_billing(service_id=service_with_emails.id, free_sms_fragment_limit=0, financial_year_start=year) - create_ft_billing(bst_date=start_date, template=email_template, notifications_sent=10) + create_ft_billing(local_date=start_date, template=email_template, notifications_sent=10) # service with letters: service_with_letters = create_service(service_name='c - letters only') @@ -1007,11 +1007,11 @@ def set_up_usage_data(start_date): dao_add_service_to_organisation(service=service_with_letters, organisation_id=org_for_service_with_letters.id) create_annual_billing(service_id=service_with_letters.id, free_sms_fragment_limit=0, financial_year_start=year) - create_ft_billing(bst_date=start_date, template=letter_template_3, + create_ft_billing(local_date=start_date, template=letter_template_3, notifications_sent=2, billable_unit=3, rate=.50, postage='first') - create_ft_billing(bst_date=one_week_later, template=letter_template_3, + create_ft_billing(local_date=one_week_later, template=letter_template_3, notifications_sent=8, billable_unit=5, rate=.65, postage='second') - create_ft_billing(bst_date=one_month_later, template=letter_template_3, + create_ft_billing(local_date=one_month_later, template=letter_template_3, notifications_sent=12, billable_unit=5, rate=.65, postage='second') # service with letters, without an organisation: @@ -1023,13 +1023,13 @@ def set_up_usage_data(start_date): financial_year_start=year ) - create_ft_billing(bst_date=two_days_later, template=letter_template_4, + create_ft_billing(local_date=two_days_later, template=letter_template_4, notifications_sent=7, billable_unit=4, rate=1.55, postage='rest-of-world') - create_ft_billing(bst_date=two_days_later, template=letter_template_4, + create_ft_billing(local_date=two_days_later, template=letter_template_4, notifications_sent=8, billable_unit=4, rate=1.55, postage='europe') - create_ft_billing(bst_date=two_days_later, template=letter_template_4, + create_ft_billing(local_date=two_days_later, template=letter_template_4, notifications_sent=2, billable_unit=1, rate=.35, postage='second') - create_ft_billing(bst_date=two_days_later, template=letter_template_4, + create_ft_billing(local_date=two_days_later, template=letter_template_4, notifications_sent=1, billable_unit=1, rate=.50, postage='first') # service with chargeable SMS, without an organisation @@ -1044,9 +1044,9 @@ def set_up_usage_data(start_date): create_annual_billing( service_id=service_with_sms_without_org.id, free_sms_fragment_limit=10, financial_year_start=year ) - create_ft_billing(bst_date=one_week_earlier, template=sms_template, rate=0.11, billable_unit=12) - create_ft_billing(bst_date=two_days_later, template=sms_template, rate=0.11) - create_ft_billing(bst_date=one_week_later, template=sms_template, billable_unit=2, rate=0.11) + create_ft_billing(local_date=one_week_earlier, template=sms_template, rate=0.11, billable_unit=12) + create_ft_billing(local_date=two_days_later, template=sms_template, rate=0.11) + create_ft_billing(local_date=one_week_later, template=sms_template, billable_unit=2, rate=0.11) # service with SMS within free allowance service_with_sms_within_allowance = create_service( @@ -1056,7 +1056,7 @@ def set_up_usage_data(start_date): create_annual_billing( service_id=service_with_sms_within_allowance.id, free_sms_fragment_limit=10, financial_year_start=year ) - create_ft_billing(bst_date=one_week_later, template=sms_template_2, billable_unit=2, rate=0.11) + create_ft_billing(local_date=one_week_later, template=sms_template_2, billable_unit=2, rate=0.11) # service without ft_billing this year service_with_out_ft_billing_this_year = create_service( diff --git a/tests/app/job/test_rest.py b/tests/app/job/test_rest.py index f0cdc60d9..5d4e6e075 100644 --- a/tests/app/job/test_rest.py +++ b/tests/app/job/test_rest.py @@ -667,7 +667,7 @@ def test_get_job_by_id_with_stats_for_old_job_where_notifications_have_been_purg job_status='finished') def __create_ft_status(job, status, count): - create_ft_notification_status(bst_date=job.created_at.date(), + create_ft_notification_status(local_date=job.created_at.date(), notification_type='sms', service=job.service, job=job, diff --git a/tests/app/organisation/test_rest.py b/tests/app/organisation/test_rest.py index cc5d68a23..dd7f24e0a 100644 --- a/tests/app/organisation/test_rest.py +++ b/tests/app/organisation/test_rest.py @@ -833,7 +833,7 @@ def test_get_organisation_services_usage(admin_request, notify_db_session): template = create_template(service=service) dao_add_service_to_organisation(service=service, organisation_id=org.id) create_annual_billing(service_id=service.id, free_sms_fragment_limit=10, financial_year_start=2019) - create_ft_billing(bst_date=datetime.utcnow().date(), template=template, billable_unit=19, rate=0.060, + create_ft_billing(local_date=datetime.utcnow().date(), template=template, billable_unit=19, rate=0.060, notifications_sent=19) response = admin_request.get( 'organisation.get_organisation_services_usage', @@ -863,7 +863,7 @@ def test_get_organisation_services_usage_sort_active_first(admin_request, notify dao_add_service_to_organisation(service=service, organisation_id=org.id) dao_add_service_to_organisation(service=archived_service, organisation_id=org.id) create_annual_billing(service_id=service.id, free_sms_fragment_limit=10, financial_year_start=2019) - create_ft_billing(bst_date=datetime.utcnow().date(), template=template, billable_unit=19, rate=0.060, + create_ft_billing(local_date=datetime.utcnow().date(), template=template, billable_unit=19, rate=0.060, notifications_sent=19) response = admin_request.get( 'organisation.get_organisation_services_usage', diff --git a/tests/app/performance_dashboard/test_rest.py b/tests/app/performance_dashboard/test_rest.py index ea75a64db..5ac33c1b0 100644 --- a/tests/app/performance_dashboard/test_rest.py +++ b/tests/app/performance_dashboard/test_rest.py @@ -14,59 +14,59 @@ def test_performance_dashboard(sample_service, admin_request): template_sms = create_template(service=sample_service, template_type='sms', template_name='a') template_email = create_template(service=sample_service, template_type='email', template_name='b') template_letter = create_template(service=sample_service, template_type='letter', template_name='c') - create_ft_notification_status(bst_date=date(2021, 2, 28), + create_ft_notification_status(local_date=date(2021, 2, 28), service=template_email.service, template=template_email, count=10) - create_ft_notification_status(bst_date=date(2021, 2, 28), + create_ft_notification_status(local_date=date(2021, 2, 28), service=template_sms.service, template=template_sms, count=5) - create_ft_notification_status(bst_date=date(2021, 2, 28), + create_ft_notification_status(local_date=date(2021, 2, 28), service=template_letter.service, template=template_letter, count=2) - create_ft_notification_status(bst_date=date(2021, 3, 1), + create_ft_notification_status(local_date=date(2021, 3, 1), service=template_email.service, template=template_email, count=15) - create_ft_notification_status(bst_date=date(2021, 3, 1), + create_ft_notification_status(local_date=date(2021, 3, 1), service=template_sms.service, template=template_sms, count=20) - create_ft_notification_status(bst_date=date(2021, 3, 1), + create_ft_notification_status(local_date=date(2021, 3, 1), service=template_letter.service, template=template_letter, count=3) - create_ft_notification_status(bst_date=date(2021, 3, 2), + create_ft_notification_status(local_date=date(2021, 3, 2), service=template_email.service, template=template_email, count=25) - create_ft_notification_status(bst_date=date(2021, 3, 2), + create_ft_notification_status(local_date=date(2021, 3, 2), service=template_sms.service, template=template_sms, count=30) - create_ft_notification_status(bst_date=date(2021, 3, 2), + create_ft_notification_status(local_date=date(2021, 3, 2), service=template_letter.service, template=template_letter, count=10) - create_ft_notification_status(bst_date=date(2021, 3, 3), + create_ft_notification_status(local_date=date(2021, 3, 3), service=template_email.service, template=template_email, count=45) - create_ft_notification_status(bst_date=date(2021, 3, 3), + create_ft_notification_status(local_date=date(2021, 3, 3), service=template_sms.service, template=template_sms, count=35) - create_ft_notification_status(bst_date=date(2021, 3, 3), + create_ft_notification_status(local_date=date(2021, 3, 3), service=template_letter.service, template=template_letter, count=15) - create_process_time(bst_date='2021-02-28', messages_total=15, messages_within_10_secs=14) - create_process_time(bst_date='2021-03-01', messages_total=35, messages_within_10_secs=34) - create_process_time(bst_date='2021-03-02', messages_total=15, messages_within_10_secs=12) - create_process_time(bst_date='2021-03-03', messages_total=15, messages_within_10_secs=14) + create_process_time(local_date='2021-02-28', messages_total=15, messages_within_10_secs=14) + create_process_time(local_date='2021-03-01', messages_total=35, messages_within_10_secs=34) + create_process_time(local_date='2021-03-02', messages_total=15, messages_within_10_secs=12) + create_process_time(local_date='2021-03-03', messages_total=15, messages_within_10_secs=14) results = admin_request.get(endpoint="performance_dashboard.get_performance_dashboard", start_date='2021-03-01', diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 64bf6c46d..278446a7b 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -191,8 +191,8 @@ def test_get_live_services_data(sample_user, admin_request): sms_template = create_template(service=service) email_template = create_template(service=service, template_type='email') dao_add_service_to_organisation(service=service, organisation_id=org.id) - create_ft_billing(bst_date='2019-04-20', template=sms_template) - create_ft_billing(bst_date='2019-04-20', template=email_template) + create_ft_billing(local_date='2019-04-20', template=sms_template) + create_ft_billing(local_date='2019-04-20', template=email_template) create_annual_billing(service.id, 1, 2019) create_annual_billing(service_2.id, 2, 2018) @@ -2188,13 +2188,13 @@ def test_get_detailed_services_only_includes_todays_notifications(sample_templat def test_get_detailed_services_for_date_range(sample_template, start_date_delta, end_date_delta): from app.service.rest import get_detailed_services - create_ft_notification_status(bst_date=(datetime.utcnow() - timedelta(days=3)).date(), + create_ft_notification_status(local_date=(datetime.utcnow() - timedelta(days=3)).date(), service=sample_template.service, notification_type='sms') - create_ft_notification_status(bst_date=(datetime.utcnow() - timedelta(days=2)).date(), + create_ft_notification_status(local_date=(datetime.utcnow() - timedelta(days=2)).date(), service=sample_template.service, notification_type='sms') - create_ft_notification_status(bst_date=(datetime.utcnow() - timedelta(days=1)).date(), + create_ft_notification_status(local_date=(datetime.utcnow() - timedelta(days=1)).date(), service=sample_template.service, notification_type='sms') diff --git a/tests/app/service/test_statistics_rest.py b/tests/app/service/test_statistics_rest.py index ae577dd80..ee5d2ab36 100644 --- a/tests/app/service/test_statistics_rest.py +++ b/tests/app/service/test_statistics_rest.py @@ -26,7 +26,7 @@ def test_get_template_usage_by_month_returns_correct_data( admin_request, sample_template ): - create_ft_notification_status(bst_date=date(2017, 4, 2), template=sample_template, count=3) + create_ft_notification_status(local_date=date(2017, 4, 2), template=sample_template, count=3) create_notification(sample_template, created_at=datetime.utcnow()) resp_json = admin_request.get( @@ -61,8 +61,8 @@ def test_get_template_usage_by_month_returns_two_templates(admin_request, sample template_name=PRECOMPILED_TEMPLATE_NAME, hidden=True ) - create_ft_notification_status(bst_date=datetime(2017, 4, 2), template=template_one, count=1) - create_ft_notification_status(bst_date=datetime(2017, 4, 2), template=sample_template, count=3) + create_ft_notification_status(local_date=datetime(2017, 4, 2), template=template_one, count=1) + create_ft_notification_status(local_date=datetime(2017, 4, 2), template=sample_template, count=3) create_notification(sample_template, created_at=datetime.utcnow()) resp_json = admin_request.get( diff --git a/tests/app/template_statistics/test_rest.py b/tests/app/template_statistics/test_rest.py index 1eeef92a2..efc063af4 100644 --- a/tests/app/template_statistics/test_rest.py +++ b/tests/app/template_statistics/test_rest.py @@ -127,7 +127,7 @@ def test_get_last_used_datetime_for_template( date_from_notification = datetime.utcnow() - timedelta(hours=2) create_notification(template=sample_template, created_at=date_from_notification) date_from_ft_status = (datetime.utcnow() - timedelta(days=2)).date() - create_ft_notification_status(bst_date=date_from_ft_status, + create_ft_notification_status(local_date=date_from_ft_status, template=sample_template) json_resp = admin_request.get(