mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Merge pull request #3454 from alphagov/upsert-status-180693991
Rewrite status aggregation to be a bulk upsert
This commit is contained in:
@@ -599,9 +599,10 @@ def test_create_nightly_notification_status_for_service_and_day(notify_db_sessio
|
||||
def test_create_nightly_notification_status_for_service_and_day_overwrites_old_data(notify_db_session):
|
||||
first_service = create_service(service_name='First Service')
|
||||
first_template = create_template(service=first_service)
|
||||
create_notification(template=first_template, status='delivered')
|
||||
|
||||
process_day = date.today()
|
||||
|
||||
# first run: one notification, expect one row (just one status)
|
||||
notification = create_notification(template=first_template, status='sending')
|
||||
create_nightly_notification_status_for_service_and_day(str(process_day), first_service.id, 'sms')
|
||||
|
||||
new_fact_data = FactNotificationStatus.query.order_by(
|
||||
@@ -611,8 +612,11 @@ def test_create_nightly_notification_status_for_service_and_day_overwrites_old_d
|
||||
|
||||
assert len(new_fact_data) == 1
|
||||
assert new_fact_data[0].notification_count == 1
|
||||
assert new_fact_data[0].notification_status == 'sending'
|
||||
|
||||
create_notification(template=first_template, status='delivered')
|
||||
# second run: status changed, still expect one row (one status)
|
||||
notification.status = 'delivered'
|
||||
create_notification(template=first_template, status='created')
|
||||
create_nightly_notification_status_for_service_and_day(str(process_day), first_service.id, 'sms')
|
||||
|
||||
updated_fact_data = FactNotificationStatus.query.order_by(
|
||||
@@ -620,8 +624,11 @@ def test_create_nightly_notification_status_for_service_and_day_overwrites_old_d
|
||||
FactNotificationStatus.notification_type
|
||||
).all()
|
||||
|
||||
assert len(updated_fact_data) == 1
|
||||
assert updated_fact_data[0].notification_count == 2
|
||||
assert len(updated_fact_data) == 2
|
||||
assert updated_fact_data[0].notification_count == 1
|
||||
assert updated_fact_data[0].notification_status == 'created'
|
||||
assert updated_fact_data[1].notification_count == 1
|
||||
assert updated_fact_data[1].notification_status == 'delivered'
|
||||
|
||||
|
||||
# the job runs at 12:30am London time. 04/01 is in BST.
|
||||
|
||||
@@ -14,8 +14,8 @@ from app.dao.fact_notification_status_dao import (
|
||||
fetch_notification_status_totals_for_all_services,
|
||||
fetch_notification_statuses_for_job,
|
||||
fetch_stats_for_all_services_by_date_range,
|
||||
fetch_status_data_for_service_and_day,
|
||||
get_total_notifications_for_date_range,
|
||||
update_fact_notification_status,
|
||||
)
|
||||
from app.models import (
|
||||
EMAIL_TYPE,
|
||||
@@ -32,6 +32,7 @@ from app.models import (
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
NOTIFICATION_TEMPORARY_FAILURE,
|
||||
SMS_TYPE,
|
||||
FactNotificationStatus,
|
||||
)
|
||||
from tests.app.db import (
|
||||
create_ft_notification_status,
|
||||
@@ -618,7 +619,7 @@ def test_get_total_notifications_for_date_range(sample_service):
|
||||
('2022-03-27T23:30', date(2022, 3, 27), 0), # 28/03 00:30 BST
|
||||
('2022-03-26T23:30', date(2022, 3, 26), 1), # 26/03 23:30 GMT
|
||||
])
|
||||
def test_fetch_status_data_for_service_and_day_respects_gmt_bst(
|
||||
def test_update_fact_notification_status_respects_gmt_bst(
|
||||
sample_template,
|
||||
sample_service,
|
||||
created_at_utc,
|
||||
@@ -626,5 +627,9 @@ def test_fetch_status_data_for_service_and_day_respects_gmt_bst(
|
||||
expected_count,
|
||||
):
|
||||
create_notification(template=sample_template, created_at=created_at_utc)
|
||||
rows = fetch_status_data_for_service_and_day(process_day, sample_service.id, SMS_TYPE)
|
||||
assert len(rows) == expected_count
|
||||
update_fact_notification_status(process_day, SMS_TYPE, sample_service.id)
|
||||
|
||||
assert FactNotificationStatus.query.filter_by(
|
||||
service_id=sample_service.id,
|
||||
bst_date=process_day
|
||||
).count() == expected_count
|
||||
|
||||
Reference in New Issue
Block a user