Alpha client removed from code. Tests fixed but will wait till other notifications jobs are done before creating a pull request.

This commit is contained in:
Nicholas Staples
2016-02-09 11:38:57 +00:00
parent c1b0cef864
commit 2fda7ee59b
6 changed files with 9 additions and 172 deletions

View File

@@ -14,18 +14,6 @@ def test_get_notifications(
"""
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch(
'app.notify_alpha_client.fetch_notification_by_id',
return_value={
'notifications': [
{
'id': 'my_id',
'notification': 'some notify'
}
]
}
)
auth_header = create_authorization_header(
service_id=sample_api_key.service_id,
path=url_for('notifications.get_notifications', notification_id=123),
@@ -35,12 +23,7 @@ def test_get_notifications(
url_for('notifications.get_notifications', notification_id=123),
headers=[auth_header])
json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 200
assert len(json_resp['notifications']) == 1
assert json_resp['notifications'][0]['id'] == 'my_id'
assert json_resp['notifications'][0]['notification'] == 'some notify'
notify_alpha_client.fetch_notification_by_id.assert_called_with("123")
def test_get_notifications_empty_result(
@@ -50,14 +33,6 @@ def test_get_notifications_empty_result(
"""
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch(
'app.notify_alpha_client.fetch_notification_by_id',
return_value={
'notifications': [
]
}
)
auth_header = create_authorization_header(
service_id=sample_api_key.service_id,
path=url_for('notifications.get_notifications', notification_id=123),
@@ -67,10 +42,7 @@ def test_get_notifications_empty_result(
url_for('notifications.get_notifications', notification_id=123),
headers=[auth_header])
json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 200
assert len(json_resp['notifications']) == 0
notify_alpha_client.fetch_notification_by_id.assert_called_with("123")
def test_create_sms_should_reject_if_no_phone_numbers(
@@ -80,10 +52,6 @@ def test_create_sms_should_reject_if_no_phone_numbers(
"""
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch(
'app.notify_alpha_client.send_sms',
return_value='success'
)
data = {
'template': "my message"
}
@@ -102,7 +70,6 @@ def test_create_sms_should_reject_if_no_phone_numbers(
assert response.status_code == 400
assert json_resp['result'] == 'error'
assert 'Missing data for required field.' in json_resp['message']['to'][0]
assert not notify_alpha_client.send_sms.called
def test_should_reject_bad_phone_numbers(
@@ -112,10 +79,6 @@ def test_should_reject_bad_phone_numbers(
"""
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch(
'app.notify_alpha_client.send_sms',
return_value='success'
)
data = {
'to': 'invalid',
'template': "my message"
@@ -134,7 +97,6 @@ def test_should_reject_bad_phone_numbers(
assert response.status_code == 400
assert json_resp['result'] == 'error'
assert 'Invalid phone number, must be of format +441234123123' in json_resp['message']['to']
assert not notify_alpha_client.send_sms.called
def test_send_notification_restrict_mobile(notify_api,
@@ -150,14 +112,9 @@ def test_send_notification_restrict_mobile(notify_api,
"""
with notify_api.test_request_context():
with notify_api.test_client() as client:
Service.query.filter_by(
id=sample_template.service.id).update({'restricted': True})
invalid_mob = '+449999999999'
mocker.patch(
'app.notify_alpha_client.send_sms',
return_value={}
)
data = {
'to': invalid_mob,
'template': sample_template.id
@@ -177,7 +134,6 @@ def test_send_notification_restrict_mobile(notify_api,
json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 400
assert 'Invalid phone number for restricted service' in json_resp['message']['restricted']
assert not notify_alpha_client.send_sms.called
def test_send_notification_invalid_template_id(notify_api,
@@ -196,10 +152,6 @@ def test_send_notification_invalid_template_id(notify_api,
Service.query.filter_by(
id=sample_template.service.id).update({'restricted': True})
invalid_mob = '+449999999999'
mocker.patch(
'app.notify_alpha_client.send_sms',
return_value={}
)
data = {
'to': invalid_mob,
'template': 9999
@@ -219,7 +171,6 @@ def test_send_notification_invalid_template_id(notify_api,
json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 400
assert 'Template not found' in json_resp['message']['template']
assert not notify_alpha_client.send_sms.called
@moto.mock_sqs
@@ -235,20 +186,6 @@ def test_should_allow_valid_message(notify_api,
"""
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch(
'app.notify_alpha_client.send_sms',
return_value={
"notification": {
"createdAt": "2015-11-03T09:37:27.414363Z",
"id": 100,
"jobId": 65,
"message": "valid",
"method": "sms",
"status": "created",
"to": sample_user.mobile_number
}
}
)
data = {
'to': '+441234123123',
'template': sample_template.id
@@ -263,11 +200,7 @@ def test_should_allow_valid_message(notify_api,
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header])
json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 200
assert json_resp['notification']['id'] == 100
notify_alpha_client.send_sms.assert_called_with(mobile_number='+441234123123',
message=sample_template.content)
@moto.mock_sqs
@@ -284,22 +217,6 @@ def test_send_email_valid_data(notify_api,
from_address = "from@notify.com"
subject = "This is the subject"
message = "This is the message"
mocker.patch(
'app.notify_alpha_client.send_email',
return_value={
"notification": {
"createdAt": "2015-11-03T09:37:27.414363Z",
"id": 100,
"jobId": 65,
"subject": subject,
"message": message,
"method": "email",
"status": "created",
"to": to_address,
"from": from_address
}
}
)
data = {
'to': to_address,
'from': from_address,
@@ -316,11 +233,7 @@ def test_send_email_valid_data(notify_api,
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header])
json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 200
assert json_resp['notification']['id'] == 100
notify_alpha_client.send_email.assert_called_with(
to_address, message, from_address, subject)
@moto.mock_sqs
@@ -333,20 +246,6 @@ def test_valid_message_with_service_id(notify_api,
mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch(
'app.notify_alpha_client.send_sms',
return_value={
"notification": {
"createdAt": "2015-11-03T09:37:27.414363Z",
"id": 100,
"jobId": 65,
"message": "valid",
"method": "sms",
"status": "created",
"to": sample_user.mobile_number
}
}
)
job_id = uuid.uuid4()
service_id = sample_template.service.id
url = url_for('notifications.create_sms_for_service', service_id=service_id)
@@ -365,11 +264,7 @@ def test_valid_message_with_service_id(notify_api,
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header])
json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 200
assert json_resp['notification']['id'] == 100
notify_alpha_client.send_sms.assert_called_with(mobile_number='+441234123123',
message=sample_template.content)
@moto.mock_sqs