mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-09 13:39:50 -04:00
reformat
This commit is contained in:
@@ -13,30 +13,32 @@ def test_get_all_templates_returns_200(client, sample_service):
|
||||
create_template(
|
||||
sample_service,
|
||||
template_type=tmp_type,
|
||||
subject='subject_{}'.format(name) if tmp_type == EMAIL_TYPE else '',
|
||||
subject="subject_{}".format(name) if tmp_type == EMAIL_TYPE else "",
|
||||
template_name=name,
|
||||
)
|
||||
for name, tmp_type in product(('A', 'B', 'C'), TEMPLATE_TYPES)
|
||||
for name, tmp_type in product(("A", "B", "C"), TEMPLATE_TYPES)
|
||||
]
|
||||
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
|
||||
response = client.get(path='/v2/templates',
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
response = client.get(
|
||||
path="/v2/templates",
|
||||
headers=[("Content-Type", "application/json"), auth_header],
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers['Content-type'] == 'application/json'
|
||||
assert response.headers["Content-type"] == "application/json"
|
||||
|
||||
json_response = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert len(json_response['templates']) == len(templates)
|
||||
assert len(json_response["templates"]) == len(templates)
|
||||
|
||||
for index, template in enumerate(json_response['templates']):
|
||||
assert template['id'] == str(templates[index].id)
|
||||
assert template['body'] == templates[index].content
|
||||
assert template['type'] == templates[index].template_type
|
||||
for index, template in enumerate(json_response["templates"]):
|
||||
assert template["id"] == str(templates[index].id)
|
||||
assert template["body"] == templates[index].content
|
||||
assert template["type"] == templates[index].template_type
|
||||
if templates[index].template_type == EMAIL_TYPE:
|
||||
assert template['subject'] == templates[index].subject
|
||||
assert template["subject"] == templates[index].subject
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tmp_type", TEMPLATE_TYPES)
|
||||
@@ -45,34 +47,38 @@ def test_get_all_templates_for_valid_type_returns_200(client, sample_service, tm
|
||||
create_template(
|
||||
sample_service,
|
||||
template_type=tmp_type,
|
||||
template_name='Template {}'.format(i),
|
||||
subject='subject_{}'.format(i) if tmp_type == EMAIL_TYPE else ''
|
||||
template_name="Template {}".format(i),
|
||||
subject="subject_{}".format(i) if tmp_type == EMAIL_TYPE else "",
|
||||
)
|
||||
for i in range(3)
|
||||
]
|
||||
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
|
||||
response = client.get(path='/v2/templates?type={}'.format(tmp_type),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
response = client.get(
|
||||
path="/v2/templates?type={}".format(tmp_type),
|
||||
headers=[("Content-Type", "application/json"), auth_header],
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers['Content-type'] == 'application/json'
|
||||
assert response.headers["Content-type"] == "application/json"
|
||||
|
||||
json_response = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert len(json_response['templates']) == len(templates)
|
||||
assert len(json_response["templates"]) == len(templates)
|
||||
|
||||
for index, template in enumerate(json_response['templates']):
|
||||
assert template['id'] == str(templates[index].id)
|
||||
assert template['body'] == templates[index].content
|
||||
assert template['type'] == tmp_type
|
||||
for index, template in enumerate(json_response["templates"]):
|
||||
assert template["id"] == str(templates[index].id)
|
||||
assert template["body"] == templates[index].content
|
||||
assert template["type"] == tmp_type
|
||||
if templates[index].template_type == EMAIL_TYPE:
|
||||
assert template['subject'] == templates[index].subject
|
||||
assert template["subject"] == templates[index].subject
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tmp_type", TEMPLATE_TYPES)
|
||||
def test_get_correct_num_templates_for_valid_type_returns_200(client, sample_service, tmp_type):
|
||||
def test_get_correct_num_templates_for_valid_type_returns_200(
|
||||
client, sample_service, tmp_type
|
||||
):
|
||||
num_templates = 3
|
||||
|
||||
templates = []
|
||||
@@ -85,35 +91,39 @@ def test_get_correct_num_templates_for_valid_type_returns_200(client, sample_ser
|
||||
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
|
||||
response = client.get(path='/v2/templates?type={}'.format(tmp_type),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
response = client.get(
|
||||
path="/v2/templates?type={}".format(tmp_type),
|
||||
headers=[("Content-Type", "application/json"), auth_header],
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
json_response = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert len(json_response['templates']) == num_templates
|
||||
assert len(json_response["templates"]) == num_templates
|
||||
|
||||
|
||||
def test_get_all_templates_for_invalid_type_returns_400(client, sample_service):
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
|
||||
invalid_type = 'coconut'
|
||||
invalid_type = "coconut"
|
||||
|
||||
response = client.get(path='/v2/templates?type={}'.format(invalid_type),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
response = client.get(
|
||||
path="/v2/templates?type={}".format(invalid_type),
|
||||
headers=[("Content-Type", "application/json"), auth_header],
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
assert response.headers['Content-type'] == 'application/json'
|
||||
assert response.headers["Content-type"] == "application/json"
|
||||
|
||||
json_response = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert json_response == {
|
||||
'status_code': 400,
|
||||
'errors': [
|
||||
"status_code": 400,
|
||||
"errors": [
|
||||
{
|
||||
'message': 'type coconut is not one of [sms, email]',
|
||||
'error': 'ValidationError'
|
||||
"message": "type coconut is not one of [sms, email]",
|
||||
"error": "ValidationError",
|
||||
}
|
||||
]
|
||||
],
|
||||
}
|
||||
|
||||
@@ -15,207 +15,244 @@ valid_json_get_all_response = [
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
'id': str(uuid.uuid4()),
|
||||
'type': SMS_TYPE,
|
||||
'created_at': '2017-01-10T18:25:43.511Z',
|
||||
'updated_at': None,
|
||||
'version': 1,
|
||||
'created_by': 'someone@test.com',
|
||||
'body': 'some body',
|
||||
'name': 'some name',
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"created_at": "2017-01-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
"created_by": "someone@test.com",
|
||||
"body": "some body",
|
||||
"name": "some name",
|
||||
},
|
||||
{
|
||||
'id': str(uuid.uuid4()),
|
||||
'type': EMAIL_TYPE,
|
||||
'created_at': '2017-02-10T18:25:43.511Z',
|
||||
'updated_at': None,
|
||||
'version': 2,
|
||||
'created_by': 'someone@test.com',
|
||||
'subject': 'test subject',
|
||||
'body': 'some body',
|
||||
'name': 'some name',
|
||||
}
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": EMAIL_TYPE,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 2,
|
||||
"created_by": "someone@test.com",
|
||||
"subject": "test subject",
|
||||
"body": "some body",
|
||||
"name": "some name",
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
'id': str(uuid.uuid4()),
|
||||
'type': SMS_TYPE,
|
||||
'created_at': '2017-02-10T18:25:43.511Z',
|
||||
'updated_at': None,
|
||||
'version': 2,
|
||||
'created_by': 'someone@test.com',
|
||||
'body': 'some body',
|
||||
'name': 'some name',
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 2,
|
||||
"created_by": "someone@test.com",
|
||||
"body": "some body",
|
||||
"name": "some name",
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"templates": []
|
||||
}
|
||||
{"templates": []},
|
||||
]
|
||||
|
||||
invalid_json_get_all_response = [
|
||||
({
|
||||
"templates": [
|
||||
{
|
||||
'id': 'invalid_id',
|
||||
'type': SMS_TYPE,
|
||||
'created_at': '2017-02-10T18:25:43.511Z',
|
||||
'updated_at': None,
|
||||
'version': 1,
|
||||
'created_by': 'someone@test.com',
|
||||
'body': 'some body',
|
||||
'name': 'some name',
|
||||
}
|
||||
]
|
||||
}, ['templates is not a valid UUID']),
|
||||
({
|
||||
"templates": [
|
||||
{
|
||||
'id': str(uuid.uuid4()),
|
||||
'type': SMS_TYPE,
|
||||
'created_at': '2017-02-10T18:25:43.511Z',
|
||||
'updated_at': None,
|
||||
'version': 'invalid_version',
|
||||
'created_by': 'someone@test.com',
|
||||
'body': 'some body',
|
||||
'name': 'some name',
|
||||
}
|
||||
]
|
||||
}, ['templates invalid_version is not of type integer']),
|
||||
({
|
||||
"templates": [
|
||||
{
|
||||
'id': str(uuid.uuid4()),
|
||||
'type': SMS_TYPE,
|
||||
'created_at': 'invalid_created_at',
|
||||
'updated_at': None,
|
||||
'version': 1,
|
||||
'created_by': 'someone@test.com',
|
||||
'body': 'some body',
|
||||
'name': 'some name',
|
||||
}
|
||||
]
|
||||
}, ['templates invalid_created_at is not a date-time']),
|
||||
({}, ['templates is a required property']),
|
||||
({
|
||||
"templates": [
|
||||
{
|
||||
'type': SMS_TYPE,
|
||||
'created_at': '2017-02-10T18:25:43.511Z',
|
||||
'updated_at': None,
|
||||
'version': 1,
|
||||
'created_by': 'someone@test.com',
|
||||
'body': 'some body',
|
||||
'name': 'some name',
|
||||
}
|
||||
]
|
||||
}, ['templates id is a required property']),
|
||||
({
|
||||
"templates": [
|
||||
{
|
||||
'id': str(uuid.uuid4()),
|
||||
'type': SMS_TYPE,
|
||||
'created_at': '2017-02-10T18:25:43.511Z',
|
||||
'updated_at': None,
|
||||
'version': 1,
|
||||
'created_by': 'someone@test.com',
|
||||
'body': 'some body',
|
||||
}
|
||||
]
|
||||
}, ['templates name is a required property']),
|
||||
({
|
||||
"templates": [
|
||||
{
|
||||
'id': str(uuid.uuid4()),
|
||||
'created_at': '2017-02-10T18:25:43.511Z',
|
||||
'updated_at': None,
|
||||
'version': 1,
|
||||
'created_by': 'someone@test.com',
|
||||
'body': 'some body',
|
||||
'name': 'some name',
|
||||
}
|
||||
]
|
||||
}, ['templates type is a required property']),
|
||||
({
|
||||
"templates": [
|
||||
{
|
||||
'id': str(uuid.uuid4()),
|
||||
'type': SMS_TYPE,
|
||||
'updated_at': None,
|
||||
'version': 1,
|
||||
'created_by': 'someone@test.com',
|
||||
'body': 'some body',
|
||||
'name': 'some name',
|
||||
}
|
||||
]
|
||||
}, ['templates created_at is a required property']),
|
||||
({
|
||||
"templates": [
|
||||
{
|
||||
'id': str(uuid.uuid4()),
|
||||
'type': SMS_TYPE,
|
||||
'created_at': '2017-02-10T18:25:43.511Z',
|
||||
'version': 1,
|
||||
'created_by': 'someone@test.com',
|
||||
'body': 'some body',
|
||||
'name': 'some name',
|
||||
}
|
||||
]
|
||||
}, ['templates updated_at is a required property']),
|
||||
({
|
||||
"templates": [
|
||||
{
|
||||
'id': str(uuid.uuid4()),
|
||||
'type': SMS_TYPE,
|
||||
'created_at': '2017-02-10T18:25:43.511Z',
|
||||
'updated_at': None,
|
||||
'created_by': 'someone@test.com',
|
||||
'body': 'some body',
|
||||
'name': 'some name',
|
||||
}
|
||||
]
|
||||
}, ['templates version is a required property']),
|
||||
({
|
||||
"templates": [
|
||||
{
|
||||
'id': str(uuid.uuid4()),
|
||||
'type': SMS_TYPE,
|
||||
'created_at': '2017-02-10T18:25:43.511Z',
|
||||
'updated_at': None,
|
||||
'version': 1,
|
||||
'body': 'some body',
|
||||
'name': 'some name',
|
||||
}
|
||||
]
|
||||
}, ['templates created_by is a required property']),
|
||||
({
|
||||
"templates": [
|
||||
{
|
||||
'id': str(uuid.uuid4()),
|
||||
'type': SMS_TYPE,
|
||||
'created_at': '2017-02-10T18:25:43.511Z',
|
||||
'updated_at': None,
|
||||
'version': 1,
|
||||
'created_by': 'someone@test.com',
|
||||
'name': 'some name',
|
||||
}
|
||||
]
|
||||
}, ['templates body is a required property']),
|
||||
({
|
||||
"templates": [
|
||||
{
|
||||
'type': SMS_TYPE,
|
||||
'created_at': '2017-02-10T18:25:43.511Z',
|
||||
'updated_at': None,
|
||||
'created_by': 'someone@test.com',
|
||||
'body': 'some body',
|
||||
'name': 'some name',
|
||||
}
|
||||
]
|
||||
}, ['templates id is a required property', 'templates version is a required property']),
|
||||
(
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"id": "invalid_id",
|
||||
"type": SMS_TYPE,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
"created_by": "someone@test.com",
|
||||
"body": "some body",
|
||||
"name": "some name",
|
||||
}
|
||||
]
|
||||
},
|
||||
["templates is not a valid UUID"],
|
||||
),
|
||||
(
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": "invalid_version",
|
||||
"created_by": "someone@test.com",
|
||||
"body": "some body",
|
||||
"name": "some name",
|
||||
}
|
||||
]
|
||||
},
|
||||
["templates invalid_version is not of type integer"],
|
||||
),
|
||||
(
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"created_at": "invalid_created_at",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
"created_by": "someone@test.com",
|
||||
"body": "some body",
|
||||
"name": "some name",
|
||||
}
|
||||
]
|
||||
},
|
||||
["templates invalid_created_at is not a date-time"],
|
||||
),
|
||||
({}, ["templates is a required property"]),
|
||||
(
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"type": SMS_TYPE,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
"created_by": "someone@test.com",
|
||||
"body": "some body",
|
||||
"name": "some name",
|
||||
}
|
||||
]
|
||||
},
|
||||
["templates id is a required property"],
|
||||
),
|
||||
(
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
"created_by": "someone@test.com",
|
||||
"body": "some body",
|
||||
}
|
||||
]
|
||||
},
|
||||
["templates name is a required property"],
|
||||
),
|
||||
(
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
"created_by": "someone@test.com",
|
||||
"body": "some body",
|
||||
"name": "some name",
|
||||
}
|
||||
]
|
||||
},
|
||||
["templates type is a required property"],
|
||||
),
|
||||
(
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
"created_by": "someone@test.com",
|
||||
"body": "some body",
|
||||
"name": "some name",
|
||||
}
|
||||
]
|
||||
},
|
||||
["templates created_at is a required property"],
|
||||
),
|
||||
(
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"version": 1,
|
||||
"created_by": "someone@test.com",
|
||||
"body": "some body",
|
||||
"name": "some name",
|
||||
}
|
||||
]
|
||||
},
|
||||
["templates updated_at is a required property"],
|
||||
),
|
||||
(
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"created_by": "someone@test.com",
|
||||
"body": "some body",
|
||||
"name": "some name",
|
||||
}
|
||||
]
|
||||
},
|
||||
["templates version is a required property"],
|
||||
),
|
||||
(
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
"body": "some body",
|
||||
"name": "some name",
|
||||
}
|
||||
]
|
||||
},
|
||||
["templates created_by is a required property"],
|
||||
),
|
||||
(
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"id": str(uuid.uuid4()),
|
||||
"type": SMS_TYPE,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"version": 1,
|
||||
"created_by": "someone@test.com",
|
||||
"name": "some name",
|
||||
}
|
||||
]
|
||||
},
|
||||
["templates body is a required property"],
|
||||
),
|
||||
(
|
||||
{
|
||||
"templates": [
|
||||
{
|
||||
"type": SMS_TYPE,
|
||||
"created_at": "2017-02-10T18:25:43.511Z",
|
||||
"updated_at": None,
|
||||
"created_by": "someone@test.com",
|
||||
"body": "some body",
|
||||
"name": "some name",
|
||||
}
|
||||
]
|
||||
},
|
||||
[
|
||||
"templates id is a required property",
|
||||
"templates version is a required property",
|
||||
],
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -227,21 +264,21 @@ def test_get_all_template_request_schema_against_no_args_is_valid(template_type)
|
||||
|
||||
@pytest.mark.parametrize("template_type", TEMPLATE_TYPES)
|
||||
def test_get_all_template_request_schema_against_valid_args_is_valid(template_type):
|
||||
data = {'type': template_type}
|
||||
data = {"type": template_type}
|
||||
assert validate(data, get_all_template_request) == data
|
||||
|
||||
|
||||
@pytest.mark.parametrize("template_type", TEMPLATE_TYPES)
|
||||
def test_get_all_template_request_schema_against_invalid_args_is_invalid(template_type):
|
||||
data = {'type': 'unknown'}
|
||||
data = {"type": "unknown"}
|
||||
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate(data, get_all_template_request)
|
||||
errors = json.loads(str(e.value))
|
||||
|
||||
assert errors['status_code'] == 400
|
||||
assert len(errors['errors']) == 1
|
||||
assert errors['errors'][0]['message'] == 'type unknown is not one of [sms, email]'
|
||||
assert errors["status_code"] == 400
|
||||
assert len(errors["errors"]) == 1
|
||||
assert errors["errors"][0]["message"] == "type unknown is not one of [sms, email]"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("response", valid_json_get_all_response)
|
||||
@@ -255,7 +292,7 @@ def test_invalid_get_all_templates_response_schema_is_invalid(response, error_me
|
||||
validate(response, get_all_template_response)
|
||||
errors = json.loads(str(e.value))
|
||||
|
||||
assert errors['status_code'] == 400
|
||||
assert len(errors['errors']) == len(error_messages)
|
||||
for error in errors['errors']:
|
||||
assert error['message'] in error_messages
|
||||
assert errors["status_code"] == 400
|
||||
assert len(errors["errors"]) == len(error_messages)
|
||||
for error in errors["errors"]:
|
||||
assert error["message"] in error_messages
|
||||
|
||||
Reference in New Issue
Block a user