Skip to content

Commit cd6996c

Browse files
committed
Add NullUnmarshaller tests
1 parent 418049e commit cd6996c

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

tests/unit/unmarshalling/test_unmarshal.py

+37-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import datetime
22
import uuid
3+
from functools import partial
34

45
import pytest
56
from isodate.tzinfo import UTC
67
from isodate.tzinfo import FixedOffset
78
from openapi_schema_validator import OAS30Validator
9+
from openapi_schema_validator import OAS31Validator
810

911
from openapi_core.spec.paths import Spec
1012
from openapi_core.unmarshalling.schemas.enums import UnmarshalContext
@@ -23,21 +25,25 @@
2325

2426

2527
@pytest.fixture
26-
def unmarshaller_factory():
28+
def schema_unmarshaller_factory():
2729
def create_unmarshaller(
28-
schema, custom_formatters=None, context=UnmarshalContext.REQUEST
30+
validator, schema, custom_formatters=None, context=None
2931
):
3032
custom_formatters = custom_formatters or {}
3133
return SchemaUnmarshallersFactory(
32-
OAS30Validator,
34+
validator,
3335
custom_formatters=custom_formatters,
3436
context=context,
3537
).create(schema)
3638

3739
return create_unmarshaller
3840

3941

40-
class TestUnmarshal:
42+
class TestOAS30SchemaUnmarshallerUnmarshal:
43+
@pytest.fixture
44+
def unmarshaller_factory(self, schema_unmarshaller_factory):
45+
return partial(schema_unmarshaller_factory, OAS30Validator)
46+
4147
def test_no_schema(self, unmarshaller_factory):
4248
spec = None
4349
value = "test"
@@ -79,7 +85,11 @@ def unmarshal(self, value):
7985
).unmarshal(value)
8086

8187

82-
class TestSchemaUnmarshallerCall:
88+
class TestOAS30SchemaUnmarshallerCall:
89+
@pytest.fixture
90+
def unmarshaller_factory(self, schema_unmarshaller_factory):
91+
return partial(schema_unmarshaller_factory, OAS30Validator)
92+
8393
def test_deprecated(self, unmarshaller_factory):
8494
schema = {
8595
"type": "string",
@@ -824,3 +834,25 @@ def test_additional_properties_list(self, unmarshaller_factory):
824834
assert result == {
825835
"user_ids": [1, 2, 3, 4],
826836
}
837+
838+
839+
class TestOAS31SchemaUnmarshallerCall:
840+
@pytest.fixture
841+
def unmarshaller_factory(self, schema_unmarshaller_factory):
842+
return partial(schema_unmarshaller_factory, OAS31Validator)
843+
844+
def test_null(self, unmarshaller_factory):
845+
schema = {"type": "null"}
846+
spec = Spec.from_dict(schema)
847+
848+
result = unmarshaller_factory(spec)(None)
849+
850+
assert result is None
851+
852+
@pytest.mark.parametrize("value", ["string", 2, 3.14, True, [1, 2], {}])
853+
def test_null_invalid(self, unmarshaller_factory, value):
854+
schema = {"type": "null"}
855+
spec = Spec.from_dict(schema)
856+
857+
with pytest.raises(InvalidSchemaValue):
858+
unmarshaller_factory(spec)(value)

0 commit comments

Comments
 (0)