From 9b1b5ffe776748b777f1c229e3fd1e95dcec6932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20K=C3=B6tter?= Date: Thu, 13 Jul 2023 01:36:35 +0200 Subject: [PATCH] tests - response content-type application/octet-stream --- aiopenapi3/v30/glue.py | 7 +++- tests/conftest.py | 5 +++ .../paths-response-content-type-octet.yaml | 38 +++++++++++++++++++ tests/path_test.py | 14 +++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/paths-response-content-type-octet.yaml diff --git a/aiopenapi3/v30/glue.py b/aiopenapi3/v30/glue.py index 692435f8..9be80344 100644 --- a/aiopenapi3/v30/glue.py +++ b/aiopenapi3/v30/glue.py @@ -432,8 +432,11 @@ def _process(self, result): ).unmarshalled return rheaders, data else: - # We have received a valid (i.e. expected) content type, - # but we can't validate it since it's not json. + """ + We have received a valid (i.e. expected) content type, + e.g. application/octet-stream + but we can't validate it since it's not json. + """ return rheaders, ctx.received diff --git a/tests/conftest.py b/tests/conftest.py index de68bf92..006b515f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -266,6 +266,11 @@ def with_paths_response_header(openapi_version): yield _get_parsed_yaml("paths-response-header.yaml", openapi_version) +@pytest.fixture +def with_paths_response_content_type_octet(): + yield _get_parsed_yaml("paths-response-content-type-octet.yaml") + + @pytest.fixture def with_paths_response_header_v20(): yield _get_parsed_yaml("paths-response-header-v20.yaml") diff --git a/tests/fixtures/paths-response-content-type-octet.yaml b/tests/fixtures/paths-response-content-type-octet.yaml new file mode 100644 index 00000000..fa8a41b1 --- /dev/null +++ b/tests/fixtures/paths-response-content-type-octet.yaml @@ -0,0 +1,38 @@ +openapi: 3.0.3 +info: + title: '' + version: 0.0.0 +servers: + - url: http://127.0.0.1/api + +security: + - {} + +paths: + /octet/headers: + get: + operationId: header + responses: + 200: + description: "ok" + content: + application/octet-stream: + schema: + type: string + format: byte + headers: + X-required: + required: true + schema: + type: string + /octet: + get: + operationId: octet + responses: + 200: + description: "ok" + content: + application/octet-stream: + schema: + type: string + format: byte diff --git a/tests/path_test.py b/tests/path_test.py index 46021403..075755a3 100644 --- a/tests/path_test.py +++ b/tests/path_test.py @@ -352,6 +352,20 @@ def test_paths_response_header(httpx_mock, with_paths_response_header): return +def test_paths_response_content_type_octet(httpx_mock, with_paths_response_content_type_octet): + CONTENT = b"\x00\x11" + httpx_mock.add_response(headers={"Content-Type": "application/octet-stream", "X-required": "1"}, content=CONTENT) + api = OpenAPI(URLBASE, with_paths_response_content_type_octet, session_factory=httpx.Client) + headers, data = api._.header(return_headers=True) + assert isinstance(headers["X-required"], str) + assert data == CONTENT + request = httpx_mock.get_requests()[-1] + + data = api._.octet() + assert data == CONTENT + request = httpx_mock.get_requests()[-1] + + def test_paths_tags(httpx_mock, with_paths_tags): import copy