55import os
66from typing import Any , cast
77
8+ import httpx
89import pytest
10+ from respx import MockRouter
911
12+ import openai ._legacy_response as _legacy_response
1013from openai import OpenAI , AsyncOpenAI
14+ from tests .utils import assert_matches_type
15+
16+ # pyright: reportDeprecated=false
1117
1218base_url = os .environ .get ("TEST_API_BASE_URL" , "http://127.0.0.1:4010" )
1319
@@ -16,15 +22,25 @@ class TestContent:
1622 parametrize = pytest .mark .parametrize ("client" , [False , True ], indirect = True , ids = ["loose" , "strict" ])
1723
1824 @parametrize
19- def test_method_retrieve (self , client : OpenAI ) -> None :
25+ @pytest .mark .respx (base_url = base_url )
26+ def test_method_retrieve (self , client : OpenAI , respx_mock : MockRouter ) -> None :
27+ respx_mock .get ("/containers/container_id/files/file_id/content" ).mock (
28+ return_value = httpx .Response (200 , json = {"foo" : "bar" })
29+ )
2030 content = client .containers .files .content .retrieve (
2131 file_id = "file_id" ,
2232 container_id = "container_id" ,
2333 )
24- assert content is None
34+ assert isinstance (content , _legacy_response .HttpxBinaryResponseContent )
35+ assert content .json () == {"foo" : "bar" }
2536
2637 @parametrize
27- def test_raw_response_retrieve (self , client : OpenAI ) -> None :
38+ @pytest .mark .respx (base_url = base_url )
39+ def test_raw_response_retrieve (self , client : OpenAI , respx_mock : MockRouter ) -> None :
40+ respx_mock .get ("/containers/container_id/files/file_id/content" ).mock (
41+ return_value = httpx .Response (200 , json = {"foo" : "bar" })
42+ )
43+
2844 response = client .containers .files .content .with_raw_response .retrieve (
2945 file_id = "file_id" ,
3046 container_id = "container_id" ,
@@ -33,10 +49,14 @@ def test_raw_response_retrieve(self, client: OpenAI) -> None:
3349 assert response .is_closed is True
3450 assert response .http_request .headers .get ("X-Stainless-Lang" ) == "python"
3551 content = response .parse ()
36- assert content is None
52+ assert_matches_type ( _legacy_response . HttpxBinaryResponseContent , content , path = [ "response" ])
3753
3854 @parametrize
39- def test_streaming_response_retrieve (self , client : OpenAI ) -> None :
55+ @pytest .mark .respx (base_url = base_url )
56+ def test_streaming_response_retrieve (self , client : OpenAI , respx_mock : MockRouter ) -> None :
57+ respx_mock .get ("/containers/container_id/files/file_id/content" ).mock (
58+ return_value = httpx .Response (200 , json = {"foo" : "bar" })
59+ )
4060 with client .containers .files .content .with_streaming_response .retrieve (
4161 file_id = "file_id" ,
4262 container_id = "container_id" ,
@@ -45,11 +65,12 @@ def test_streaming_response_retrieve(self, client: OpenAI) -> None:
4565 assert response .http_request .headers .get ("X-Stainless-Lang" ) == "python"
4666
4767 content = response .parse ()
48- assert content is None
68+ assert_matches_type ( bytes , content , path = [ "response" ])
4969
5070 assert cast (Any , response .is_closed ) is True
5171
5272 @parametrize
73+ @pytest .mark .respx (base_url = base_url )
5374 def test_path_params_retrieve (self , client : OpenAI ) -> None :
5475 with pytest .raises (ValueError , match = r"Expected a non-empty value for `container_id` but received ''" ):
5576 client .containers .files .content .with_raw_response .retrieve (
@@ -68,15 +89,25 @@ class TestAsyncContent:
6889 parametrize = pytest .mark .parametrize ("async_client" , [False , True ], indirect = True , ids = ["loose" , "strict" ])
6990
7091 @parametrize
71- async def test_method_retrieve (self , async_client : AsyncOpenAI ) -> None :
92+ @pytest .mark .respx (base_url = base_url )
93+ async def test_method_retrieve (self , async_client : AsyncOpenAI , respx_mock : MockRouter ) -> None :
94+ respx_mock .get ("/containers/container_id/files/file_id/content" ).mock (
95+ return_value = httpx .Response (200 , json = {"foo" : "bar" })
96+ )
7297 content = await async_client .containers .files .content .retrieve (
7398 file_id = "file_id" ,
7499 container_id = "container_id" ,
75100 )
76- assert content is None
101+ assert isinstance (content , _legacy_response .HttpxBinaryResponseContent )
102+ assert content .json () == {"foo" : "bar" }
77103
78104 @parametrize
79- async def test_raw_response_retrieve (self , async_client : AsyncOpenAI ) -> None :
105+ @pytest .mark .respx (base_url = base_url )
106+ async def test_raw_response_retrieve (self , async_client : AsyncOpenAI , respx_mock : MockRouter ) -> None :
107+ respx_mock .get ("/containers/container_id/files/file_id/content" ).mock (
108+ return_value = httpx .Response (200 , json = {"foo" : "bar" })
109+ )
110+
80111 response = await async_client .containers .files .content .with_raw_response .retrieve (
81112 file_id = "file_id" ,
82113 container_id = "container_id" ,
@@ -85,10 +116,14 @@ async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
85116 assert response .is_closed is True
86117 assert response .http_request .headers .get ("X-Stainless-Lang" ) == "python"
87118 content = response .parse ()
88- assert content is None
119+ assert_matches_type ( _legacy_response . HttpxBinaryResponseContent , content , path = [ "response" ])
89120
90121 @parametrize
91- async def test_streaming_response_retrieve (self , async_client : AsyncOpenAI ) -> None :
122+ @pytest .mark .respx (base_url = base_url )
123+ async def test_streaming_response_retrieve (self , async_client : AsyncOpenAI , respx_mock : MockRouter ) -> None :
124+ respx_mock .get ("/containers/container_id/files/file_id/content" ).mock (
125+ return_value = httpx .Response (200 , json = {"foo" : "bar" })
126+ )
92127 async with async_client .containers .files .content .with_streaming_response .retrieve (
93128 file_id = "file_id" ,
94129 container_id = "container_id" ,
@@ -97,11 +132,12 @@ async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> N
97132 assert response .http_request .headers .get ("X-Stainless-Lang" ) == "python"
98133
99134 content = await response .parse ()
100- assert content is None
135+ assert_matches_type ( bytes , content , path = [ "response" ])
101136
102137 assert cast (Any , response .is_closed ) is True
103138
104139 @parametrize
140+ @pytest .mark .respx (base_url = base_url )
105141 async def test_path_params_retrieve (self , async_client : AsyncOpenAI ) -> None :
106142 with pytest .raises (ValueError , match = r"Expected a non-empty value for `container_id` but received ''" ):
107143 await async_client .containers .files .content .with_raw_response .retrieve (
0 commit comments