Update notification schemas with optional schedule_for element

This commit is contained in:
Rebecca Law
2017-05-15 15:02:38 +01:00
parent 75a4dad8c1
commit 38e5b31e9a
3 changed files with 60 additions and 8 deletions

View File

@@ -246,7 +246,8 @@ def valid_email_response():
"id": str(uuid.uuid4()),
"version": 1,
"uri": "http://notify.api/v2/template/id"
}
},
"scheduled_for": ""
}
@@ -262,7 +263,8 @@ def valid_email_response_with_optionals():
"id": str(uuid.uuid4()),
"version": 1,
"uri": "http://notify.api/v2/template/id"
}
},
"schedule_for": "2017-05-12 13:00:00"
}
@@ -346,7 +348,41 @@ def test_get_notifications_response_with_email_and_phone_number():
"subject": "some subject",
"created_at": "2016-01-01",
"sent_at": "2016-01-01",
"completed_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])
def test_post_schema_valid_scheduled_for(schema):
j = {"template_id": str(uuid.uuid4()),
"email_address": "joe@gmail.com",
"scheduled_for": "2017-05-12 13:00:00"}
if schema == post_email_request_schema:
j.update({"email_address": "joe@gmail.com"})
else:
j.update({"phone_number": "07515111111"})
assert validate(j, schema) == j
@pytest.mark.parametrize("invalid_datetime",
["2017-05-12 13:00", "13:00:00 2017-01-01"])
@pytest.mark.parametrize("schema",
[post_email_request_schema, post_sms_request_schema])
def test_post_email_schema_invalid_scheduled_for(invalid_datetime, schema):
j = {"template_id": str(uuid.uuid4()),
"scheduled_for": invalid_datetime}
if schema == post_email_request_schema:
j.update({"email_address": "joe@gmail.com"})
else:
j.update({"phone_number": "07515111111"})
with pytest.raises(ValidationError) as e:
validate(j, schema)
error = json.loads(str(e.value))
assert error['status_code'] == 400
assert error['errors'] == [{'error': 'ValidationError',
'message': "scheduled_for datetime format is invalid. Use the format: "
"YYYY-MM-DD HH:MM:SS, for example 2017-05-30 13:00:00"}]