Added a date range filter for the get all services end point.

When the start_date and end_date query argruments exists in the request,
the query will return the results from the NotificationHistory table for the given date range.
We will need to check the performance of this query, but this will only be used by the platform admin page.
This commit is contained in:
Rebecca Law
2016-12-28 15:39:55 +00:00
parent 8c5c712f2b
commit 8ad078b663
4 changed files with 81 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timedelta
import uuid
import functools
@@ -21,7 +21,8 @@ from app.dao.services_dao import (
dao_fetch_todays_stats_for_service,
dao_fetch_weekly_historical_stats_for_service,
fetch_todays_total_message_count,
dao_fetch_todays_stats_for_all_services
dao_fetch_todays_stats_for_all_services,
fetch_stats_by_date_range_for_all_services
)
from app.dao.users_dao import save_model_user
from app.models import (
@@ -639,3 +640,19 @@ def test_dao_fetch_todays_stats_for_all_services_can_exclude_from_test_key(notif
assert len(stats) == 1
assert stats[0].count == 2
def test_fetch_stats_by_date_range_for_all_services(notify_db, notify_db_session):
create_notification(notify_db, notify_db_session, created_at=datetime.now() - timedelta(days=4))
create_notification(notify_db, notify_db_session, created_at=datetime.now() - timedelta(days=3))
result_one = create_notification(notify_db, notify_db_session, created_at=datetime.now() - timedelta(days=2))
create_notification(notify_db, notify_db_session, created_at=datetime.now() - timedelta(days=1))
create_notification(notify_db, notify_db_session, created_at=datetime.now())
start_date = (datetime.utcnow() - timedelta(days=2)).date()
end_date = (datetime.utcnow() - timedelta(days=1)).date()
results = fetch_stats_by_date_range_for_all_services(start_date, end_date).all()
assert len(results) == 1
assert results[0] == ('sms', 'created', result_one.service_id, 2)