mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Updates:
* Add notify user id in config * Add dao method to get provider history versions along with tests * BUG: Provider switching did not handle case where priorities were equal. This * adds a fix to properly cover this case along with tests
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import pytest
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from freezegun import freeze_time
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy import asc, desc
|
||||
|
||||
from app.models import ProviderDetails, ProviderDetailsHistory
|
||||
from app import clients
|
||||
@@ -15,7 +14,9 @@ from app.dao.provider_details_dao import (
|
||||
get_provider_details_by_notification_type,
|
||||
dao_switch_sms_provider_to_provider_with_identifier,
|
||||
dao_toggle_sms_provider,
|
||||
dao_update_provider_details
|
||||
dao_update_provider_details,
|
||||
dao_get_provider_versions,
|
||||
dao_get_sms_provider_with_equal_priority
|
||||
)
|
||||
|
||||
|
||||
@@ -148,9 +149,13 @@ def test_switch_sms_provider_to_inactive_provider_does_not_switch(
|
||||
|
||||
|
||||
def test_toggle_sms_provider_switches_provider(
|
||||
mocker,
|
||||
restore_provider_details,
|
||||
current_sms_provider
|
||||
current_sms_provider,
|
||||
sample_user
|
||||
|
||||
):
|
||||
mocker.patch('app.provider_details.switch_providers.get_user_by_id', return_value=sample_user)
|
||||
dao_toggle_sms_provider(current_sms_provider.identifier)
|
||||
new_provider = get_current_provider('sms')
|
||||
|
||||
@@ -161,8 +166,11 @@ def test_toggle_sms_provider_switches_provider(
|
||||
|
||||
|
||||
def test_toggle_sms_provider_switches_when_provider_priorities_are_equal(
|
||||
restore_provider_details
|
||||
mocker,
|
||||
restore_provider_details,
|
||||
sample_user
|
||||
):
|
||||
mocker.patch('app.provider_details.switch_providers.get_user_by_id', return_value=sample_user)
|
||||
current_provider = get_current_provider('sms')
|
||||
new_provider = get_alternative_sms_provider(current_provider.identifier)
|
||||
|
||||
@@ -178,9 +186,12 @@ def test_toggle_sms_provider_switches_when_provider_priorities_are_equal(
|
||||
|
||||
|
||||
def test_toggle_sms_provider_updates_provider_history(
|
||||
mocker,
|
||||
restore_provider_details,
|
||||
current_sms_provider
|
||||
current_sms_provider,
|
||||
sample_user
|
||||
):
|
||||
mocker.patch('app.provider_details.switch_providers.get_user_by_id', return_value=sample_user)
|
||||
provider_history_rows = ProviderDetailsHistory.query.filter(
|
||||
ProviderDetailsHistory.id == current_sms_provider.id
|
||||
).order_by(
|
||||
@@ -197,3 +208,68 @@ def test_toggle_sms_provider_updates_provider_history(
|
||||
|
||||
assert len(updated_provider_history_rows) - len(provider_history_rows) == 1
|
||||
assert updated_provider_history_rows[0].version - provider_history_rows[0].version == 1
|
||||
|
||||
|
||||
def test_toggle_sms_provider_switches_provider_stores_notify_user_id(
|
||||
restore_provider_details,
|
||||
sample_user,
|
||||
mocker
|
||||
):
|
||||
mocker.patch('app.provider_details.switch_providers.get_user_by_id', return_value=sample_user)
|
||||
|
||||
current_provider = get_current_provider('sms')
|
||||
dao_toggle_sms_provider(current_provider.identifier)
|
||||
new_provider = get_current_provider('sms')
|
||||
|
||||
assert current_provider.identifier != new_provider.identifier
|
||||
assert new_provider.created_by.id == sample_user.id
|
||||
assert new_provider.created_by_id == sample_user.id
|
||||
|
||||
|
||||
def test_toggle_sms_provider_switches_provider_stores_notify_user_id_in_history(
|
||||
restore_provider_details,
|
||||
sample_user,
|
||||
mocker
|
||||
):
|
||||
mocker.patch('app.provider_details.switch_providers.get_user_by_id', return_value=sample_user)
|
||||
|
||||
old_provider = get_current_provider('sms')
|
||||
dao_toggle_sms_provider(old_provider.identifier)
|
||||
new_provider = get_current_provider('sms')
|
||||
|
||||
old_provider_from_history = ProviderDetailsHistory.query.filter_by(
|
||||
identifier=old_provider.identifier,
|
||||
version=old_provider.version
|
||||
).order_by(
|
||||
asc(ProviderDetailsHistory.priority)
|
||||
).first()
|
||||
new_provider_from_history = ProviderDetailsHistory.query.filter_by(
|
||||
identifier=new_provider.identifier,
|
||||
version=new_provider.version
|
||||
).order_by(
|
||||
asc(ProviderDetailsHistory.priority)
|
||||
).first()
|
||||
|
||||
assert old_provider.version == old_provider_from_history.version
|
||||
assert new_provider.version == new_provider_from_history.version
|
||||
assert new_provider_from_history.created_by_id == sample_user.id
|
||||
assert old_provider_from_history.created_by_id == sample_user.id
|
||||
|
||||
|
||||
def test_can_get_all_provider_history(current_sms_provider):
|
||||
assert len(dao_get_provider_versions(current_sms_provider.id)) == 1
|
||||
|
||||
|
||||
def test_get_sms_provider_with_equal_priority_returns_provider(
|
||||
restore_provider_details
|
||||
):
|
||||
current_provider = get_current_provider('sms')
|
||||
new_provider = get_alternative_sms_provider(current_provider.identifier)
|
||||
|
||||
current_provider.priority = new_provider.priority
|
||||
dao_update_provider_details(current_provider)
|
||||
|
||||
conflicting_provider = \
|
||||
dao_get_sms_provider_with_equal_priority(current_provider.identifier, current_provider.priority)
|
||||
|
||||
assert conflicting_provider
|
||||
|
||||
Reference in New Issue
Block a user