Skip to content

Commit d3740fb

Browse files
committed
OAS32Validator basic tests
1 parent 946593c commit d3740fb

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

tests/integration/test_validators.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,10 +1023,47 @@ def test_format_checker_is_distinct_from_oas31(self):
10231023
assert oas32_format_checker is not oas31_format_checker
10241024

10251025
def test_validator_shares_oas31_behavior(self):
1026-
assert (
1027-
OAS32Validator.VALIDATORS == OAS31Validator.VALIDATORS
1026+
assert OAS32Validator.VALIDATORS == OAS31Validator.VALIDATORS
1027+
1028+
def test_format_validation_int32(self, validator_class):
1029+
schema = {"type": "integer", "format": "int32"}
1030+
validator = validator_class(
1031+
schema, format_checker=oas32_format_checker
1032+
)
1033+
1034+
result = validator.validate(42)
1035+
assert result is None
1036+
1037+
with pytest.raises(ValidationError):
1038+
validator.validate(9999999999)
1039+
1040+
def test_format_validation_date(self, validator_class):
1041+
schema = {"type": "string", "format": "date"}
1042+
validator = validator_class(
1043+
schema, format_checker=oas32_format_checker
10281044
)
10291045

1046+
result = validator.validate("2024-01-15")
1047+
assert result is None
1048+
1049+
with pytest.raises(ValidationError):
1050+
validator.validate("not-a-date")
1051+
1052+
def test_schema_with_allof(self, validator_class):
1053+
schema = {
1054+
"allOf": [
1055+
{"type": "object", "properties": {"id": {"type": "integer"}}},
1056+
{"type": "object", "properties": {"name": {"type": "string"}}},
1057+
]
1058+
}
1059+
validator = validator_class(schema)
1060+
1061+
result = validator.validate({"id": 1, "name": "test"})
1062+
assert result is None
1063+
1064+
with pytest.raises(ValidationError):
1065+
validator.validate({"id": "not-an-integer"})
1066+
10301067

10311068
class TestOAS30StrictValidator:
10321069
"""

0 commit comments

Comments
 (0)