Remove scalars from execute and add test coverage

This commit is contained in:
Andrew Shumway
2024-11-07 09:45:56 -07:00
parent 165042b37c
commit 6df7a218a7
2 changed files with 41 additions and 1 deletions

View File

@@ -474,7 +474,7 @@ def dao_fetch_stats_for_service_from_days(service_id, start_date, end_date):
func.date_trunc("day", NotificationAllTimeView.created_at),
)
)
return db.session.execute(stmt).scalars().all()
return db.session.execute(stmt).all()
def dao_fetch_stats_for_service_from_days_for_user(

View File

@@ -3634,3 +3634,43 @@ def test_get_monthly_notification_data_by_service(sample_service, admin_request)
0,
],
]
def test_get_service_notification_statistics_by_day(
admin_request, mocker, sample_service
):
mock_data = [
{
"notification_type": "email",
"status": "sent",
"day": "2024-11-01",
"count": 10,
},
{
"notification_type": "sms",
"status": "failed",
"day": "2024-11-02",
"count": 5,
},
{
"notification_type": "sms",
"status": "delivered",
"day": "2024-11-03",
"count": 11,
},
]
mock_get_service_statistics_for_specific_days = mocker.patch(
"app.service.rest.get_service_statistics_for_specific_days",
return_value=mock_data,
)
response = admin_request.get(
"service.get_service_notification_statistics_by_day",
service_id=sample_service.id,
start="2024-11-03",
days="1",
)["data"]
assert mock_get_service_statistics_for_specific_days.assert_called_once
assert response == mock_data