diff --git a/tests/path_test.py b/tests/path_test.py index c6f3edb7..1d764658 100644 --- a/tests/path_test.py +++ b/tests/path_test.py @@ -111,6 +111,7 @@ def test_operation_populated(openapi_version, petstore_expanded): assert type(con2.schema_._target) == openapi_version.schema +@pytest.mark.httpx_mock(can_send_already_matched_responses=True) def test_paths_security(httpx_mock, with_paths_security): api = OpenAPI(URLBASE, with_paths_security, session_factory=httpx.Client, use_operation_tags=False) httpx_mock.add_response(headers={"Content-Type": "application/json"}, json="user") @@ -227,6 +228,7 @@ def test_paths_parameters_invalid(with_paths_parameters_invalid): OpenAPI(URLBASE, with_paths_parameters_invalid, session_factory=httpx.Client) +@pytest.mark.httpx_mock(can_send_already_matched_responses=True) def test_paths_parameters_oneOf(httpx_mock, with_paths_parameters_oneOf): api = OpenAPI(URLBASE, with_paths_parameters_oneOf, session_factory=httpx.Client) httpx_mock.add_response(headers={"Content-Type": "application/json"}, json="test") @@ -266,6 +268,7 @@ def test_paths_parameter_default(httpx_mock, with_paths_parameter_default): assert u.parts[3] == "path" +@pytest.mark.httpx_mock(can_send_already_matched_responses=True) def test_paths_parameter_format(httpx_mock, with_paths_parameter_format): httpx_mock.add_response(headers={"Content-Type": "application/json"}, json="test") api = OpenAPI(URLBASE, with_paths_parameter_format, session_factory=httpx.Client) @@ -389,6 +392,7 @@ def test_paths_parameter_format(httpx_mock, with_paths_parameter_format): return +@pytest.mark.httpx_mock(can_send_already_matched_responses=True) def test_paths_parameter_format_complex(httpx_mock, with_paths_parameter_format_complex): httpx_mock.add_response(headers={"Content-Type": "application/json"}, json="test") @@ -423,6 +427,7 @@ def test_paths_response_header(httpx_mock, with_paths_response_header): return +@pytest.mark.httpx_mock(can_send_already_matched_responses=True) 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) @@ -437,6 +442,7 @@ def test_paths_response_content_type_octet(httpx_mock, with_paths_response_conte request = httpx_mock.get_requests()[-1] +@pytest.mark.httpx_mock(can_send_already_matched_responses=True) def test_paths_tags(httpx_mock, with_paths_tags): import copy @@ -513,6 +519,7 @@ def test_paths_response_error(httpx_mock, with_paths_response_error): api._.test() +@pytest.mark.httpx_mock(can_send_already_matched_responses=True) def test_paths_request_calling(httpx_mock, with_paths_response_status_pattern_default): api = OpenAPI("/", with_paths_response_status_pattern_default, session_factory=httpx.Client) @@ -560,6 +567,7 @@ def test_paths_servers(httpx_mock, with_paths_servers): return +@pytest.mark.httpx_mock(can_send_already_matched_responses=True) def test_paths_server_variables(httpx_mock, with_paths_server_variables): api = OpenAPI("http://example/openapi.yaml", with_paths_server_variables, session_factory=httpx.Client) assert api.url.host == "default" diff --git a/tests/pathv20_test.py b/tests/pathv20_test.py index 04e38864..c4cdcdc3 100644 --- a/tests/pathv20_test.py +++ b/tests/pathv20_test.py @@ -20,6 +20,7 @@ def test_paths_security_v20_url(with_paths_security_v20): assert str(api.url) == "https://api.example.com/v1" +@pytest.mark.httpx_mock(can_send_already_matched_responses=True) def test_paths_security_v20_securityparameters(httpx_mock, with_paths_security_v20): api = OpenAPI(URLBASE, with_paths_security_v20, session_factory=httpx.Client) user = api._.createUser.return_value().get_type().model_construct(name="test", id=1) @@ -92,6 +93,7 @@ def test_paths_security_v20_alternate_securityparameters(httpx_mock, with_paths_ api._.alternateSecurity(data={}, parameters={}) +@pytest.mark.httpx_mock(can_send_already_matched_responses=True) def test_paths_security_v20_post_body(httpx_mock, with_paths_security_v20): auth = str(uuid.uuid4()) api = OpenAPI(URLBASE, with_paths_security_v20, session_factory=httpx.Client) @@ -147,6 +149,7 @@ def test_paths_response_header_v20(httpx_mock, with_paths_response_header_v20): return +@pytest.mark.httpx_mock(can_send_already_matched_responses=True) def test_paths_parameter_format_v20(httpx_mock, with_paths_parameter_format_v20): httpx_mock.add_response(headers={"Content-Type": "application/json"}, json="ok") api = OpenAPI(URLBASE, with_paths_parameter_format_v20, session_factory=httpx.Client) @@ -173,16 +176,30 @@ def test_paths_parameter_format_v20(httpx_mock, with_paths_parameter_format_v20) params["file1"] = ("file1name", io.BytesIO(b"y"), "ct") result = api._.formdata(parameters=params) request = httpx_mock.get_requests()[-1] + + import multipart + from httpx._multipart import MultipartStream + + files = dict() + + def on_file(file): + file.file_object.seek(0) + files[file.field_name] = (file.file_name.decode(), file.file_object) + + multipart.parse_form(request.headers, io.BytesIO(request.content), None, on_file) + + ms = MultipartStream({}, files=files) + assert ( - (f := request.stream.fields[0]) is not None + (f := ms.fields[0]) is not None and f.filename == "file0name" - and f.headers["Content-Type"] == "ct" + # and f.headers["Content-Type"] == "ct" and f.file.read() == b"x" ) assert ( - (f := request.stream.fields[1]) is not None + (f := ms.fields[1]) is not None and f.filename == "file1name" - and f.headers["Content-Type"] == "ct" + # and f.headers["Content-Type"] == "ct" and f.file.read() == b"y" ) assert result == "ok"