Added tests to ensure pick correct provider from the database in the celery tasks.

This commit is contained in:
Martyn Inglis
2016-05-11 14:03:12 +01:00
parent 6493e4db9c
commit 42c42bfdc9
2 changed files with 33 additions and 3 deletions

View File

@@ -13,12 +13,13 @@ from app.celery.tasks import (
delete_verify_codes,
delete_invitations,
delete_failed_notifications,
delete_successful_notifications
delete_successful_notifications,
provider_to_use
)
from app import (aws_ses_client, encryption, DATETIME_FORMAT, mmg_client)
from app.clients.email.aws_ses import AwsSesClientException
from app.clients.sms.mmg import MMGClientException
from app.dao import notifications_dao, jobs_dao
from app.dao import notifications_dao, jobs_dao, provider_details_dao
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.orm.exc import NoResultFound
from app.celery.tasks import s3
@@ -44,6 +45,36 @@ class AnyStringWith(str):
mmg_error = {'Error': '40', 'Description': 'error'}
def test_should_return_highest_priority_active_provider(notify_db, notify_db_session):
providers = provider_details_dao.get_provider_details_by_notification_type('sms')
first = providers[0]
second = providers[1]
assert provider_to_use('sms', '1234').name == first.identifier
first.priority = 20
second.priority = 10
provider_details_dao.dao_update_provider_details(first)
provider_details_dao.dao_update_provider_details(second)
assert provider_to_use('sms', '1234').name == second.identifier
first.priority = 10
first.active = False
second.priority = 20
provider_details_dao.dao_update_provider_details(first)
provider_details_dao.dao_update_provider_details(second)
assert provider_to_use('sms', '1234').name == second.identifier
first.active = True
provider_details_dao.dao_update_provider_details(first)
assert provider_to_use('sms', '1234').name == first.identifier
def test_should_call_delete_notifications_more_than_week_in_task(notify_api, mocker):
mocked = mocker.patch('app.celery.tasks.delete_notifications_created_more_than_a_week_ago')
delete_successful_notifications()

View File

@@ -41,7 +41,6 @@ def notify_db(notify_api, request):
db.session.remove()
db.drop_all()
db.engine.execute("drop table alembic_version")
db.engine.execute("drop type providers")
db.get_engine(notify_api).dispose()
request.addfinalizer(teardown)