Skip to content

Commit 0a0565d

Browse files
committed
Request unmarshaller test formatting fix
1 parent fe55453 commit 0a0565d

File tree

1 file changed

+43
-35
lines changed

1 file changed

+43
-35
lines changed

tests/unit/unmarshalling/test_request_unmarshallers.py

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import enum
2+
23
import pytest
34
from jsonschema_path import SchemaPath
45

5-
from openapi_core import V30RequestUnmarshaller, V31RequestUnmarshaller
6+
from openapi_core import V30RequestUnmarshaller
7+
from openapi_core import V31RequestUnmarshaller
68
from openapi_core.datatypes import Parameters
79
from openapi_core.testing import MockRequest
810

@@ -43,13 +45,11 @@ def spec_dict(self):
4345
"$ref": "#/components/schemas/createResource"
4446
}
4547
}
46-
}
48+
},
4749
},
4850
"responses": {
49-
"201": {
50-
"description": "Resource was created."
51-
}
52-
}
51+
"201": {"description": "Resource was created."}
52+
},
5353
},
5454
"get": {
5555
"description": "POST resources test request",
@@ -67,61 +67,69 @@ def spec_dict(self):
6767
"default": {
6868
"description": "Returned resources matching request."
6969
}
70-
}
71-
}
70+
},
71+
},
7272
}
7373
},
7474
"components": {
7575
"schemas": {
7676
"colors": {
7777
"type": "string",
7878
"enum": ["yellow", "blue", "red"],
79-
"format": "enum_Colors"
79+
"format": "enum_Colors",
8080
},
8181
"createResource": {
8282
"type": "object",
8383
"properties": {
84-
"resId": {
85-
"type": "integer"
86-
},
87-
"color": {
88-
"$ref": "#/components/schemas/colors"
89-
}
84+
"resId": {"type": "integer"},
85+
"color": {"$ref": "#/components/schemas/colors"},
9086
},
91-
"required": ["resId", "color"]
92-
}
87+
"required": ["resId", "color"],
88+
},
9389
}
94-
}
90+
},
9591
}
9692

9793
@pytest.fixture(scope="session")
9894
def spec(self, spec_dict):
9995
return SchemaPath.from_dict(spec_dict)
10096

101-
@pytest.mark.parametrize("req_unmarshaller_cls", [V30RequestUnmarshaller, V31RequestUnmarshaller])
97+
@pytest.mark.parametrize(
98+
"req_unmarshaller_cls",
99+
[V30RequestUnmarshaller, V31RequestUnmarshaller],
100+
)
102101
def test_request_body_extra_unmarshaller(self, spec, req_unmarshaller_cls):
103-
ru = req_unmarshaller_cls(spec=spec, extra_format_unmarshallers={
104-
"enum_Colors": Colors.of
105-
})
106-
request = MockRequest(host_url="http://example.com",
107-
method="post",
108-
path="/resources",
109-
data=b'{"resId": 23498572, "color": "blue"}')
102+
ru = req_unmarshaller_cls(
103+
spec=spec, extra_format_unmarshallers={"enum_Colors": Colors.of}
104+
)
105+
request = MockRequest(
106+
host_url="http://example.com",
107+
method="post",
108+
path="/resources",
109+
data=b'{"resId": 23498572, "color": "blue"}',
110+
)
110111
result = ru.unmarshal(request)
111112

112113
assert not result.errors
113114
assert result.body == {"resId": 23498572, "color": Colors.BLUE}
114115
assert result.parameters == Parameters()
115116

116-
@pytest.mark.parametrize("req_unmarshaller_cls", [V30RequestUnmarshaller, V31RequestUnmarshaller])
117-
def test_request_param_extra_unmarshaller(self, spec, req_unmarshaller_cls):
118-
ru = req_unmarshaller_cls(spec=spec, extra_format_unmarshallers={
119-
"enum_Colors": Colors.of
120-
})
121-
request = MockRequest(host_url="http://example.com",
122-
method="get",
123-
path="/resources",
124-
args={"color": "blue"})
117+
@pytest.mark.parametrize(
118+
"req_unmarshaller_cls",
119+
[V30RequestUnmarshaller, V31RequestUnmarshaller],
120+
)
121+
def test_request_param_extra_unmarshaller(
122+
self, spec, req_unmarshaller_cls
123+
):
124+
ru = req_unmarshaller_cls(
125+
spec=spec, extra_format_unmarshallers={"enum_Colors": Colors.of}
126+
)
127+
request = MockRequest(
128+
host_url="http://example.com",
129+
method="get",
130+
path="/resources",
131+
args={"color": "blue"},
132+
)
125133
result = ru.unmarshal(request)
126134

127135
assert not result.errors

0 commit comments

Comments
 (0)