Only return active SMS senders

Updated the DAO methods which return a single SMS sender and all SMS senders
to only return the non-archived senders. Changed the error raised in the Admin
interface from a SQLAlchemyError to a BadRequestError.
This commit is contained in:
Katie Smith
2018-04-25 14:23:00 +01:00
parent f810daa3c5
commit 663021e494
7 changed files with 77 additions and 19 deletions

View File

@@ -10,6 +10,7 @@ from freezegun import freeze_time
from app.celery.scheduled_tasks import daily_stats_template_usage_by_month
from app.dao.organisation_dao import dao_add_service_to_organisation
from app.dao.service_sms_sender_dao import dao_get_sms_senders_by_service_id
from app.dao.services_dao import dao_remove_user_from_service
from app.dao.templates_dao import dao_redact_template
from app.dao.users_dao import save_model_user
@@ -2715,9 +2716,10 @@ def test_add_service_sms_sender_can_add_multiple_senders(client, notify_db_sessi
assert len(senders) == 2
def test_add_service_sms_sender_when_it_is_an_inbound_number_updates_the_only_existing_sms_sender(
def test_add_service_sms_sender_when_it_is_an_inbound_number_updates_the_only_existing_non_archived_sms_sender(
client, notify_db_session):
service = create_service_with_defined_sms_sender(sms_sender_value='GOVUK')
create_service_sms_sender(service=service, sms_sender="archived", is_default=False, archived=True)
inbound_number = create_inbound_number(number='12345')
data = {
"sms_sender": str(inbound_number.id),
@@ -2736,7 +2738,7 @@ def test_add_service_sms_sender_when_it_is_an_inbound_number_updates_the_only_ex
assert resp_json['inbound_number_id'] == str(inbound_number.id)
assert resp_json['is_default']
senders = ServiceSmsSender.query.all()
senders = dao_get_sms_senders_by_service_id(service.id)
assert len(senders) == 1

View File

@@ -3,7 +3,6 @@ from unittest.mock import Mock
import pytest
from notifications_utils.recipients import InvalidPhoneError
from sqlalchemy.exc import SQLAlchemyError
from app.v2.errors import BadRequestError, TooManyRequestsError
from app.config import QueueNames
@@ -334,5 +333,6 @@ def test_send_one_off_notification_should_throw_exception_if_sms_sender_id_doesn
'created_by': str(sample_template.service.created_by_id)
}
with pytest.raises(expected_exception=SQLAlchemyError):
with pytest.raises(expected_exception=BadRequestError) as e:
send_one_off_notification(service_id=sample_template.service.id, post_data=data)
assert e.value.message == 'SMS sender not found'