Skip to content

Commit 04cbaa5

Browse files
refactor: update body() to not decode bytes
The underlying openapi-code library changed how they pass back the response body in 0.19 Refs: python-openapi/openapi-core#710 Co-authored-by: Wim De Clercq <[email protected]> Signed-off-by: Mike Fiedler <[email protected]>
1 parent 8686e3b commit 04cbaa5

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

pyramid_openapi3/tests/test_contenttypes.py

-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ def test_post_json(self) -> None:
7272
res = self._testapp().post_json("/foo", {"bar": "baz"}, status=200)
7373
self.assertEqual(res.json, {"bar": "zab"})
7474

75-
# FIXME: Something deep in request validation isn't happy right now.
76-
# Might be related: https://github.com/Pylons/pyramid_openapi3/issues/199
77-
@unittest.expectedFailure
7875
def test_post_form(self) -> None: # pragma: no cover
7976
"""Post with `application/x-www-form-urlencoded`."""
8077

pyramid_openapi3/tests/test_wrappers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_relative_app_request() -> None:
7272
assert openapi_request.path == "/subpath/foo"
7373
assert openapi_request.path_pattern == "/foo"
7474
assert openapi_request.method == "get"
75-
assert openapi_request.body == ""
75+
assert openapi_request.body == b""
7676
assert openapi_request.mimetype == "text/html"
7777
assert openapi_request.content_type == "text/html"
7878

@@ -114,7 +114,7 @@ def test_mapped_values_response() -> None:
114114

115115
openapi_response = PyramidOpenAPIResponse(pyramid_request.response)
116116

117-
assert openapi_response.data == ""
117+
assert openapi_response.data == b""
118118
assert openapi_response.status_code == 200
119119
assert openapi_response.mimetype == "text/html"
120120
assert openapi_response.content_type == "text/html"

pyramid_openapi3/wrappers.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ def method(self) -> str:
4747
return self.request.method.lower()
4848

4949
@property
50-
def body(self) -> t.Optional[t.Union[str, t.Dict]]:
51-
"""The request body, as string.""" # noqa D401
50+
def body(self) -> t.Optional[t.Union[bytes, str, t.Dict]]:
51+
"""The request body.""" # noqa D401
5252
if "multipart/form-data" == self.request.content_type:
5353
return self.request.POST.mixed()
54-
if isinstance(self.request.body, bytes):
55-
return self.request.body.decode("utf-8")
5654
return self.request.body
5755

5856
@property
@@ -71,9 +69,9 @@ def __init__(self, response: Response) -> None:
7169
self.response = response
7270

7371
@property
74-
def data(self) -> str:
75-
"""The response body, as string.""" # noqa D401
76-
return self.response.text
72+
def data(self) -> bytes:
73+
"""The response body.""" # noqa D401
74+
return self.response.body
7775

7876
@property
7977
def status_code(self) -> int:

0 commit comments

Comments
 (0)