diff --git a/requirements.txt b/requirements.txt index ab5ad39..b66d10e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ +isodate jsonschema six +strict_rfc3339 diff --git a/setup.cfg b/setup.cfg index 46527b1..4a0cd0e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -23,8 +23,10 @@ python_requires = >= 2.7, != 3.0.*, != 3.1.*, != 3.2.*, != 3.3.*, != 3.4.* setup_requires = setuptools install_requires = + isodate jsonschema six + strict_rfc3339 tests_require = mock; python_version<"3.0" pytest diff --git a/tests/integration/test_validators.py b/tests/integration/test_validators.py index 931bda1..e977235 100644 --- a/tests/integration/test_validators.py +++ b/tests/integration/test_validators.py @@ -1,7 +1,9 @@ from jsonschema import ValidationError +import mock import pytest +from six import u -from openapi_schema_validator import OAS30Validator +from openapi_schema_validator import OAS30Validator, oas30_format_checker class TestOAS30ValidatorValidate(object): @@ -28,3 +30,45 @@ def test_nullable(self, schema_type): result = validator.validate(value) assert result is None + + @pytest.mark.parametrize('value', [ + u('1989-01-02T00:00:00Z'), + u('2018-01-02T23:59:59Z'), + ]) + @mock.patch( + 'openapi_schema_validator._format.' + 'DATETIME_HAS_STRICT_RFC3339', True + ) + @mock.patch( + 'openapi_schema_validator._format.' + 'DATETIME_HAS_ISODATE', False + ) + def test_string_format_datetime_strict_rfc3339(self, value): + schema = {"type": 'string', "format": 'date-time'} + validator = OAS30Validator( + schema, format_checker=oas30_format_checker) + + result = validator.validate(value) + + assert result is None + + @pytest.mark.parametrize('value', [ + u('1989-01-02T00:00:00Z'), + u('2018-01-02T23:59:59Z'), + ]) + @mock.patch( + 'openapi_schema_validator._format.' + 'DATETIME_HAS_STRICT_RFC3339', False + ) + @mock.patch( + 'openapi_schema_validator._format.' + 'DATETIME_HAS_ISODATE', True + ) + def test_string_format_datetime_isodate(self, value): + schema = {"type": 'string', "format": 'date-time'} + validator = OAS30Validator( + schema, format_checker=oas30_format_checker) + + result = validator.validate(value) + + assert result is None