mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
Update the query to execute immediately.
Fix indent. Left a comment as to why start and end date are not set.
This commit is contained in:
@@ -262,7 +262,7 @@ def dao_fetch_todays_stats_for_all_services(include_from_test_key=True):
|
|||||||
if not include_from_test_key:
|
if not include_from_test_key:
|
||||||
query = query.filter(Notification.key_type != KEY_TYPE_TEST)
|
query = query.filter(Notification.key_type != KEY_TYPE_TEST)
|
||||||
|
|
||||||
return query
|
return query.all()
|
||||||
|
|
||||||
|
|
||||||
@statsd(namespace='dao')
|
@statsd(namespace='dao')
|
||||||
@@ -290,4 +290,4 @@ def fetch_stats_by_date_range_for_all_services(start_date, end_date, include_fro
|
|||||||
if not include_from_test_key:
|
if not include_from_test_key:
|
||||||
query = query.filter(NotificationHistory.key_type != KEY_TYPE_TEST)
|
query = query.filter(NotificationHistory.key_type != KEY_TYPE_TEST)
|
||||||
|
|
||||||
return query
|
return query.all()
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ def get_services():
|
|||||||
detailed = request.args.get('detailed') == 'True'
|
detailed = request.args.get('detailed') == 'True'
|
||||||
user_id = request.args.get('user_id', None)
|
user_id = request.args.get('user_id', None)
|
||||||
include_from_test_key = request.args.get('include_from_test_key', 'True') != 'False'
|
include_from_test_key = request.args.get('include_from_test_key', 'True') != 'False'
|
||||||
|
# If start and end date are not set in the request.args, we are expecting today's stats.
|
||||||
start_date = request.args.get('start_date', None)
|
start_date = request.args.get('start_date', None)
|
||||||
end_date = request.args.get('end_date', None)
|
end_date = request.args.get('end_date', None)
|
||||||
|
|
||||||
@@ -283,7 +284,7 @@ def get_detailed_services(only_active=False, include_from_test_key=True, start_d
|
|||||||
stats = dao_fetch_todays_stats_for_all_services(include_from_test_key=include_from_test_key)
|
stats = dao_fetch_todays_stats_for_all_services(include_from_test_key=include_from_test_key)
|
||||||
|
|
||||||
for service_id, rows in itertools.groupby(stats, lambda x: x.service_id):
|
for service_id, rows in itertools.groupby(stats, lambda x: x.service_id):
|
||||||
services[service_id].statistics = statistics.format_statistics(rows)
|
services[service_id].statistics = statistics.format_statistics(rows)
|
||||||
|
|
||||||
# if service has not sent anything, query will not have set statistics correctly
|
# if service has not sent anything, query will not have set statistics correctly
|
||||||
for service in services.values():
|
for service in services.values():
|
||||||
|
|||||||
@@ -576,7 +576,7 @@ def test_dao_fetch_todays_stats_for_all_services_includes_all_services(notify_db
|
|||||||
notify_db, notify_db_session, service=service2,
|
notify_db, notify_db_session, service=service2,
|
||||||
template=create_email_template(notify_db, notify_db_session, service=service2))
|
template=create_email_template(notify_db, notify_db_session, service=service2))
|
||||||
|
|
||||||
stats = dao_fetch_todays_stats_for_all_services().all()
|
stats = dao_fetch_todays_stats_for_all_services()
|
||||||
|
|
||||||
assert len(stats) == 4
|
assert len(stats) == 4
|
||||||
# services are ordered by service id; not explicit on email/sms or status
|
# services are ordered by service id; not explicit on email/sms or status
|
||||||
@@ -591,7 +591,7 @@ def test_dao_fetch_todays_stats_for_all_services_only_includes_today(notify_db):
|
|||||||
just_after_midnight_today = create_notification(notify_db, None, to_field='2', status='failed')
|
just_after_midnight_today = create_notification(notify_db, None, to_field='2', status='failed')
|
||||||
|
|
||||||
with freeze_time('2001-01-02T12:00:00'):
|
with freeze_time('2001-01-02T12:00:00'):
|
||||||
stats = dao_fetch_todays_stats_for_all_services().all()
|
stats = dao_fetch_todays_stats_for_all_services()
|
||||||
|
|
||||||
stats = {row.status: row.count for row in stats}
|
stats = {row.status: row.count for row in stats}
|
||||||
assert 'delivered' not in stats
|
assert 'delivered' not in stats
|
||||||
@@ -611,7 +611,7 @@ def test_dao_fetch_todays_stats_for_all_services_groups_correctly(notify_db, not
|
|||||||
# service2: 1 sms "created"
|
# service2: 1 sms "created"
|
||||||
create_notification(notify_db, notify_db_session, service=service2)
|
create_notification(notify_db, notify_db_session, service=service2)
|
||||||
|
|
||||||
stats = dao_fetch_todays_stats_for_all_services().all()
|
stats = dao_fetch_todays_stats_for_all_services()
|
||||||
|
|
||||||
assert len(stats) == 4
|
assert len(stats) == 4
|
||||||
assert ('sms', 'created', service1.id, 2) in stats
|
assert ('sms', 'created', service1.id, 2) in stats
|
||||||
@@ -625,7 +625,7 @@ def test_dao_fetch_todays_stats_for_all_services_includes_all_keys_by_default(no
|
|||||||
create_notification(notify_db, notify_db_session, key_type=KEY_TYPE_TEAM)
|
create_notification(notify_db, notify_db_session, key_type=KEY_TYPE_TEAM)
|
||||||
create_notification(notify_db, notify_db_session, key_type=KEY_TYPE_TEST)
|
create_notification(notify_db, notify_db_session, key_type=KEY_TYPE_TEST)
|
||||||
|
|
||||||
stats = dao_fetch_todays_stats_for_all_services().all()
|
stats = dao_fetch_todays_stats_for_all_services()
|
||||||
|
|
||||||
assert len(stats) == 1
|
assert len(stats) == 1
|
||||||
assert stats[0].count == 3
|
assert stats[0].count == 3
|
||||||
@@ -636,7 +636,7 @@ def test_dao_fetch_todays_stats_for_all_services_can_exclude_from_test_key(notif
|
|||||||
create_notification(notify_db, notify_db_session, key_type=KEY_TYPE_TEAM)
|
create_notification(notify_db, notify_db_session, key_type=KEY_TYPE_TEAM)
|
||||||
create_notification(notify_db, notify_db_session, key_type=KEY_TYPE_TEST)
|
create_notification(notify_db, notify_db_session, key_type=KEY_TYPE_TEST)
|
||||||
|
|
||||||
stats = dao_fetch_todays_stats_for_all_services(include_from_test_key=False).all()
|
stats = dao_fetch_todays_stats_for_all_services(include_from_test_key=False)
|
||||||
|
|
||||||
assert len(stats) == 1
|
assert len(stats) == 1
|
||||||
assert stats[0].count == 2
|
assert stats[0].count == 2
|
||||||
@@ -652,7 +652,7 @@ def test_fetch_stats_by_date_range_for_all_services(notify_db, notify_db_session
|
|||||||
start_date = (datetime.utcnow() - timedelta(days=2)).date()
|
start_date = (datetime.utcnow() - timedelta(days=2)).date()
|
||||||
end_date = (datetime.utcnow() - timedelta(days=1)).date()
|
end_date = (datetime.utcnow() - timedelta(days=1)).date()
|
||||||
|
|
||||||
results = fetch_stats_by_date_range_for_all_services(start_date, end_date).all()
|
results = fetch_stats_by_date_range_for_all_services(start_date, end_date)
|
||||||
|
|
||||||
assert len(results) == 1
|
assert len(results) == 1
|
||||||
assert results[0] == ('sms', 'created', result_one.service_id, 2)
|
assert results[0] == ('sms', 'created', result_one.service_id, 2)
|
||||||
|
|||||||
Reference in New Issue
Block a user