mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-05 22:20:49 -04:00
Improvements to the tests.
Update AuthError with a to_dict_v2 method.
This commit is contained in:
@@ -25,16 +25,15 @@ def test_post_sms_schema_is_valid(input):
|
||||
|
||||
def test_post_sms_json_schema_bad_uuid_and_missing_phone_number():
|
||||
j = {"template_id": "notUUID"}
|
||||
try:
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate(j, post_sms_request)
|
||||
except ValidationError as e:
|
||||
error = json.loads(e.message)
|
||||
assert "POST v2/notifications/sms" in error['message']
|
||||
assert len(error.get('fields')) == 2
|
||||
assert "phone_number" in e.message
|
||||
assert "template_id" in e.message
|
||||
assert error.get('code') == '1001'
|
||||
assert error.get('link', None) is not None
|
||||
error = json.loads(e.value.message)
|
||||
assert "POST v2/notifications/sms" in error['message']
|
||||
assert len(error.get('fields')) == 2
|
||||
assert "'phone_number' is a required property" in error['fields']
|
||||
assert "'template_id' not a valid UUID" in error['fields']
|
||||
assert error.get('code') == '1001'
|
||||
assert error.get('link', None) is not None
|
||||
|
||||
|
||||
def test_post_sms_schema_with_personalisation_that_is_not_a_dict():
|
||||
@@ -44,15 +43,14 @@ def test_post_sms_schema_with_personalisation_that_is_not_a_dict():
|
||||
"reference": "reference from caller",
|
||||
"personalisation": "not_a_dict"
|
||||
}
|
||||
try:
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate(j, post_sms_request)
|
||||
except ValidationError as e:
|
||||
error = json.loads(e.message)
|
||||
assert "POST v2/notifications/sms" in error['message']
|
||||
assert len(error.get('fields')) == 1
|
||||
assert "personalisation" in e.message
|
||||
assert error.get('code') == '1001'
|
||||
assert error.get('link', None) is not None
|
||||
error = json.loads(e.value.message)
|
||||
assert "POST v2/notifications/sms" in error['message']
|
||||
assert len(error.get('fields')) == 1
|
||||
assert error['fields'][0] == "'personalisation' should contain key value pairs"
|
||||
assert error.get('code') == '1001'
|
||||
assert error.get('link', None) is not None
|
||||
|
||||
|
||||
valid_response = {
|
||||
@@ -85,7 +83,6 @@ def test_post_sms_response_schema_is_valid(input):
|
||||
def test_post_sms_response_schema_missing_uri():
|
||||
j = valid_response
|
||||
del j["uri"]
|
||||
try:
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate(j, post_sms_response)
|
||||
except ValidationError as e:
|
||||
assert 'uri' in e.message
|
||||
assert 'uri' in e.value.message
|
||||
|
||||
@@ -2,6 +2,7 @@ import uuid
|
||||
|
||||
from flask import json
|
||||
|
||||
from app.models import Notification
|
||||
from tests import create_authorization_header
|
||||
|
||||
|
||||
@@ -22,10 +23,17 @@ def test_post_sms_notification_returns_201(notify_api, sample_template, mocker):
|
||||
|
||||
assert response.status_code == 201
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
notifications = Notification.query.all()
|
||||
assert len(notifications) == 1
|
||||
notification_id = notifications[0].id
|
||||
assert resp_json['id'] is not None
|
||||
assert resp_json['reference'] is None
|
||||
assert resp_json['content']['body'] == sample_template.content
|
||||
assert resp_json['content']['from_number'] == sample_template.service.sms_sender
|
||||
assert 'v2/notifications/{}'.format(notification_id) in resp_json['uri']
|
||||
assert resp_json['template']['id'] == str(sample_template.id)
|
||||
assert resp_json['template']['version'] == sample_template.version
|
||||
assert 'v2/templates/{}'.format(sample_template.id) in resp_json['template']['uri']
|
||||
assert mocked.called
|
||||
|
||||
|
||||
@@ -70,7 +78,9 @@ def test_post_sms_notification_returns_403_and_well_formed_auth_error(notify_api
|
||||
assert response.headers['Content-type'] == 'application/json'
|
||||
error_resp = json.loads(response.get_data(as_text=True))
|
||||
assert error_resp['code'] == 401
|
||||
assert error_resp['message'] == {'token': ['Unauthorized, authentication token must be provided']}
|
||||
assert error_resp['message'] == 'Unauthorized, authentication token must be provided'
|
||||
assert error_resp['fields'] == {'token': ['Unauthorized, authentication token must be provided']}
|
||||
assert error_resp['link'] == 'link to docs'
|
||||
|
||||
|
||||
def test_post_sms_notification_returns_400_and_for_schema_problems(notify_api, sample_template):
|
||||
|
||||
Reference in New Issue
Block a user