remove unused provider dao functions

This commit is contained in:
Leo Hemsted
2019-11-11 14:47:20 +00:00
parent fa7e0a1e84
commit 8fa7cde593
3 changed files with 19 additions and 102 deletions

View File

@@ -66,29 +66,6 @@ def dao_toggle_sms_provider(*args, **kwargs):
raise NotImplementedError raise NotImplementedError
@transactional
def dao_switch_sms_provider_to_provider_with_identifier(identifier):
new_provider = get_provider_details_by_identifier(identifier)
if provider_is_inactive(new_provider):
return
# Check first to see if there is another provider with the same priority
# as this needs to be updated differently
conflicting_provider = dao_get_sms_provider_with_equal_priority(new_provider.identifier, new_provider.priority)
providers_to_update = []
if conflicting_provider:
switch_providers(conflicting_provider, new_provider)
else:
current_provider = get_current_provider('sms')
if not provider_is_primary(current_provider, new_provider, identifier):
providers_to_update = switch_providers(current_provider, new_provider)
for provider in providers_to_update:
dao_update_provider_details(provider)
def get_provider_details_by_notification_type(notification_type, supports_international=False): def get_provider_details_by_notification_type(notification_type, supports_international=False):
filters = [ProviderDetails.notification_type == notification_type] filters = [ProviderDetails.notification_type == notification_type]
@@ -108,19 +85,6 @@ def dao_update_provider_details(provider_details):
db.session.add(history) db.session.add(history)
def dao_get_sms_provider_with_equal_priority(identifier, priority):
provider = db.session.query(ProviderDetails).filter(
ProviderDetails.identifier != identifier,
ProviderDetails.notification_type == 'sms',
ProviderDetails.priority == priority,
ProviderDetails.active
).order_by(
asc(ProviderDetails.priority)
).first()
return provider
def dao_get_provider_stats(): def dao_get_provider_stats():
# this query does not include the current day since the task to populate ft_billing runs overnight # this query does not include the current day since the task to populate ft_billing runs overnight

View File

