Refactoring the send to provider code out of the tasks folder

- building a rest endpoint to call that code to compliment the existing task based approach.
This commit is contained in:
Martyn Inglis
2016-09-21 13:27:32 +01:00
parent bd06b18684
commit 991cc884b4
5 changed files with 92 additions and 28 deletions

View File

@@ -1,31 +1,8 @@
import uuid
from datetime import datetime
import pytest
from celery.exceptions import MaxRetriesExceededError
from unittest.mock import ANY, call
from notifications_utils.recipients import validate_phone_number, format_phone_number
import app
from app import statsd_client, mmg_client
from app.celery import provider_tasks
from app.celery.provider_tasks import send_sms_to_provider, send_email_to_provider
from app.celery.research_mode_tasks import send_sms_response, send_email_response
from app.clients.email import EmailClientException
from app.clients.sms import SmsClientException
from app.dao import notifications_dao, provider_details_dao
from app.dao import provider_statistics_dao
from app.dao.provider_statistics_dao import get_provider_statistics
from app.models import (
Notification,
NotificationStatistics,
Job,
Organisation,
KEY_TYPE_NORMAL,
KEY_TYPE_TEST,
BRANDING_ORG,
BRANDING_BOTH
)
from app.models import Notification
from tests.app.conftest import sample_notification

View File

@@ -5,6 +5,7 @@ import pytest
from mock import ANY
import app
from sqlalchemy.orm.exc import NoResultFound
from app import mmg_client
from app.dao import (provider_details_dao, notifications_dao, provider_statistics_dao)
from app.dao.provider_statistics_dao import get_provider_statistics
@@ -46,6 +47,18 @@ def test_should_return_highest_priority_active_provider(notify_db, notify_db_ses
assert send_to_providers.provider_to_use('sms', '1234').name == first.identifier
def test_raises_not_found_exception_if_no_notification_for_id(notify_db, notify_db_session, mocker):
mocker.patch('app.mmg_client.send_sms')
mocker.patch('app.mmg_client.get_name', return_value="mmg")
notification_id = uuid.uuid4()
with pytest.raises(NoResultFound) as exc:
send_to_providers.send_sms_to_provider(notification_id)
assert str(exc.value) == "No notification for {}".format(str(notification_id))
app.mmg_client.send_sms.assert_not_called()
def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
notify_db,
notify_db_session,