From f9f3bb8370c3e24a5fee7ea026fdf37179a6a9ce Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 23 Sep 2016 10:27:10 +0100 Subject: [PATCH] Make DAO optionally return test key notifications Developers need visibility of what their integration is doing within the app. This includes notifications sent with a test key. This commit adds an optional, defaults-to-false parameter to include notifications sent from a test API key when getting notifications. --- app/dao/notifications_dao.py | 5 +++-- tests/app/dao/test_notification_dao.py | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index 2453db6c5..c289f60ed 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -236,7 +236,8 @@ def get_notifications_for_service( limit_days=None, key_type=None, personalisation=False, - include_jobs=False + include_jobs=False, + include_from_test_key=False ): if page_size is None: page_size = current_app.config['PAGE_SIZE'] @@ -252,7 +253,7 @@ def get_notifications_for_service( if key_type is not None: filters.append(Notification.key_type == key_type) - else: + elif not include_from_test_key: filters.append(Notification.key_type != KEY_TYPE_TEST) query = Notification.query.filter(*filters) diff --git a/tests/app/dao/test_notification_dao.py b/tests/app/dao/test_notification_dao.py index 39c91912c..97885f50a 100644 --- a/tests/app/dao/test_notification_dao.py +++ b/tests/app/dao/test_notification_dao.py @@ -1000,11 +1000,15 @@ def test_get_notifications_created_by_api_or_csv_are_returned_correctly_excludin all_notifications = Notification.query.all() assert len(all_notifications) == 4 - # returns all API derived notifications + # returns all real API derived notifications all_notifications = get_notifications_for_service(sample_service.id).items assert len(all_notifications) == 2 - # all notifications including jobs + # returns all API derived notifications, including those created with test key + all_notifications = get_notifications_for_service(sample_service.id, include_from_test_key=True).items + assert len(all_notifications) == 3 + + # all real notifications including jobs all_notifications = get_notifications_for_service(sample_service.id, limit_days=1, include_jobs=True).items assert len(all_notifications) == 3