Update JSON schema postage validation for new values

This commit is contained in:
Katie Smith
2020-06-08 13:45:22 +01:00
parent 6cd914b9d3
commit ab956c9eb3
4 changed files with 7 additions and 5 deletions

View File

@@ -34,8 +34,8 @@ def validate_schema_email_address(instance):
@format_checker.checks('postage', raises=ValidationError) @format_checker.checks('postage', raises=ValidationError)
def validate_schema_postage(instance): def validate_schema_postage(instance):
if isinstance(instance, str): if isinstance(instance, str):
if instance not in ["first", "second"]: if instance not in ["first", "second", "europe", "rest-of-world"]:
raise ValidationError("invalid. It must be either first or second.") raise ValidationError("invalid. It must be first, second, europe or rest-of-world.")
return True return True

View File

@@ -2340,7 +2340,8 @@ def test_create_pdf_letter(mocker, sample_service_full_permissions, client, fake
{"postage": "third", "filename": "string", "created_by": "string", "file_id": "string", {"postage": "third", "filename": "string", "created_by": "string", "file_id": "string",
"recipient_address": "Some Address"}, "recipient_address": "Some Address"},
[ [
{'error': 'ValidationError', 'message': 'postage invalid. It must be either first or second.'} {'error': 'ValidationError',
'message': 'postage invalid. It must be first, second, europe or rest-of-world.'}
] ]
) )
]) ])

View File

@@ -794,7 +794,8 @@ def test_create_a_template_with_foreign_service_reply_to(admin_request, sample_u
{"name": "my template", "template_type": "sms", "content": "hi", "postage": "third", {"name": "my template", "template_type": "sms", "content": "hi", "postage": "third",
"service": "1af43c02-b5a8-4923-ad7f-5279b75ff2d0", "created_by": "30587644-9083-44d8-a114-98887f07f1e3"}, "service": "1af43c02-b5a8-4923-ad7f-5279b75ff2d0", "created_by": "30587644-9083-44d8-a114-98887f07f1e3"},
[ [
{"error": "ValidationError", "message": "postage invalid. It must be either first or second."}, {"error": "ValidationError",
"message": "postage invalid. It must be first, second, europe or rest-of-world."},
] ]
), ),
]) ])

View File

@@ -637,7 +637,7 @@ def test_post_letter_notification_throws_error_for_invalid_postage(client, notif
assert response.status_code == 400, response.get_data(as_text=True) assert response.status_code == 400, response.get_data(as_text=True)
resp_json = json.loads(response.get_data(as_text=True)) resp_json = json.loads(response.get_data(as_text=True))
assert resp_json['errors'][0]['message'] == "postage invalid. It must be either first or second." assert resp_json['errors'][0]['message'] == "postage invalid. It must be first, second, europe or rest-of-world."
assert not Notification.query.first() assert not Notification.query.first()