|
4 | 4 |
|
5 | 5 | import os
|
6 | 6 |
|
| 7 | +import httpx |
7 | 8 | import pytest
|
| 9 | +from respx import MockRouter |
8 | 10 |
|
9 | 11 | from openai import OpenAI, AsyncOpenAI
|
10 | 12 | from tests.utils import assert_matches_type
|
11 | 13 | from openai.types import FileObject, FileDeleted
|
| 14 | +from openai._types import BinaryResponseContent |
12 | 15 | from openai._client import OpenAI, AsyncOpenAI
|
13 | 16 | from openai.pagination import SyncPage, AsyncPage
|
14 | 17 |
|
| 18 | +# pyright: reportDeprecated=false |
| 19 | + |
15 | 20 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
|
16 | 21 | api_key = "My API Key"
|
17 | 22 |
|
@@ -91,19 +96,43 @@ def test_raw_response_delete(self, client: OpenAI) -> None:
|
91 | 96 | assert_matches_type(FileDeleted, file, path=["response"])
|
92 | 97 |
|
93 | 98 | @parametrize
|
94 |
| - def test_method_retrieve_content(self, client: OpenAI) -> None: |
95 |
| - file = client.files.retrieve_content( |
| 99 | + @pytest.mark.respx(base_url=base_url) |
| 100 | + def test_method_content(self, client: OpenAI, respx_mock: MockRouter) -> None: |
| 101 | + respx_mock.get("/files/{file_id}/content").mock(return_value=httpx.Response(200, json={"foo": "bar"})) |
| 102 | + file = client.files.content( |
96 | 103 | "string",
|
97 | 104 | )
|
98 |
| - assert_matches_type(str, file, path=["response"]) |
| 105 | + assert isinstance(file, BinaryResponseContent) |
| 106 | + assert file.json() == {"foo": "bar"} |
99 | 107 |
|
100 | 108 | @parametrize
|
101 |
| - def test_raw_response_retrieve_content(self, client: OpenAI) -> None: |
102 |
| - response = client.files.with_raw_response.retrieve_content( |
| 109 | + @pytest.mark.respx(base_url=base_url) |
| 110 | + def test_raw_response_content(self, client: OpenAI, respx_mock: MockRouter) -> None: |
| 111 | + respx_mock.get("/files/{file_id}/content").mock(return_value=httpx.Response(200, json={"foo": "bar"})) |
| 112 | + response = client.files.with_raw_response.content( |
103 | 113 | "string",
|
104 | 114 | )
|
105 | 115 | assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
106 | 116 | file = response.parse()
|
| 117 | + assert isinstance(file, BinaryResponseContent) |
| 118 | + assert file.json() == {"foo": "bar"} |
| 119 | + |
| 120 | + @parametrize |
| 121 | + def test_method_retrieve_content(self, client: OpenAI) -> None: |
| 122 | + with pytest.warns(DeprecationWarning): |
| 123 | + file = client.files.retrieve_content( |
| 124 | + "string", |
| 125 | + ) |
| 126 | + assert_matches_type(str, file, path=["response"]) |
| 127 | + |
| 128 | + @parametrize |
| 129 | + def test_raw_response_retrieve_content(self, client: OpenAI) -> None: |
| 130 | + with pytest.warns(DeprecationWarning): |
| 131 | + response = client.files.with_raw_response.retrieve_content( |
| 132 | + "string", |
| 133 | + ) |
| 134 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 135 | + file = response.parse() |
107 | 136 | assert_matches_type(str, file, path=["response"])
|
108 | 137 |
|
109 | 138 |
|
@@ -182,17 +211,41 @@ async def test_raw_response_delete(self, client: AsyncOpenAI) -> None:
|
182 | 211 | assert_matches_type(FileDeleted, file, path=["response"])
|
183 | 212 |
|
184 | 213 | @parametrize
|
185 |
| - async def test_method_retrieve_content(self, client: AsyncOpenAI) -> None: |
186 |
| - file = await client.files.retrieve_content( |
| 214 | + @pytest.mark.respx(base_url=base_url) |
| 215 | + async def test_method_content(self, client: AsyncOpenAI, respx_mock: MockRouter) -> None: |
| 216 | + respx_mock.get("/files/{file_id}/content").mock(return_value=httpx.Response(200, json={"foo": "bar"})) |
| 217 | + file = await client.files.content( |
187 | 218 | "string",
|
188 | 219 | )
|
189 |
| - assert_matches_type(str, file, path=["response"]) |
| 220 | + assert isinstance(file, BinaryResponseContent) |
| 221 | + assert file.json() == {"foo": "bar"} |
190 | 222 |
|
191 | 223 | @parametrize
|
192 |
| - async def test_raw_response_retrieve_content(self, client: AsyncOpenAI) -> None: |
193 |
| - response = await client.files.with_raw_response.retrieve_content( |
| 224 | + @pytest.mark.respx(base_url=base_url) |
| 225 | + async def test_raw_response_content(self, client: AsyncOpenAI, respx_mock: MockRouter) -> None: |
| 226 | + respx_mock.get("/files/{file_id}/content").mock(return_value=httpx.Response(200, json={"foo": "bar"})) |
| 227 | + response = await client.files.with_raw_response.content( |
194 | 228 | "string",
|
195 | 229 | )
|
196 | 230 | assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
197 | 231 | file = response.parse()
|
| 232 | + assert isinstance(file, BinaryResponseContent) |
| 233 | + assert file.json() == {"foo": "bar"} |
| 234 | + |
| 235 | + @parametrize |
| 236 | + async def test_method_retrieve_content(self, client: AsyncOpenAI) -> None: |
| 237 | + with pytest.warns(DeprecationWarning): |
| 238 | + file = await client.files.retrieve_content( |
| 239 | + "string", |
| 240 | + ) |
| 241 | + assert_matches_type(str, file, path=["response"]) |
| 242 | + |
| 243 | + @parametrize |
| 244 | + async def test_raw_response_retrieve_content(self, client: AsyncOpenAI) -> None: |
| 245 | + with pytest.warns(DeprecationWarning): |
| 246 | + response = await client.files.with_raw_response.retrieve_content( |
| 247 | + "string", |
| 248 | + ) |
| 249 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 250 | + file = response.parse() |
198 | 251 | assert_matches_type(str, file, path=["response"])
|
0 commit comments