I have an issue with the test, not sure why?

This commit is contained in:
Rebecca Law
2016-02-17 17:48:23 +00:00
parent 66cf6cfd30
commit 9073814d9f
12 changed files with 142 additions and 35 deletions

View File

@@ -1,10 +1,7 @@
import uuid
import pytest
from app.celery.tasks import (send_sms, send_sms_code)
from app import twilio_client, encryption
from app.clients.sms.twilio import TwilioClientException
from app.celery.tasks import send_sms
from app import firetext_client
from app.celery.tasks import (send_sms, send_sms_code, send_email_code)
from app import (firetext_client, aws_ses_client, encryption)
from app.clients.sms.firetext import FiretextClientException
from app.dao import notifications_dao
from sqlalchemy.exc import SQLAlchemyError
@@ -98,3 +95,20 @@ def test_should_log_firetext_client_exception(mocker):
mocker.patch('app.firetext_client.send_sms', side_effect=FiretextClientException)
send_sms_code(encrypted_notification)
firetext_client.send_sms.assert_called_once_with(notification['to'], notification['secret_code'])
def test_should_send_email_code(mocker):
notification = {'to_address': 'someone@it.gov.uk',
'from_address': 'no-reply@notify.gov.uk',
'subject': 'Verification code',
'body': 11111}
encrypted_notification = encryption.encrypt(notification)
mocker.patch('app.aws_ses_client.send_email')
send_email_code(encrypted_notification)
aws_ses_client.send_email.assert_called_once_with((notification['from_address'],
notification['to_address'],
notification['subject'],
notification['body']))

View File

@@ -207,3 +207,8 @@ def sample_notification(notify_db,
@pytest.fixture(scope='function')
def mock_celery_send_sms_code(mocker):
return mocker.patch('app.celery.tasks.send_sms_code.apply_async')
@pytest.fixture(scope='function')
def mock_celery_send_email_code(mocker):
return mocker.patch('app.celery.tasks.send_email_code.apply_async')

View File

@@ -294,17 +294,14 @@ def test_send_user_code_for_sms_with_optional_to_field(notify_api,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 204
encrpyted = encryption.encrypt({'to': '+441119876757', 'secret_code': '11111'})
app.celery.tasks.send_sms_code.apply_async.assert_called_once_with([encrpyted], queue='sms_code')
encrypted = encryption.encrypt({'to': '+441119876757', 'secret_code': '11111'})
app.celery.tasks.send_sms_code.apply_async.assert_called_once_with([encrypted], queue='sms_code')
@moto.mock_sqs
def test_send_user_code_for_email(notify_api,
notify_db,
notify_db_session,
sample_email_code,
sqs_client_conn,
mock_secret_code):
mock_secret_code,
mock_celery_send_email_code):
"""
Tests POST endpoint '/<user_id>/code' successful email
"""
@@ -320,15 +317,18 @@ def test_send_user_code_for_email(notify_api,
data=data,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 204
notification = {'to_address': sample_email_code.user.email_address,
'from_address': notify_api.config['VERIFY_CODE_FROM_EMAIL_ADDRESS'],
'subject': 'Verification code',
'body': 11111}
encrypted = encryption.encrypt([notification])
app.celery.tasks.send_email_code.apply_async.assert_called_once_with([encrypted], queue='email_code')
@moto.mock_sqs
def test_send_user_code_for_email_uses_optional_to_field(notify_api,
notify_db,
notify_db_session,
sample_email_code,
sqs_client_conn,
mock_secret_code):
mock_secret_code,
mock_celery_send_email_code):
"""
Tests POST endpoint '/<user_id>/code' successful email with included in body
"""
@@ -344,6 +344,13 @@ def test_send_user_code_for_email_uses_optional_to_field(notify_api,
data=data,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 204
notification = json.dumps({'to_address': 'different@email.gov.uk',
'from_address': 'no-reply@notify.works',
'subject': 'Verification code',
'body': '11111'})
encrypted = encryption.encrypt([notification])
app.celery.tasks.send_email_code.apply_async.assert_called_once_with([encrypted], queue='email_code')
def test_request_verify_code_schema_invalid_code_type(notify_api, notify_db, notify_db_session, sample_user):

View File

@@ -59,13 +59,6 @@ def notify_db_session(request):
request.addfinalizer(teardown)
@pytest.fixture(scope='function')
def notify_config(notify_api):
notify_api.config['NOTIFY_API_ENVIRONMENT'] = 'test'
notify_api.config.from_object(configs['test'])
return notify_api.config
@pytest.fixture(scope='function')
def os_environ(request):
env_patch = mock.patch('os.environ', {})