@@ -11,11 +11,9 @@ from app.dao.provider_details_dao import (
get_current_provider, get_current_provider,
get_provider_details_by_identifier, get_provider_details_by_identifier,
get_provider_details_by_notification_type, get_provider_details_by_notification_type,
dao_switch_sms_provider_to_provider_with_identifier,
dao_update_provider_details, dao_update_provider_details,
dao_get_provider_stats, dao_get_provider_stats,
dao_get_provider_versions, dao_get_provider_versions,
dao_get_sms_provider_with_equal_priority,
dao_reduce_sms_provider_priority, dao_reduce_sms_provider_priority,
) )
from tests.app.db import ( from tests.app.db import (
@@ -135,32 +133,6 @@ def test_get_alternative_sms_provider_fails_if_unrecognised():
get_alternative_sms_provider('ses') get_alternative_sms_provider('ses')
def test_switch_sms_provider_to_current_provider_does_not_switch(
restore_provider_details,
current_sms_provider
):
dao_switch_sms_provider_to_provider_with_identifier(current_sms_provider.identifier)
new_provider = get_current_provider('sms')
assert current_sms_provider.id == new_provider.id
assert current_sms_provider.identifier == new_provider.identifier
def test_switch_sms_provider_to_inactive_provider_does_not_switch(
restore_provider_details,
current_sms_provider
):
alternative_sms_provider = get_alternative_sms_provider(current_sms_provider.identifier)
alternative_sms_provider.active = False
dao_update_provider_details(alternative_sms_provider)
dao_switch_sms_provider_to_provider_with_identifier(alternative_sms_provider.identifier)
new_provider = get_current_provider('sms')
assert new_provider.id == current_sms_provider.id
assert new_provider.identifier == current_sms_provider.identifier
@pytest.mark.parametrize(['starting_priorities', 'expected_priorities'], [ @pytest.mark.parametrize(['starting_priorities', 'expected_priorities'], [
({'mmg': 50, 'firetext': 50}, {'mmg': 40, 'firetext': 60}), ({'mmg': 50, 'firetext': 50}, {'mmg': 40, 'firetext': 60}),
({'mmg': 0, 'firetext': 20}, {'mmg': 0, 'firetext': 30}), # lower bound respected ({'mmg': 0, 'firetext': 20}, {'mmg': 0, 'firetext': 30}), # lower bound respected
@@ -287,21 +259,6 @@ def test_can_get_all_provider_history(restore_provider_details, current_sms_prov
assert len(dao_get_provider_versions(current_sms_provider.id)) == 1 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
def test_get_current_sms_provider_returns_active_only(restore_provider_details): def test_get_current_sms_provider_returns_active_only(restore_provider_details):
current_provider = get_current_provider('sms') current_provider = get_current_provider('sms')
current_provider.active = False current_provider.active = False

View File

@@ -11,7 +11,7 @@ from requests import HTTPError
import app import app
from app import mmg_client, firetext_client from app import mmg_client, firetext_client
from app.dao import (provider_details_dao, notifications_dao) from app.dao import (provider_details_dao, notifications_dao)
from app.dao.provider_details_dao import dao_switch_sms_provider_to_provider_with_identifier from app.dao.provider_details_dao import get_provider_details_by_identifier
from app.delivery import send_to_providers from app.delivery import send_to_providers
from app.exceptions import NotificationTechnicalFailureException from app.exceptions import NotificationTechnicalFailureException
from app.models import ( from app.models import (
@@ -567,64 +567,60 @@ def test_should_set_notification_billable_units_if_sending_to_provider_fails(
def test_should_send_sms_to_international_providers( def test_should_send_sms_to_international_providers(
restore_provider_details, restore_provider_details,
sample_sms_template_with_html, sample_template,
sample_user, sample_user,
mocker mocker
): ):
mocker.patch('app.provider_details.switch_providers.get_user_by_id', return_value=sample_user) mocker.patch('app.mmg_client.send_sms')
mocker.patch('app.firetext_client.send_sms')
dao_switch_sms_provider_to_provider_with_identifier('firetext') # set firetext to active
get_provider_details_by_identifier('firetext').priority = 100
get_provider_details_by_identifier('mmg').priority = 0
db_notification_uk = create_notification( notification_uk = create_notification(
template=sample_sms_template_with_html, template=sample_template,
to_field="+447234123999", to_field="+447234123999",
personalisation={"name": "Jo"}, personalisation={"name": "Jo"},
status='created', status='created',
international=False, international=False,
reply_to_text=sample_sms_template_with_html.service.get_default_sms_sender() reply_to_text=sample_template.service.get_default_sms_sender()
) )
db_notification_international = create_notification( notification_international = create_notification(
template=sample_sms_template_with_html, template=sample_template,
to_field="+6011-17224412", to_field="+6011-17224412",
personalisation={"name": "Jo"}, personalisation={"name": "Jo"},
status='created', status='created',
international=True, international=True,
reply_to_text=sample_sms_template_with_html.service.get_default_sms_sender() reply_to_text=sample_template.service.get_default_sms_sender()
) )
mocker.patch('app.mmg_client.send_sms')
mocker.patch('app.firetext_client.send_sms')
send_to_providers.send_sms_to_provider( send_to_providers.send_sms_to_provider(
db_notification_uk notification_uk
) )
firetext_client.send_sms.assert_called_once_with( firetext_client.send_sms.assert_called_once_with(
to="447234123999", to="447234123999",
content=ANY, content=ANY,
reference=str(db_notification_uk.id), reference=str(notification_uk.id),
sender=current_app.config['FROM_NUMBER'] sender=current_app.config['FROM_NUMBER']
) )
send_to_providers.send_sms_to_provider( send_to_providers.send_sms_to_provider(
db_notification_international notification_international
) )
mmg_client.send_sms.assert_called_once_with( mmg_client.send_sms.assert_called_once_with(
to="601117224412", to="601117224412",
content=ANY, content=ANY,
reference=str(db_notification_international.id), reference=str(notification_international.id),
sender=current_app.config['FROM_NUMBER'] sender=current_app.config['FROM_NUMBER']
) )
notification_uk = Notification.query.filter_by(id=db_notification_uk.id).one()
notification_int = Notification.query.filter_by(id=db_notification_international.id).one()
assert notification_uk.status == 'sending' assert notification_uk.status == 'sending'
assert notification_uk.sent_by == 'firetext' assert notification_uk.sent_by == 'firetext'
assert notification_int.status == 'sent' assert notification_international.status == 'sent'
assert notification_int.sent_by == 'mmg' assert notification_international.sent_by == 'mmg'
@pytest.mark.parametrize('sms_sender, expected_sender, prefix_sms, expected_content', [ @pytest.mark.parametrize('sms_sender, expected_sender, prefix_sms, expected_content', [