Skip to content

Commit

Permalink
[#190] use VA_IDENTIFIER_TYPES enum in post email request
Browse files Browse the repository at this point in the history
  • Loading branch information
marisahoenig committed Oct 8, 2020
1 parent b4c5824 commit 22e4236
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/v2/notifications/notification_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@
"email_address": {"type": "string", "format": "email_address"},
"va_identifier": {"type": "object", "properties": {
"id_type": {
"type": "string"
"type": "string",
"enum": VA_IDENTIFIER_TYPES
},
"value": {
"type": "string"
Expand Down
38 changes: 34 additions & 4 deletions tests/app/v2/notifications/test_notification_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,15 @@ def test_post_sms_request_schema_invalid_phone_number_and_missing_template():
}
valid_va_identifier_json = {
"va_identifier": {
"id_type": "foo",
"id_type": VA_PROFILE_ID,
"value": "bar"
},
"template_id": str(uuid.uuid4())
}
valid_email_and_va_identifier_json = {
"email_address": "[email protected]",
"va_identifier": {
"id_type": "foo",
"id_type": VA_PROFILE_ID,
"value": "bar"
},
"template_id": str(uuid.uuid4())
Expand Down Expand Up @@ -336,7 +336,7 @@ def test_post_email_schema_invalid_email_address(email_address, err_msg):


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 @@ -345,7 +345,7 @@ def test_post_email_schema_invalid_email_address(email_address, err_msg):
(missing_value_json, ["value"]),
(missing_id_type_and_value_json, ["id_type", "value"])
])
def test_post_email_json_schema_invalid_va_identifier(va_identifier, missing_key_name):
def test_post_email_json_schema_missing_va_identifier_required_fields(va_identifier, missing_key_name):
j = {
"va_identifier": va_identifier,
"template_id": str(uuid.uuid4())
Expand All @@ -361,6 +361,36 @@ def test_post_email_json_schema_invalid_va_identifier(va_identifier, missing_key
'message': "va_identifier " + key_name + " is a required property"} in error['errors']


def test_post_email_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_email_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']


@pytest.mark.parametrize("va_identifier_type", VA_IDENTIFIER_TYPES)
def test_post_email_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_email_request_schema) == id_type_as_enum_json


def valid_email_response():
return {
"id": str(uuid.uuid4()),
Expand Down

0 comments on commit 22e4236

Please sign in to comment.