From ce2401c6e00f069244e9b121551eb5d564b58b7b Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Mon, 24 Apr 2017 14:48:06 +0100 Subject: [PATCH] Ensure get_current_provider only returns active --- app/dao/provider_details_dao.py | 3 ++- tests/app/dao/test_provider_details_dao.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/dao/provider_details_dao.py b/app/dao/provider_details_dao.py index 2992a0107..ff4db1a93 100644 --- a/app/dao/provider_details_dao.py +++ b/app/dao/provider_details_dao.py @@ -36,7 +36,8 @@ def get_alternative_sms_provider(identifier): def get_current_provider(notification_type): return ProviderDetails.query.filter_by( - notification_type=notification_type + notification_type=notification_type, + active=True ).order_by( asc(ProviderDetails.priority) ).first() diff --git a/tests/app/dao/test_provider_details_dao.py b/tests/app/dao/test_provider_details_dao.py index 51339370c..5092bd1b9 100644 --- a/tests/app/dao/test_provider_details_dao.py +++ b/tests/app/dao/test_provider_details_dao.py @@ -273,3 +273,12 @@ def test_get_sms_provider_with_equal_priority_returns_provider( dao_get_sms_provider_with_equal_priority(current_provider.identifier, current_provider.priority) assert conflicting_provider + + +def test_get_current_sms_provider_returns_active_only(restore_provider_details): + current_provider = get_current_provider('sms') + current_provider.active = False + dao_update_provider_details(current_provider) + new_current_provider = get_current_provider('sms') + + assert current_provider.identifier != new_current_provider.identifier