Skip to content

Commit

Permalink
fix: handle built-in custom formats correctly #496
Browse files Browse the repository at this point in the history
  • Loading branch information
heitorlessa committed Jul 2, 2021
1 parent 8724294 commit 96ed44f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/functional/validator/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,24 @@ def eventbridge_schema_registry_cloudtrail_v2_s3():
"x-amazon-events-detail-type": "AWS API Call via CloudTrail",
"x-amazon-events-source": "aws.s3",
}


@pytest.fixture
def schema_datetime_format():
return {
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"type": "object",
"title": "Sample schema with string date-time format",
"description": "The root schema comprises the entire JSON document.",
"required": ["message"],
"properties": {
"message": {
"$id": "#/properties/message",
"type": "string",
"format": "date-time",
"title": "The message",
"examples": ["hello world"],
},
},
}
9 changes: 9 additions & 0 deletions tests/functional/validator/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,12 @@ def _func_echo_decoder(self, value):
envelope="powertools_json(data).payload",
jmespath_options=jmespath_opts,
)


def test_validate_date_time_format(schema_datetime_format):
raw_event = {"message": "2021-06-29T14:46:06.804Z"}
validate(event=raw_event, schema=schema_datetime_format)

invalid_datetime = {"message": "2021-06-29T14"}
with pytest.raises(exceptions.SchemaValidationError, match="data.message must be date-time"):
validate(event=invalid_datetime, schema=schema_datetime_format)

0 comments on commit 96ed44f

Please sign in to comment.