Using jsonschema for create_template.

Updated jsonschema to Draft7, this allowed a conditional validation on subject, if template_type == 'email' or 'letter' then subject is required.
This version is backward compatible with Draft4.
When creating TempalteRedacted, I've built the dict depending on if the created_by or created_by_id exists.
This commit is contained in:
Rebecca Law
2018-11-02 16:00:22 +00:00
parent 1230495e88
commit 39198ed67e
8 changed files with 69 additions and 17 deletions

View File

@@ -172,7 +172,8 @@ def test_should_error_if_created_by_missing(client, sample_user, sample_service)
)
json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 400
assert json_resp['result'] == 'error'
assert json_resp["errors"][0]["error"] == 'ValidationError'
assert json_resp["errors"][0]["message"] == 'created_by is a required property'
def test_should_be_error_if_service_does_not_exist_on_update(client, fake_uuid):
@@ -211,15 +212,14 @@ def test_must_have_a_subject_on_an_email_or_letter_template(client, sample_user,
data=data
)
json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 400
assert json_resp['result'] == 'error'
assert json_resp['message'] == {'subject': ['Invalid template subject']}
assert json_resp['errors'][0]['error'] == "ValidationError"
assert json_resp['errors'][0]["message"] == 'subject is a required property'
def test_update_should_update_a_template(client, sample_user, sample_template):
data = {
'content': 'my template has new content <script type="text/javascript">alert("foo")</script>',
'created_by': str(sample_user.id)
'created_by_id': str(sample_user.id)
}
data = json.dumps(data)
auth_header = create_authorization_header()