mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-30 11:18:54 -04:00
Merge branch 'master' into updating-service_sms_senders
This commit is contained in:
@@ -12,7 +12,7 @@ from app.dao.services_dao import dao_remove_user_from_service
|
||||
from app.dao.templates_dao import dao_redact_template
|
||||
from app.dao.users_dao import save_model_user
|
||||
from app.models import (
|
||||
User, Organisation, Service, ServicePermission, Notification,
|
||||
User, Organisation, Service, ServicePermission, Notification, ServiceEmailReplyTo,
|
||||
DVLA_ORG_LAND_REGISTRY,
|
||||
KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST,
|
||||
EMAIL_TYPE, SMS_TYPE, LETTER_TYPE, INTERNATIONAL_SMS_TYPE, INBOUND_SMS_TYPE,
|
||||
@@ -2133,10 +2133,8 @@ def test_is_service_name_unique_returns_400_when_name_does_not_exist(client):
|
||||
assert json_resp["message"][1]["email_from"] == ["Can't be empty"]
|
||||
|
||||
|
||||
def test_update_service_reply_to_email_address_upserts_email_reply_to(mocker, admin_request, sample_service):
|
||||
update_mock = mocker.patch('app.service.rest.create_or_update_email_reply_to')
|
||||
|
||||
admin_request.post(
|
||||
def test_update_service_reply_to_email_address_upserts_email_reply_to(admin_request, sample_service):
|
||||
response = admin_request.post(
|
||||
'service.update_service',
|
||||
service_id=sample_service.id,
|
||||
_data={
|
||||
@@ -2145,4 +2143,8 @@ def test_update_service_reply_to_email_address_upserts_email_reply_to(mocker, ad
|
||||
_expected_status=200
|
||||
)
|
||||
|
||||
assert update_mock.called
|
||||
service_reply_to_emails = ServiceEmailReplyTo.query.all()
|
||||
assert len(service_reply_to_emails) == 1
|
||||
assert service_reply_to_emails[0].email_address == 'new@mail.com'
|
||||
assert service_reply_to_emails[0].is_default
|
||||
assert response['data']['reply_to_email_address'] == 'new@mail.com'
|
||||
|
||||
@@ -5,15 +5,12 @@ from flask import json
|
||||
from freezegun import freeze_time
|
||||
from jsonschema import ValidationError
|
||||
|
||||
from app.schema_validation import validate
|
||||
from app.v2.notifications.notification_schemas import (
|
||||
get_notifications_request,
|
||||
get_notification_response,
|
||||
post_sms_request as post_sms_request_schema,
|
||||
post_sms_response as post_sms_response_schema,
|
||||
post_email_request as post_email_request_schema,
|
||||
post_email_response as post_email_response_schema
|
||||
post_email_request as post_email_request_schema
|
||||
)
|
||||
from app.schema_validation import validate
|
||||
|
||||
|
||||
@pytest.mark.parametrize('invalid_statuses, valid_statuses', [
|
||||
@@ -163,40 +160,6 @@ def test_post_sms_request_schema_invalid_phone_number_and_missing_template():
|
||||
assert {"error": "ValidationError", "message": "template_id is a required property"} in errors
|
||||
|
||||
|
||||
def valid_sms_response():
|
||||
return {
|
||||
"id": str(uuid.uuid4()),
|
||||
"content": {"body": "contents of message",
|
||||
"from_number": "46045"},
|
||||
"uri": "http://notify.api/v2/notifications/id",
|
||||
"template": {
|
||||
"id": str(uuid.uuid4()),
|
||||
"version": 1,
|
||||
"uri": "http://notify.api/v2/template/id"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def valid_sms_response_with_optionals():
|
||||
return {
|
||||
"id": str(uuid.uuid4()),
|
||||
"reference": "reference_from_service",
|
||||
"content": {"body": "contents of message",
|
||||
"from_number": "46045"},
|
||||
"uri": "http://notify.api/v2/notifications/id",
|
||||
"template": {
|
||||
"id": str(uuid.uuid4()),
|
||||
"version": 1,
|
||||
"uri": "http://notify.api/v2/template/id"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize('input', [valid_sms_response()])
|
||||
def test_post_sms_response_schema_schema_is_valid(input):
|
||||
assert validate(input, post_sms_response_schema) == input
|
||||
|
||||
|
||||
valid_post_email_json = {"email_address": "test@example.gov.uk",
|
||||
"template_id": str(uuid.uuid4())
|
||||
}
|
||||
@@ -252,110 +215,6 @@ def valid_email_response():
|
||||
}
|
||||
|
||||
|
||||
def valid_email_response_with_optionals():
|
||||
return {
|
||||
"id": str(uuid.uuid4()),
|
||||
"reference": "some reference",
|
||||
"content": {"body": "the body of the message",
|
||||
"subject": "subject of the message",
|
||||
"from_email": "service@dig.gov.uk"},
|
||||
"uri": "http://notify.api/v2/notifications/id",
|
||||
"template": {
|
||||
"id": str(uuid.uuid4()),
|
||||
"version": 1,
|
||||
"uri": "http://notify.api/v2/template/id"
|
||||
},
|
||||
"schedule_for": "2017-05-12 13:00:00"
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("input", [valid_email_response(), valid_email_response_with_optionals()])
|
||||
def test_post_email_response_schema(input):
|
||||
assert validate(input, post_email_response_schema) == input
|
||||
|
||||
|
||||
@pytest.mark.parametrize('response, schema', [
|
||||
(valid_email_response(), post_email_response_schema),
|
||||
(valid_sms_response(), post_sms_response_schema)
|
||||
])
|
||||
def test_post_sms_response_schema_missing_uri_raises_validation_error(response, schema):
|
||||
del response['uri']
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate(response, schema)
|
||||
error = json.loads(str(e.value))
|
||||
assert error['status_code'] == 400
|
||||
assert error['errors'] == [{'error': 'ValidationError',
|
||||
'message': "uri is a required property"}]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('response, schema', [
|
||||
(valid_email_response(), post_email_response_schema),
|
||||
(valid_sms_response(), post_sms_response_schema)
|
||||
])
|
||||
def test_post_sms_response_schema_invalid_uri_raises_validation_error(response, schema):
|
||||
response['uri'] = 'invalid-uri'
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate(response, schema)
|
||||
error = json.loads(str(e.value))
|
||||
assert error['status_code'] == 400
|
||||
assert error['errors'] == [{'error': 'ValidationError',
|
||||
'message': "uri invalid-uri is not a valid URI."}]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('response, schema', [
|
||||
(valid_email_response(), post_email_response_schema),
|
||||
(valid_sms_response(), post_sms_response_schema)
|
||||
])
|
||||
def test_post_sms_response_schema_missing_template_uri_raises_validation_error(response, schema):
|
||||
del response['template']['uri']
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate(response, schema)
|
||||
error = json.loads(str(e.value))
|
||||
assert error['status_code'] == 400
|
||||
assert error['errors'] == [{'error': 'ValidationError',
|
||||
'message': "template uri is a required property"}]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('response, schema', [
|
||||
(valid_email_response(), post_email_response_schema),
|
||||
(valid_sms_response(), post_sms_response_schema)
|
||||
])
|
||||
def test_post_sms_response_schema_invalid_template_uri_raises_validation_error(response, schema):
|
||||
response['template']['uri'] = 'invalid-uri'
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate(response, schema)
|
||||
error = json.loads(str(e.value))
|
||||
assert error['status_code'] == 400
|
||||
assert error['errors'] == [{'error': 'ValidationError',
|
||||
'message': "template invalid-uri is not a valid URI."}]
|
||||
|
||||
|
||||
def test_get_notifications_response_with_email_and_phone_number():
|
||||
response = {"id": str(uuid.uuid4()),
|
||||
"reference": "something",
|
||||
"email_address": None,
|
||||
"phone_number": "+447115411111",
|
||||
"line_1": None,
|
||||
"line_2": None,
|
||||
"line_3": None,
|
||||
"line_4": None,
|
||||
"line_5": None,
|
||||
"line_6": None,
|
||||
"postcode": None,
|
||||
"type": "email",
|
||||
"status": "delivered",
|
||||
"template": {"id": str(uuid.uuid4()), "version": 1, "uri": "http://template/id"},
|
||||
"body": "some body",
|
||||
"subject": "some subject",
|
||||
"created_at": "2016-01-01",
|
||||
"sent_at": "2016-01-01",
|
||||
"completed_at": "2016-01-01",
|
||||
"schedule_for": ""
|
||||
}
|
||||
|
||||
assert validate(response, get_notification_response) == response
|
||||
|
||||
|
||||
@pytest.mark.parametrize("schema",
|
||||
[post_email_request_schema, post_sms_request_schema])
|
||||
@freeze_time("2017-05-12 13:00:00")
|
||||
|
||||
@@ -12,7 +12,9 @@ from app.models import KEY_TYPE_TEST
|
||||
from app.models import LETTER_TYPE
|
||||
from app.models import Notification
|
||||
from app.models import SMS_TYPE
|
||||
from app.schema_validation import validate
|
||||
from app.v2.errors import RateLimitError
|
||||
from app.v2.notifications.notification_schemas import post_letter_response
|
||||
from app.variables import LETTER_TEST_API_FILENAME
|
||||
from app.variables import LETTER_API_FILENAME
|
||||
|
||||
@@ -53,6 +55,7 @@ def test_post_letter_notification_returns_201(client, sample_letter_template, mo
|
||||
|
||||
resp_json = letter_request(client, data, service_id=sample_letter_template.service_id)
|
||||
|
||||
assert validate(resp_json, post_letter_response) == resp_json
|
||||
job = Job.query.one()
|
||||
assert job.original_file_name == LETTER_API_FILENAME
|
||||
notification = Notification.query.one()
|
||||
|
||||
@@ -10,7 +10,9 @@ from app.models import (
|
||||
from flask import json, current_app
|
||||
|
||||
from app.models import Notification
|
||||
from app.schema_validation import validate
|
||||
from app.v2.errors import RateLimitError
|
||||
from app.v2.notifications.notification_schemas import post_sms_response, post_email_response
|
||||
from tests import create_authorization_header
|
||||
from tests.app.conftest import (
|
||||
sample_template as create_sample_template, sample_service,
|
||||
@@ -38,6 +40,7 @@ def test_post_sms_notification_returns_201(client, sample_template_with_placehol
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert response.status_code == 201
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
assert validate(resp_json, post_sms_response) == resp_json
|
||||
notifications = Notification.query.all()
|
||||
assert len(notifications) == 1
|
||||
notification_id = notifications[0].id
|
||||
@@ -71,6 +74,7 @@ def test_post_sms_notification_uses_inbound_number_as_sender(client, sample_temp
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert response.status_code == 201
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
assert validate(resp_json, post_sms_response) == resp_json
|
||||
notifications = Notification.query.all()
|
||||
assert len(notifications) == 1
|
||||
notification_id = notifications[0].id
|
||||
@@ -170,6 +174,7 @@ def test_post_email_notification_returns_201(client, sample_email_template_with_
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert response.status_code == 201
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
assert validate(resp_json, post_email_response) == resp_json
|
||||
notification = Notification.query.first()
|
||||
assert resp_json['id'] == str(notification.id)
|
||||
assert resp_json['reference'] == reference
|
||||
@@ -178,7 +183,8 @@ def test_post_email_notification_returns_201(client, sample_email_template_with_
|
||||
.replace('((name))', 'Bob').replace('GOV.UK', u'GOV.\u200bUK')
|
||||
assert resp_json['content']['subject'] == sample_email_template_with_placeholders.subject \
|
||||
.replace('((name))', 'Bob')
|
||||
assert resp_json['content']['from_email'] == sample_email_template_with_placeholders.service.email_from
|
||||
assert resp_json['content']['from_email'] == "{}@{}".format(
|
||||
sample_email_template_with_placeholders.service.email_from, current_app.config['NOTIFY_EMAIL_DOMAIN'])
|
||||
assert 'v2/notifications/{}'.format(notification.id) in resp_json['uri']
|
||||
assert resp_json['template']['id'] == str(sample_email_template_with_placeholders.id)
|
||||
assert resp_json['template']['version'] == sample_email_template_with_placeholders.version
|
||||
|
||||
Reference in New Issue
Block a user