Skip to content

Commit 8c34462

Browse files
authored
Merge pull request #4 from DaniilGlazkoTR/feature/licensing
Switch to a MIT-licensed dependency
2 parents c86b093 + 48ffd98 commit 8c34462

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed

openapi_schema_validator/_format.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from jsonschema.exceptions import FormatError
88
from six import binary_type, text_type, integer_types
99

10+
DATETIME_HAS_RFC3339_VALIDATOR = False
1011
DATETIME_HAS_STRICT_RFC3339 = False
1112
DATETIME_HAS_ISODATE = False
1213
DATETIME_RAISES = ()
@@ -19,6 +20,14 @@
1920
DATETIME_HAS_ISODATE = True
2021
DATETIME_RAISES += (ValueError, isodate.ISO8601Error)
2122

23+
try:
24+
from rfc3339_validator import validate_rfc3339
25+
except ImportError:
26+
pass
27+
else:
28+
DATETIME_HAS_RFC3339_VALIDATOR = True
29+
DATETIME_RAISES += (ValueError, TypeError)
30+
2231
try:
2332
import strict_rfc3339
2433
except ImportError:
@@ -64,6 +73,9 @@ def is_datetime(instance):
6473
if not isinstance(instance, (binary_type, text_type)):
6574
return False
6675

76+
if DATETIME_HAS_RFC3339_VALIDATOR:
77+
return validate_rfc3339(instance)
78+
6779
if DATETIME_HAS_STRICT_RFC3339:
6880
return strict_rfc3339.validate_rfc3339(instance)
6981

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
isodate
22
jsonschema
33
six
4-
strict_rfc3339
4+
strict-rfc3339
5+
rfc3339-validator

setup.cfg

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@ install_requires =
2929
isodate
3030
jsonschema>=3.0.0
3131
six
32-
strict_rfc3339
3332
tests_require =
3433
mock; python_version<"3.0"
3534
pytest
3635
pytest-flake8
3736
pytest-cov
3837

38+
[options.extras_require]
39+
rfc3339-validator =
40+
rfc3339-validator
41+
strict-rfc3339 =
42+
strict-rfc3339
43+
isodate =
44+
isodate
45+
3946
[options.packages.find]
4047
exclude =
4148
tests

tests/integration/test_validators.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,60 @@ def test_nullable(self, schema_type):
3535
u('1989-01-02T00:00:00Z'),
3636
u('2018-01-02T23:59:59Z'),
3737
])
38+
@mock.patch(
39+
'openapi_schema_validator._format.'
40+
'DATETIME_HAS_RFC3339_VALIDATOR', False
41+
)
42+
@mock.patch(
43+
'openapi_schema_validator._format.'
44+
'DATETIME_HAS_STRICT_RFC3339', False
45+
)
46+
@mock.patch(
47+
'openapi_schema_validator._format.'
48+
'DATETIME_HAS_ISODATE', False
49+
)
50+
def test_string_format_no_datetime_validator(self, value):
51+
schema = {"type": 'string', "format": 'date-time'}
52+
validator = OAS30Validator(
53+
schema, format_checker=oas30_format_checker)
54+
55+
result = validator.validate(value)
56+
57+
assert result is None
58+
59+
@pytest.mark.parametrize('value', [
60+
u('1989-01-02T00:00:00Z'),
61+
u('2018-01-02T23:59:59Z'),
62+
])
63+
@mock.patch(
64+
'openapi_schema_validator._format.'
65+
'DATETIME_HAS_RFC3339_VALIDATOR', True
66+
)
67+
@mock.patch(
68+
'openapi_schema_validator._format.'
69+
'DATETIME_HAS_STRICT_RFC3339', False
70+
)
71+
@mock.patch(
72+
'openapi_schema_validator._format.'
73+
'DATETIME_HAS_ISODATE', False
74+
)
75+
def test_string_format_datetime_rfc3339_validator(self, value):
76+
schema = {"type": 'string', "format": 'date-time'}
77+
validator = OAS30Validator(
78+
schema, format_checker=oas30_format_checker)
79+
80+
result = validator.validate(value)
81+
82+
assert result is None
83+
84+
@pytest.mark.parametrize('value', [
85+
u('1989-01-02T00:00:00Z'),
86+
u('2018-01-02T23:59:59Z'),
87+
])
88+
@mock.patch(
89+
'openapi_schema_validator._format.'
90+
'DATETIME_HAS_RFC3339_VALIDATOR', False
91+
)
3892
@mock.patch(
3993
'openapi_schema_validator._format.'
4094
'DATETIME_HAS_STRICT_RFC3339', True
@@ -56,6 +110,10 @@ def test_string_format_datetime_strict_rfc3339(self, value):
56110
u('1989-01-02T00:00:00Z'),
57111
u('2018-01-02T23:59:59Z'),
58112
])
113+
@mock.patch(
114+
'openapi_schema_validator._format.'
115+
'DATETIME_HAS_RFC3339_VALIDATOR', False
116+
)
59117
@mock.patch(
60118
'openapi_schema_validator._format.'
61119
'DATETIME_HAS_STRICT_RFC3339', False

0 commit comments

Comments
 (0)