5
5
import os
6
6
from typing import Any , cast
7
7
8
+ import httpx
8
9
import pytest
10
+ from respx import MockRouter
9
11
12
+ import openai ._legacy_response as _legacy_response
10
13
from openai import OpenAI , AsyncOpenAI
14
+ from tests .utils import assert_matches_type
15
+
16
+ # pyright: reportDeprecated=false
11
17
12
18
base_url = os .environ .get ("TEST_API_BASE_URL" , "http://127.0.0.1:4010" )
13
19
@@ -16,15 +22,25 @@ class TestContent:
16
22
parametrize = pytest .mark .parametrize ("client" , [False , True ], indirect = True , ids = ["loose" , "strict" ])
17
23
18
24
@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
+ )
20
30
content = client .containers .files .content .retrieve (
21
31
file_id = "file_id" ,
22
32
container_id = "container_id" ,
23
33
)
24
- assert content is None
34
+ assert isinstance (content , _legacy_response .HttpxBinaryResponseContent )
35
+ assert content .json () == {"foo" : "bar" }
25
36
26
37
@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
+
28
44
response = client .containers .files .content .with_raw_response .retrieve (
29
45
file_id = "file_id" ,
30
46
container_id = "container_id" ,
@@ -33,10 +49,14 @@ def test_raw_response_retrieve(self, client: OpenAI) -> None:
33
49
assert response .is_closed is True
34
50
assert response .http_request .headers .get ("X-Stainless-Lang" ) == "python"
35
51
content = response .parse ()
36
- assert content is None
52
+ assert_matches_type ( _legacy_response . HttpxBinaryResponseContent , content , path = [ "response" ])
37
53
38
54
@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
+ )
40
60
with client .containers .files .content .with_streaming_response .retrieve (
41
61
file_id = "file_id" ,
42
62
container_id = "container_id" ,
@@ -45,11 +65,12 @@ def test_streaming_response_retrieve(self, client: OpenAI) -> None:
45
65
assert response .http_request .headers .get ("X-Stainless-Lang" ) == "python"
46
66
47
67
content = response .parse ()
48
- assert content is None
68
+ assert_matches_type ( bytes , content , path = [ "response" ])
49
69
50
70
assert cast (Any , response .is_closed ) is True
51
71
52
72
@parametrize
73
+ @pytest .mark .respx (base_url = base_url )
53
74
def test_path_params_retrieve (self , client : OpenAI ) -> None :
54
75
with pytest .raises (ValueError , match = r"Expected a non-empty value for `container_id` but received ''" ):
55
76
client .containers .files .content .with_raw_response .retrieve (
@@ -68,15 +89,25 @@ class TestAsyncContent:
68
89
parametrize = pytest .mark .parametrize ("async_client" , [False , True ], indirect = True , ids = ["loose" , "strict" ])
69
90
70
91
@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
+ )
72
97
content = await async_client .containers .files .content .retrieve (
73
98
file_id = "file_id" ,
74
99
container_id = "container_id" ,
75
100
)
76
- assert content is None
101
+ assert isinstance (content , _legacy_response .HttpxBinaryResponseContent )
102
+ assert content .json () == {"foo" : "bar" }
77
103
78
104
@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
+
80
111
response = await async_client .containers .files .content .with_raw_response .retrieve (
81
112
file_id = "file_id" ,
82
113
container_id = "container_id" ,
@@ -85,10 +116,14 @@ async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
85
116
assert response .is_closed is True
86
117
assert response .http_request .headers .get ("X-Stainless-Lang" ) == "python"
87
118
content = response .parse ()
88
- assert content is None
119
+ assert_matches_type ( _legacy_response . HttpxBinaryResponseContent , content , path = [ "response" ])
89
120
90
121
@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
+ )
92
127
async with async_client .containers .files .content .with_streaming_response .retrieve (
93
128
file_id = "file_id" ,
94
129
container_id = "container_id" ,
@@ -97,11 +132,12 @@ async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> N
97
132
assert response .http_request .headers .get ("X-Stainless-Lang" ) == "python"
98
133
99
134
content = await response .parse ()
100
- assert content is None
135
+ assert_matches_type ( bytes , content , path = [ "response" ])
101
136
102
137
assert cast (Any , response .is_closed ) is True
103
138
104
139
@parametrize
140
+ @pytest .mark .respx (base_url = base_url )
105
141
async def test_path_params_retrieve (self , async_client : AsyncOpenAI ) -> None :
106
142
with pytest .raises (ValueError , match = r"Expected a non-empty value for `container_id` but received ''" ):
107
143
await async_client .containers .files .content .with_raw_response .retrieve (
0 commit comments