Skip to content

Commit

Permalink
tests - response content-type application/octet-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
commonism committed Jul 12, 2023
1 parent 66f9dfc commit 833355f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
7 changes: 5 additions & 2 deletions aiopenapi3/v30/glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
38 changes: 38 additions & 0 deletions tests/fixtures/paths-response-content-type-octet.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions tests/path_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 833355f

Please sign in to comment.