Skip to content

Commit

Permalink
[#190] adds va_identifier to sms request schema
Browse files Browse the repository at this point in the history
  • Loading branch information
marisahoenig committed Oct 7, 2020
1 parent 27b07b4 commit 0b66fe2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
14 changes: 13 additions & 1 deletion app/v2/notifications/notification_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,24 @@
"properties": {
"reference": {"type": "string"},
"phone_number": {"type": "string", "format": "phone_number"},
"va_identifier": {"type": "object", "properties": {
"type": {
"type": "string"
},
"value": {
"type": "string"
}
}},
"template_id": uuid,
"personalisation": personalisation,
"scheduled_for": {"type": ["string", "null"], "format": "datetime_within_next_day"},
"sms_sender_id": uuid
},
"required": ["phone_number", "template_id"],
"required": ["template_id"],
"anyOf": [
{"required": ["phone_number"]},
{"required": ["va_identifier"]}
],
"additionalProperties": False
}

Expand Down
29 changes: 23 additions & 6 deletions tests/app/v2/notifications/test_notification_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,25 @@ def test_get_notifications_request_invalid_statuses_and_template_types():
.format(invalid_template_type) in error_messages


valid_json = {"phone_number": "6502532222",
"template_id": str(uuid.uuid4())
}
valid_phone_number_json = {
"phone_number": "6502532222",
"template_id": str(uuid.uuid4())
}
valid_va_identifier_json = {
"va_identifier": {
"type": "foo",
"value": "bar"
},
"template_id": str(uuid.uuid4())
}
valid_phone_number_and_va_identifier_json = {
"phone_number": "6502532222",
"va_identifier": {
"type": "foo",
"value": "bar"
},
"template_id": str(uuid.uuid4())
}
valid_json_with_optionals = {
"phone_number": "6502532222",
"template_id": str(uuid.uuid4()),
Expand All @@ -113,7 +129,8 @@ def test_get_notifications_request_invalid_statuses_and_template_types():
}


@pytest.mark.parametrize("input", [valid_json, valid_json_with_optionals])
@pytest.mark.parametrize("input", [valid_phone_number_json, valid_va_identifier_json,
valid_phone_number_and_va_identifier_json, valid_json_with_optionals])
def test_post_sms_schema_is_valid(input):
assert validate(input, post_sms_request_schema) == input

Expand Down Expand Up @@ -142,7 +159,7 @@ def test_post_sms_json_schema_bad_uuid(template_id):
'message': "template_id is not a valid UUID"} in error['errors']


def test_post_sms_json_schema_bad_uuid_and_missing_phone_number():
def test_post_sms_json_schema_bad_uuid_and_missing_phone_number_and_va_identifier():
j = {"template_id": "notUUID"}
with pytest.raises(ValidationError) as e:
validate(j, post_sms_request_schema)
Expand All @@ -151,7 +168,7 @@ def test_post_sms_json_schema_bad_uuid_and_missing_phone_number():
assert error.get('status_code') == 400
assert len(error.get('errors')) == 2
assert {'error': 'ValidationError',
'message': "phone_number is a required property"} in error['errors']
'message': "{template_id: notUUID} is not valid under any of the given schemas"} in error['errors']
assert {'error': 'ValidationError',
'message': "template_id is not a valid UUID"} in error['errors']

Expand Down
2 changes: 1 addition & 1 deletion tests/app/v2/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_validation_error(app_for_test):
assert error['status_code'] == 400
assert len(error['errors']) == 2
assert {'error': 'ValidationError',
'message': "phone_number is a required property"} in error['errors']
'message': "{template_id: bad_uuid} is not valid under any of the given schemas"} in error['errors']
assert {'error': 'ValidationError',
'message': "template_id is not a valid UUID"} in error['errors']

Expand Down

0 comments on commit 0b66fe2

Please sign in to comment.