Skip to content

Commit

Permalink
[#190] use VA_IDENTIFIER_TYPES enum in post sms request
Browse files Browse the repository at this point in the history
  • Loading branch information
marisahoenig committed Oct 8, 2020
1 parent 739f9ad commit b4c5824
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
7 changes: 4 additions & 3 deletions app/v2/notifications/notification_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
NOTIFICATION_STATUS_TYPES,
NOTIFICATION_STATUS_LETTER_ACCEPTED,
NOTIFICATION_STATUS_LETTER_RECEIVED,
TEMPLATE_TYPES
)
TEMPLATE_TYPES,
VA_IDENTIFIER_TYPES)
from app.schema_validation.definitions import (uuid, personalisation, letter_personalisation)


Expand Down Expand Up @@ -136,7 +136,8 @@
"phone_number": {"type": "string", "format": "phone_number"},
"va_identifier": {"type": "object", "properties": {
"id_type": {
"type": "string"
"type": "string",
"enum": VA_IDENTIFIER_TYPES
},
"value": {
"type": "string"
Expand Down
40 changes: 35 additions & 5 deletions tests/app/v2/notifications/test_notification_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from freezegun import freeze_time
from jsonschema import ValidationError

from app.models import NOTIFICATION_CREATED, EMAIL_TYPE
from app.models import NOTIFICATION_CREATED, EMAIL_TYPE, VA_IDENTIFIER_TYPES, VA_PROFILE_ID
from app.schema_validation import validate
from app.v2.notifications.notification_schemas import (
get_notifications_request,
Expand Down Expand Up @@ -108,15 +108,15 @@ def test_get_notifications_request_invalid_statuses_and_template_types():
}
valid_va_identifier_json = {
"va_identifier": {
"id_type": "foo",
"id_type": VA_PROFILE_ID,
"value": "bar"
},
"template_id": str(uuid.uuid4())
}
valid_phone_number_and_va_identifier_json = {
"phone_number": "6502532222",
"va_identifier": {
"id_type": "foo",
"id_type": VA_PROFILE_ID,
"value": "bar"
},
"template_id": str(uuid.uuid4())
Expand All @@ -135,6 +135,18 @@ def test_post_sms_schema_is_valid(input):
assert validate(input, post_sms_request_schema) == input


@pytest.mark.parametrize("va_identifier_type", VA_IDENTIFIER_TYPES)
def test_post_sms_schema_id_type_should_only_use_enum_values(va_identifier_type):
id_type_as_enum_json = {
"va_identifier": {
"id_type": va_identifier_type,
"value": "bar"
},
"template_id": str(uuid.uuid4())
}
assert validate(id_type_as_enum_json, post_sms_request_schema) == id_type_as_enum_json


@pytest.mark.parametrize("template_id",
['2ebe4da8-17be-49fe-b02f-dff2760261a0' + "\n",
'2ebe4da8-17be-49fe-b02f-dff2760261a0' + " ",
Expand All @@ -160,7 +172,7 @@ def test_post_sms_json_schema_bad_uuid(template_id):


missing_id_type_json = {"value": "bar"}
missing_value_json = {"id_type": "foo"}
missing_value_json = {"id_type": VA_PROFILE_ID}
missing_id_type_and_value_json = {"invalid_param": "invalid"}


Expand All @@ -169,7 +181,7 @@ def test_post_sms_json_schema_bad_uuid(template_id):
(missing_value_json, ["value"]),
(missing_id_type_and_value_json, ["id_type", "value"])
])
def test_post_sms_json_schema_invalid_va_identifier(va_identifier, missing_key_name):
def test_post_sms_json_schema_missing_va_identifier_required_fields(va_identifier, missing_key_name):
j = {
"va_identifier": va_identifier,
"template_id": str(uuid.uuid4())
Expand All @@ -185,6 +197,24 @@ def test_post_sms_json_schema_invalid_va_identifier(va_identifier, missing_key_n
'message': "va_identifier " + key_name + " is a required property"} in error['errors']


def test_post_sms_json_schema_invalid_va_identifier_id_type():
id_type_not_an_accepted_va_identifier_json = {
"va_identifier": {
"id_type": "foo",
"value": "bar",
},
"template_id": str(uuid.uuid4())
}
with pytest.raises(ValidationError) as e:
validate(id_type_not_an_accepted_va_identifier_json, post_sms_request_schema)
error = json.loads(str(e.value))
assert len(error.keys()) == 2
assert error.get('status_code') == 400
assert len(error.get('errors')) == 1
assert {'error': 'ValidationError',
'message': "va_identifier foo is not one of [va_profile_id, pid, icn]"} in error['errors']


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:
Expand Down

0 comments on commit b4c5824

Please sign in to comment.