Allow excluding test key use in the all services stats query

This commit is contained in:
Jenny Duckett
2016-12-02 16:43:24 +00:00
parent ad7278fd4e
commit 7668745d8b
2 changed files with 18 additions and 2 deletions

View File

@@ -239,8 +239,8 @@ def dao_fetch_weekly_historical_stats_for_service(service_id):
@statsd(namespace='dao') @statsd(namespace='dao')
def dao_fetch_todays_stats_for_all_services(): def dao_fetch_todays_stats_for_all_services(include_from_test_key=True):
return db.session.query( query = db.session.query(
Notification.notification_type, Notification.notification_type,
Notification.status, Notification.status,
Notification.service_id, Notification.service_id,
@@ -258,3 +258,8 @@ def dao_fetch_todays_stats_for_all_services():
).order_by( ).order_by(
Notification.service_id Notification.service_id
) )
if not include_from_test_key:
query = query.filter(Notification.key_type != KEY_TYPE_TEST)
return query

View File

@@ -628,3 +628,14 @@ def test_dao_fetch_todays_stats_for_all_services_includes_all_keys_by_default(no
assert len(stats) == 1 assert len(stats) == 1
assert stats[0].count == 3 assert stats[0].count == 3
def test_dao_fetch_todays_stats_for_all_services_can_exclude_from_test_key(notify_db, notify_db_session):
create_notification(notify_db, notify_db_session, key_type=KEY_TYPE_NORMAL)
create_notification(notify_db, notify_db_session, key_type=KEY_TYPE_TEAM)
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()
assert len(stats) == 1
assert stats[0].count == 2