openai/openai-python
Publicmirrored fromhttps://github.com/openai/openai-pythonAvailable
tests/api_resources/admin/organization/test_groups.py
395lines · modecode
| 1 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import os |
| 6 | from typing import Any, cast |
| 7 | |
| 8 | import pytest |
| 9 | |
| 10 | from openai import OpenAI, AsyncOpenAI |
| 11 | from tests.utils import assert_matches_type |
| 12 | from openai.pagination import SyncNextCursorPage, AsyncNextCursorPage |
| 13 | from openai.types.admin.organization import ( |
| 14 | Group, |
| 15 | GroupDeleteResponse, |
| 16 | GroupUpdateResponse, |
| 17 | ) |
| 18 | |
| 19 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 20 | |
| 21 | |
| 22 | class TestGroups: |
| 23 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 24 | |
| 25 | @parametrize |
| 26 | def test_method_create(self, client: OpenAI) -> None: |
| 27 | group = client.admin.organization.groups.create( |
| 28 | name="x", |
| 29 | ) |
| 30 | assert_matches_type(Group, group, path=["response"]) |
| 31 | |
| 32 | @parametrize |
| 33 | def test_raw_response_create(self, client: OpenAI) -> None: |
| 34 | response = client.admin.organization.groups.with_raw_response.create( |
| 35 | name="x", |
| 36 | ) |
| 37 | |
| 38 | assert response.is_closed is True |
| 39 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 40 | group = response.parse() |
| 41 | assert_matches_type(Group, group, path=["response"]) |
| 42 | |
| 43 | @parametrize |
| 44 | def test_streaming_response_create(self, client: OpenAI) -> None: |
| 45 | with client.admin.organization.groups.with_streaming_response.create( |
| 46 | name="x", |
| 47 | ) as response: |
| 48 | assert not response.is_closed |
| 49 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 50 | |
| 51 | group = response.parse() |
| 52 | assert_matches_type(Group, group, path=["response"]) |
| 53 | |
| 54 | assert cast(Any, response.is_closed) is True |
| 55 | |
| 56 | @parametrize |
| 57 | def test_method_retrieve(self, client: OpenAI) -> None: |
| 58 | group = client.admin.organization.groups.retrieve( |
| 59 | "group_id", |
| 60 | ) |
| 61 | assert_matches_type(Group, group, path=["response"]) |
| 62 | |
| 63 | @parametrize |
| 64 | def test_raw_response_retrieve(self, client: OpenAI) -> None: |
| 65 | response = client.admin.organization.groups.with_raw_response.retrieve( |
| 66 | "group_id", |
| 67 | ) |
| 68 | |
| 69 | assert response.is_closed is True |
| 70 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 71 | group = response.parse() |
| 72 | assert_matches_type(Group, group, path=["response"]) |
| 73 | |
| 74 | @parametrize |
| 75 | def test_streaming_response_retrieve(self, client: OpenAI) -> None: |
| 76 | with client.admin.organization.groups.with_streaming_response.retrieve( |
| 77 | "group_id", |
| 78 | ) as response: |
| 79 | assert not response.is_closed |
| 80 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 81 | |
| 82 | group = response.parse() |
| 83 | assert_matches_type(Group, group, path=["response"]) |
| 84 | |
| 85 | assert cast(Any, response.is_closed) is True |
| 86 | |
| 87 | @parametrize |
| 88 | def test_path_params_retrieve(self, client: OpenAI) -> None: |
| 89 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 90 | client.admin.organization.groups.with_raw_response.retrieve( |
| 91 | "", |
| 92 | ) |
| 93 | |
| 94 | @parametrize |
| 95 | def test_method_update(self, client: OpenAI) -> None: |
| 96 | group = client.admin.organization.groups.update( |
| 97 | group_id="group_id", |
| 98 | name="x", |
| 99 | ) |
| 100 | assert_matches_type(GroupUpdateResponse, group, path=["response"]) |
| 101 | |
| 102 | @parametrize |
| 103 | def test_raw_response_update(self, client: OpenAI) -> None: |
| 104 | response = client.admin.organization.groups.with_raw_response.update( |
| 105 | group_id="group_id", |
| 106 | name="x", |
| 107 | ) |
| 108 | |
| 109 | assert response.is_closed is True |
| 110 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 111 | group = response.parse() |
| 112 | assert_matches_type(GroupUpdateResponse, group, path=["response"]) |
| 113 | |
| 114 | @parametrize |
| 115 | def test_streaming_response_update(self, client: OpenAI) -> None: |
| 116 | with client.admin.organization.groups.with_streaming_response.update( |
| 117 | group_id="group_id", |
| 118 | name="x", |
| 119 | ) as response: |
| 120 | assert not response.is_closed |
| 121 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 122 | |
| 123 | group = response.parse() |
| 124 | assert_matches_type(GroupUpdateResponse, group, path=["response"]) |
| 125 | |
| 126 | assert cast(Any, response.is_closed) is True |
| 127 | |
| 128 | @parametrize |
| 129 | def test_path_params_update(self, client: OpenAI) -> None: |
| 130 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 131 | client.admin.organization.groups.with_raw_response.update( |
| 132 | group_id="", |
| 133 | name="x", |
| 134 | ) |
| 135 | |
| 136 | @parametrize |
| 137 | def test_method_list(self, client: OpenAI) -> None: |
| 138 | group = client.admin.organization.groups.list() |
| 139 | assert_matches_type(SyncNextCursorPage[Group], group, path=["response"]) |
| 140 | |
| 141 | @parametrize |
| 142 | def test_method_list_with_all_params(self, client: OpenAI) -> None: |
| 143 | group = client.admin.organization.groups.list( |
| 144 | after="after", |
| 145 | limit=0, |
| 146 | order="asc", |
| 147 | ) |
| 148 | assert_matches_type(SyncNextCursorPage[Group], group, path=["response"]) |
| 149 | |
| 150 | @parametrize |
| 151 | def test_raw_response_list(self, client: OpenAI) -> None: |
| 152 | response = client.admin.organization.groups.with_raw_response.list() |
| 153 | |
| 154 | assert response.is_closed is True |
| 155 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 156 | group = response.parse() |
| 157 | assert_matches_type(SyncNextCursorPage[Group], group, path=["response"]) |
| 158 | |
| 159 | @parametrize |
| 160 | def test_streaming_response_list(self, client: OpenAI) -> None: |
| 161 | with client.admin.organization.groups.with_streaming_response.list() as response: |
| 162 | assert not response.is_closed |
| 163 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 164 | |
| 165 | group = response.parse() |
| 166 | assert_matches_type(SyncNextCursorPage[Group], group, path=["response"]) |
| 167 | |
| 168 | assert cast(Any, response.is_closed) is True |
| 169 | |
| 170 | @parametrize |
| 171 | def test_method_delete(self, client: OpenAI) -> None: |
| 172 | group = client.admin.organization.groups.delete( |
| 173 | "group_id", |
| 174 | ) |
| 175 | assert_matches_type(GroupDeleteResponse, group, path=["response"]) |
| 176 | |
| 177 | @parametrize |
| 178 | def test_raw_response_delete(self, client: OpenAI) -> None: |
| 179 | response = client.admin.organization.groups.with_raw_response.delete( |
| 180 | "group_id", |
| 181 | ) |
| 182 | |
| 183 | assert response.is_closed is True |
| 184 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 185 | group = response.parse() |
| 186 | assert_matches_type(GroupDeleteResponse, group, path=["response"]) |
| 187 | |
| 188 | @parametrize |
| 189 | def test_streaming_response_delete(self, client: OpenAI) -> None: |
| 190 | with client.admin.organization.groups.with_streaming_response.delete( |
| 191 | "group_id", |
| 192 | ) as response: |
| 193 | assert not response.is_closed |
| 194 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 195 | |
| 196 | group = response.parse() |
| 197 | assert_matches_type(GroupDeleteResponse, group, path=["response"]) |
| 198 | |
| 199 | assert cast(Any, response.is_closed) is True |
| 200 | |
| 201 | @parametrize |
| 202 | def test_path_params_delete(self, client: OpenAI) -> None: |
| 203 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 204 | client.admin.organization.groups.with_raw_response.delete( |
| 205 | "", |
| 206 | ) |
| 207 | |
| 208 | |
| 209 | class TestAsyncGroups: |
| 210 | parametrize = pytest.mark.parametrize( |
| 211 | "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] |
| 212 | ) |
| 213 | |
| 214 | @parametrize |
| 215 | async def test_method_create(self, async_client: AsyncOpenAI) -> None: |
| 216 | group = await async_client.admin.organization.groups.create( |
| 217 | name="x", |
| 218 | ) |
| 219 | assert_matches_type(Group, group, path=["response"]) |
| 220 | |
| 221 | @parametrize |
| 222 | async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None: |
| 223 | response = await async_client.admin.organization.groups.with_raw_response.create( |
| 224 | name="x", |
| 225 | ) |
| 226 | |
| 227 | assert response.is_closed is True |
| 228 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 229 | group = response.parse() |
| 230 | assert_matches_type(Group, group, path=["response"]) |
| 231 | |
| 232 | @parametrize |
| 233 | async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None: |
| 234 | async with async_client.admin.organization.groups.with_streaming_response.create( |
| 235 | name="x", |
| 236 | ) as response: |
| 237 | assert not response.is_closed |
| 238 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 239 | |
| 240 | group = await response.parse() |
| 241 | assert_matches_type(Group, group, path=["response"]) |
| 242 | |
| 243 | assert cast(Any, response.is_closed) is True |
| 244 | |
| 245 | @parametrize |
| 246 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 247 | group = await async_client.admin.organization.groups.retrieve( |
| 248 | "group_id", |
| 249 | ) |
| 250 | assert_matches_type(Group, group, path=["response"]) |
| 251 | |
| 252 | @parametrize |
| 253 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 254 | response = await async_client.admin.organization.groups.with_raw_response.retrieve( |
| 255 | "group_id", |
| 256 | ) |
| 257 | |
| 258 | assert response.is_closed is True |
| 259 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 260 | group = response.parse() |
| 261 | assert_matches_type(Group, group, path=["response"]) |
| 262 | |
| 263 | @parametrize |
| 264 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 265 | async with async_client.admin.organization.groups.with_streaming_response.retrieve( |
| 266 | "group_id", |
| 267 | ) as response: |
| 268 | assert not response.is_closed |
| 269 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 270 | |
| 271 | group = await response.parse() |
| 272 | assert_matches_type(Group, group, path=["response"]) |
| 273 | |
| 274 | assert cast(Any, response.is_closed) is True |
| 275 | |
| 276 | @parametrize |
| 277 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 278 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 279 | await async_client.admin.organization.groups.with_raw_response.retrieve( |
| 280 | "", |
| 281 | ) |
| 282 | |
| 283 | @parametrize |
| 284 | async def test_method_update(self, async_client: AsyncOpenAI) -> None: |
| 285 | group = await async_client.admin.organization.groups.update( |
| 286 | group_id="group_id", |
| 287 | name="x", |
| 288 | ) |
| 289 | assert_matches_type(GroupUpdateResponse, group, path=["response"]) |
| 290 | |
| 291 | @parametrize |
| 292 | async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None: |
| 293 | response = await async_client.admin.organization.groups.with_raw_response.update( |
| 294 | group_id="group_id", |
| 295 | name="x", |
| 296 | ) |
| 297 | |
| 298 | assert response.is_closed is True |
| 299 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 300 | group = response.parse() |
| 301 | assert_matches_type(GroupUpdateResponse, group, path=["response"]) |
| 302 | |
| 303 | @parametrize |
| 304 | async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None: |
| 305 | async with async_client.admin.organization.groups.with_streaming_response.update( |
| 306 | group_id="group_id", |
| 307 | name="x", |
| 308 | ) as response: |
| 309 | assert not response.is_closed |
| 310 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 311 | |
| 312 | group = await response.parse() |
| 313 | assert_matches_type(GroupUpdateResponse, group, path=["response"]) |
| 314 | |
| 315 | assert cast(Any, response.is_closed) is True |
| 316 | |
| 317 | @parametrize |
| 318 | async def test_path_params_update(self, async_client: AsyncOpenAI) -> None: |
| 319 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 320 | await async_client.admin.organization.groups.with_raw_response.update( |
| 321 | group_id="", |
| 322 | name="x", |
| 323 | ) |
| 324 | |
| 325 | @parametrize |
| 326 | async def test_method_list(self, async_client: AsyncOpenAI) -> None: |
| 327 | group = await async_client.admin.organization.groups.list() |
| 328 | assert_matches_type(AsyncNextCursorPage[Group], group, path=["response"]) |
| 329 | |
| 330 | @parametrize |
| 331 | async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 332 | group = await async_client.admin.organization.groups.list( |
| 333 | after="after", |
| 334 | limit=0, |
| 335 | order="asc", |
| 336 | ) |
| 337 | assert_matches_type(AsyncNextCursorPage[Group], group, path=["response"]) |
| 338 | |
| 339 | @parametrize |
| 340 | async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None: |
| 341 | response = await async_client.admin.organization.groups.with_raw_response.list() |
| 342 | |
| 343 | assert response.is_closed is True |
| 344 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 345 | group = response.parse() |
| 346 | assert_matches_type(AsyncNextCursorPage[Group], group, path=["response"]) |
| 347 | |
| 348 | @parametrize |
| 349 | async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None: |
| 350 | async with async_client.admin.organization.groups.with_streaming_response.list() as response: |
| 351 | assert not response.is_closed |
| 352 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 353 | |
| 354 | group = await response.parse() |
| 355 | assert_matches_type(AsyncNextCursorPage[Group], group, path=["response"]) |
| 356 | |
| 357 | assert cast(Any, response.is_closed) is True |
| 358 | |
| 359 | @parametrize |
| 360 | async def test_method_delete(self, async_client: AsyncOpenAI) -> None: |
| 361 | group = await async_client.admin.organization.groups.delete( |
| 362 | "group_id", |
| 363 | ) |
| 364 | assert_matches_type(GroupDeleteResponse, group, path=["response"]) |
| 365 | |
| 366 | @parametrize |
| 367 | async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None: |
| 368 | response = await async_client.admin.organization.groups.with_raw_response.delete( |
| 369 | "group_id", |
| 370 | ) |
| 371 | |
| 372 | assert response.is_closed is True |
| 373 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 374 | group = response.parse() |
| 375 | assert_matches_type(GroupDeleteResponse, group, path=["response"]) |
| 376 | |
| 377 | @parametrize |
| 378 | async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None: |
| 379 | async with async_client.admin.organization.groups.with_streaming_response.delete( |
| 380 | "group_id", |
| 381 | ) as response: |
| 382 | assert not response.is_closed |
| 383 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 384 | |
| 385 | group = await response.parse() |
| 386 | assert_matches_type(GroupDeleteResponse, group, path=["response"]) |
| 387 | |
| 388 | assert cast(Any, response.is_closed) is True |
| 389 | |
| 390 | @parametrize |
| 391 | async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None: |
| 392 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 393 | await async_client.admin.organization.groups.with_raw_response.delete( |
| 394 | "", |
| 395 | ) |
| 396 | |