openai/openai-python
Publicmirrored fromhttps://github.com/openai/openai-pythonAvailable
tests/api_resources/admin/organization/projects/groups/test_roles.py
494lines · 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.projects.groups import ( |
| 14 | RoleListResponse, |
| 15 | RoleCreateResponse, |
| 16 | RoleDeleteResponse, |
| 17 | RoleRetrieveResponse, |
| 18 | ) |
| 19 | |
| 20 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 21 | |
| 22 | |
| 23 | class TestRoles: |
| 24 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 25 | |
| 26 | @parametrize |
| 27 | def test_method_create(self, client: OpenAI) -> None: |
| 28 | role = client.admin.organization.projects.groups.roles.create( |
| 29 | group_id="group_id", |
| 30 | project_id="project_id", |
| 31 | role_id="role_id", |
| 32 | ) |
| 33 | assert_matches_type(RoleCreateResponse, role, path=["response"]) |
| 34 | |
| 35 | @parametrize |
| 36 | def test_raw_response_create(self, client: OpenAI) -> None: |
| 37 | response = client.admin.organization.projects.groups.roles.with_raw_response.create( |
| 38 | group_id="group_id", |
| 39 | project_id="project_id", |
| 40 | role_id="role_id", |
| 41 | ) |
| 42 | |
| 43 | assert response.is_closed is True |
| 44 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 45 | role = response.parse() |
| 46 | assert_matches_type(RoleCreateResponse, role, path=["response"]) |
| 47 | |
| 48 | @parametrize |
| 49 | def test_streaming_response_create(self, client: OpenAI) -> None: |
| 50 | with client.admin.organization.projects.groups.roles.with_streaming_response.create( |
| 51 | group_id="group_id", |
| 52 | project_id="project_id", |
| 53 | role_id="role_id", |
| 54 | ) as response: |
| 55 | assert not response.is_closed |
| 56 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 57 | |
| 58 | role = response.parse() |
| 59 | assert_matches_type(RoleCreateResponse, role, path=["response"]) |
| 60 | |
| 61 | assert cast(Any, response.is_closed) is True |
| 62 | |
| 63 | @parametrize |
| 64 | def test_path_params_create(self, client: OpenAI) -> None: |
| 65 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 66 | client.admin.organization.projects.groups.roles.with_raw_response.create( |
| 67 | group_id="group_id", |
| 68 | project_id="", |
| 69 | role_id="role_id", |
| 70 | ) |
| 71 | |
| 72 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 73 | client.admin.organization.projects.groups.roles.with_raw_response.create( |
| 74 | group_id="", |
| 75 | project_id="project_id", |
| 76 | role_id="role_id", |
| 77 | ) |
| 78 | |
| 79 | @parametrize |
| 80 | def test_method_retrieve(self, client: OpenAI) -> None: |
| 81 | role = client.admin.organization.projects.groups.roles.retrieve( |
| 82 | role_id="role_id", |
| 83 | project_id="project_id", |
| 84 | group_id="group_id", |
| 85 | ) |
| 86 | assert_matches_type(RoleRetrieveResponse, role, path=["response"]) |
| 87 | |
| 88 | @parametrize |
| 89 | def test_raw_response_retrieve(self, client: OpenAI) -> None: |
| 90 | response = client.admin.organization.projects.groups.roles.with_raw_response.retrieve( |
| 91 | role_id="role_id", |
| 92 | project_id="project_id", |
| 93 | group_id="group_id", |
| 94 | ) |
| 95 | |
| 96 | assert response.is_closed is True |
| 97 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 98 | role = response.parse() |
| 99 | assert_matches_type(RoleRetrieveResponse, role, path=["response"]) |
| 100 | |
| 101 | @parametrize |
| 102 | def test_streaming_response_retrieve(self, client: OpenAI) -> None: |
| 103 | with client.admin.organization.projects.groups.roles.with_streaming_response.retrieve( |
| 104 | role_id="role_id", |
| 105 | project_id="project_id", |
| 106 | group_id="group_id", |
| 107 | ) as response: |
| 108 | assert not response.is_closed |
| 109 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 110 | |
| 111 | role = response.parse() |
| 112 | assert_matches_type(RoleRetrieveResponse, role, path=["response"]) |
| 113 | |
| 114 | assert cast(Any, response.is_closed) is True |
| 115 | |
| 116 | @parametrize |
| 117 | def test_path_params_retrieve(self, client: OpenAI) -> None: |
| 118 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 119 | client.admin.organization.projects.groups.roles.with_raw_response.retrieve( |
| 120 | role_id="role_id", |
| 121 | project_id="", |
| 122 | group_id="group_id", |
| 123 | ) |
| 124 | |
| 125 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 126 | client.admin.organization.projects.groups.roles.with_raw_response.retrieve( |
| 127 | role_id="role_id", |
| 128 | project_id="project_id", |
| 129 | group_id="", |
| 130 | ) |
| 131 | |
| 132 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `role_id` but received ''"): |
| 133 | client.admin.organization.projects.groups.roles.with_raw_response.retrieve( |
| 134 | role_id="", |
| 135 | project_id="project_id", |
| 136 | group_id="group_id", |
| 137 | ) |
| 138 | |
| 139 | @parametrize |
| 140 | def test_method_list(self, client: OpenAI) -> None: |
| 141 | role = client.admin.organization.projects.groups.roles.list( |
| 142 | group_id="group_id", |
| 143 | project_id="project_id", |
| 144 | ) |
| 145 | assert_matches_type(SyncNextCursorPage[RoleListResponse], role, path=["response"]) |
| 146 | |
| 147 | @parametrize |
| 148 | def test_method_list_with_all_params(self, client: OpenAI) -> None: |
| 149 | role = client.admin.organization.projects.groups.roles.list( |
| 150 | group_id="group_id", |
| 151 | project_id="project_id", |
| 152 | after="after", |
| 153 | limit=0, |
| 154 | order="asc", |
| 155 | ) |
| 156 | assert_matches_type(SyncNextCursorPage[RoleListResponse], role, path=["response"]) |
| 157 | |
| 158 | @parametrize |
| 159 | def test_raw_response_list(self, client: OpenAI) -> None: |
| 160 | response = client.admin.organization.projects.groups.roles.with_raw_response.list( |
| 161 | group_id="group_id", |
| 162 | project_id="project_id", |
| 163 | ) |
| 164 | |
| 165 | assert response.is_closed is True |
| 166 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 167 | role = response.parse() |
| 168 | assert_matches_type(SyncNextCursorPage[RoleListResponse], role, path=["response"]) |
| 169 | |
| 170 | @parametrize |
| 171 | def test_streaming_response_list(self, client: OpenAI) -> None: |
| 172 | with client.admin.organization.projects.groups.roles.with_streaming_response.list( |
| 173 | group_id="group_id", |
| 174 | project_id="project_id", |
| 175 | ) as response: |
| 176 | assert not response.is_closed |
| 177 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 178 | |
| 179 | role = response.parse() |
| 180 | assert_matches_type(SyncNextCursorPage[RoleListResponse], role, path=["response"]) |
| 181 | |
| 182 | assert cast(Any, response.is_closed) is True |
| 183 | |
| 184 | @parametrize |
| 185 | def test_path_params_list(self, client: OpenAI) -> None: |
| 186 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 187 | client.admin.organization.projects.groups.roles.with_raw_response.list( |
| 188 | group_id="group_id", |
| 189 | project_id="", |
| 190 | ) |
| 191 | |
| 192 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 193 | client.admin.organization.projects.groups.roles.with_raw_response.list( |
| 194 | group_id="", |
| 195 | project_id="project_id", |
| 196 | ) |
| 197 | |
| 198 | @parametrize |
| 199 | def test_method_delete(self, client: OpenAI) -> None: |
| 200 | role = client.admin.organization.projects.groups.roles.delete( |
| 201 | role_id="role_id", |
| 202 | project_id="project_id", |
| 203 | group_id="group_id", |
| 204 | ) |
| 205 | assert_matches_type(RoleDeleteResponse, role, path=["response"]) |
| 206 | |
| 207 | @parametrize |
| 208 | def test_raw_response_delete(self, client: OpenAI) -> None: |
| 209 | response = client.admin.organization.projects.groups.roles.with_raw_response.delete( |
| 210 | role_id="role_id", |
| 211 | project_id="project_id", |
| 212 | group_id="group_id", |
| 213 | ) |
| 214 | |
| 215 | assert response.is_closed is True |
| 216 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 217 | role = response.parse() |
| 218 | assert_matches_type(RoleDeleteResponse, role, path=["response"]) |
| 219 | |
| 220 | @parametrize |
| 221 | def test_streaming_response_delete(self, client: OpenAI) -> None: |
| 222 | with client.admin.organization.projects.groups.roles.with_streaming_response.delete( |
| 223 | role_id="role_id", |
| 224 | project_id="project_id", |
| 225 | group_id="group_id", |
| 226 | ) as response: |
| 227 | assert not response.is_closed |
| 228 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 229 | |
| 230 | role = response.parse() |
| 231 | assert_matches_type(RoleDeleteResponse, role, path=["response"]) |
| 232 | |
| 233 | assert cast(Any, response.is_closed) is True |
| 234 | |
| 235 | @parametrize |
| 236 | def test_path_params_delete(self, client: OpenAI) -> None: |
| 237 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 238 | client.admin.organization.projects.groups.roles.with_raw_response.delete( |
| 239 | role_id="role_id", |
| 240 | project_id="", |
| 241 | group_id="group_id", |
| 242 | ) |
| 243 | |
| 244 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 245 | client.admin.organization.projects.groups.roles.with_raw_response.delete( |
| 246 | role_id="role_id", |
| 247 | project_id="project_id", |
| 248 | group_id="", |
| 249 | ) |
| 250 | |
| 251 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `role_id` but received ''"): |
| 252 | client.admin.organization.projects.groups.roles.with_raw_response.delete( |
| 253 | role_id="", |
| 254 | project_id="project_id", |
| 255 | group_id="group_id", |
| 256 | ) |
| 257 | |
| 258 | |
| 259 | class TestAsyncRoles: |
| 260 | parametrize = pytest.mark.parametrize( |
| 261 | "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] |
| 262 | ) |
| 263 | |
| 264 | @parametrize |
| 265 | async def test_method_create(self, async_client: AsyncOpenAI) -> None: |
| 266 | role = await async_client.admin.organization.projects.groups.roles.create( |
| 267 | group_id="group_id", |
| 268 | project_id="project_id", |
| 269 | role_id="role_id", |
| 270 | ) |
| 271 | assert_matches_type(RoleCreateResponse, role, path=["response"]) |
| 272 | |
| 273 | @parametrize |
| 274 | async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None: |
| 275 | response = await async_client.admin.organization.projects.groups.roles.with_raw_response.create( |
| 276 | group_id="group_id", |
| 277 | project_id="project_id", |
| 278 | role_id="role_id", |
| 279 | ) |
| 280 | |
| 281 | assert response.is_closed is True |
| 282 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 283 | role = response.parse() |
| 284 | assert_matches_type(RoleCreateResponse, role, path=["response"]) |
| 285 | |
| 286 | @parametrize |
| 287 | async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None: |
| 288 | async with async_client.admin.organization.projects.groups.roles.with_streaming_response.create( |
| 289 | group_id="group_id", |
| 290 | project_id="project_id", |
| 291 | role_id="role_id", |
| 292 | ) as response: |
| 293 | assert not response.is_closed |
| 294 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 295 | |
| 296 | role = await response.parse() |
| 297 | assert_matches_type(RoleCreateResponse, role, path=["response"]) |
| 298 | |
| 299 | assert cast(Any, response.is_closed) is True |
| 300 | |
| 301 | @parametrize |
| 302 | async def test_path_params_create(self, async_client: AsyncOpenAI) -> None: |
| 303 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 304 | await async_client.admin.organization.projects.groups.roles.with_raw_response.create( |
| 305 | group_id="group_id", |
| 306 | project_id="", |
| 307 | role_id="role_id", |
| 308 | ) |
| 309 | |
| 310 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 311 | await async_client.admin.organization.projects.groups.roles.with_raw_response.create( |
| 312 | group_id="", |
| 313 | project_id="project_id", |
| 314 | role_id="role_id", |
| 315 | ) |
| 316 | |
| 317 | @parametrize |
| 318 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 319 | role = await async_client.admin.organization.projects.groups.roles.retrieve( |
| 320 | role_id="role_id", |
| 321 | project_id="project_id", |
| 322 | group_id="group_id", |
| 323 | ) |
| 324 | assert_matches_type(RoleRetrieveResponse, role, path=["response"]) |
| 325 | |
| 326 | @parametrize |
| 327 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 328 | response = await async_client.admin.organization.projects.groups.roles.with_raw_response.retrieve( |
| 329 | role_id="role_id", |
| 330 | project_id="project_id", |
| 331 | group_id="group_id", |
| 332 | ) |
| 333 | |
| 334 | assert response.is_closed is True |
| 335 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 336 | role = response.parse() |
| 337 | assert_matches_type(RoleRetrieveResponse, role, path=["response"]) |
| 338 | |
| 339 | @parametrize |
| 340 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 341 | async with async_client.admin.organization.projects.groups.roles.with_streaming_response.retrieve( |
| 342 | role_id="role_id", |
| 343 | project_id="project_id", |
| 344 | group_id="group_id", |
| 345 | ) as response: |
| 346 | assert not response.is_closed |
| 347 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 348 | |
| 349 | role = await response.parse() |
| 350 | assert_matches_type(RoleRetrieveResponse, role, path=["response"]) |
| 351 | |
| 352 | assert cast(Any, response.is_closed) is True |
| 353 | |
| 354 | @parametrize |
| 355 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 356 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 357 | await async_client.admin.organization.projects.groups.roles.with_raw_response.retrieve( |
| 358 | role_id="role_id", |
| 359 | project_id="", |
| 360 | group_id="group_id", |
| 361 | ) |
| 362 | |
| 363 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 364 | await async_client.admin.organization.projects.groups.roles.with_raw_response.retrieve( |
| 365 | role_id="role_id", |
| 366 | project_id="project_id", |
| 367 | group_id="", |
| 368 | ) |
| 369 | |
| 370 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `role_id` but received ''"): |
| 371 | await async_client.admin.organization.projects.groups.roles.with_raw_response.retrieve( |
| 372 | role_id="", |
| 373 | project_id="project_id", |
| 374 | group_id="group_id", |
| 375 | ) |
| 376 | |
| 377 | @parametrize |
| 378 | async def test_method_list(self, async_client: AsyncOpenAI) -> None: |
| 379 | role = await async_client.admin.organization.projects.groups.roles.list( |
| 380 | group_id="group_id", |
| 381 | project_id="project_id", |
| 382 | ) |
| 383 | assert_matches_type(AsyncNextCursorPage[RoleListResponse], role, path=["response"]) |
| 384 | |
| 385 | @parametrize |
| 386 | async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 387 | role = await async_client.admin.organization.projects.groups.roles.list( |
| 388 | group_id="group_id", |
| 389 | project_id="project_id", |
| 390 | after="after", |
| 391 | limit=0, |
| 392 | order="asc", |
| 393 | ) |
| 394 | assert_matches_type(AsyncNextCursorPage[RoleListResponse], role, path=["response"]) |
| 395 | |
| 396 | @parametrize |
| 397 | async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None: |
| 398 | response = await async_client.admin.organization.projects.groups.roles.with_raw_response.list( |
| 399 | group_id="group_id", |
| 400 | project_id="project_id", |
| 401 | ) |
| 402 | |
| 403 | assert response.is_closed is True |
| 404 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 405 | role = response.parse() |
| 406 | assert_matches_type(AsyncNextCursorPage[RoleListResponse], role, path=["response"]) |
| 407 | |
| 408 | @parametrize |
| 409 | async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None: |
| 410 | async with async_client.admin.organization.projects.groups.roles.with_streaming_response.list( |
| 411 | group_id="group_id", |
| 412 | project_id="project_id", |
| 413 | ) as response: |
| 414 | assert not response.is_closed |
| 415 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 416 | |
| 417 | role = await response.parse() |
| 418 | assert_matches_type(AsyncNextCursorPage[RoleListResponse], role, path=["response"]) |
| 419 | |
| 420 | assert cast(Any, response.is_closed) is True |
| 421 | |
| 422 | @parametrize |
| 423 | async def test_path_params_list(self, async_client: AsyncOpenAI) -> None: |
| 424 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 425 | await async_client.admin.organization.projects.groups.roles.with_raw_response.list( |
| 426 | group_id="group_id", |
| 427 | project_id="", |
| 428 | ) |
| 429 | |
| 430 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 431 | await async_client.admin.organization.projects.groups.roles.with_raw_response.list( |
| 432 | group_id="", |
| 433 | project_id="project_id", |
| 434 | ) |
| 435 | |
| 436 | @parametrize |
| 437 | async def test_method_delete(self, async_client: AsyncOpenAI) -> None: |
| 438 | role = await async_client.admin.organization.projects.groups.roles.delete( |
| 439 | role_id="role_id", |
| 440 | project_id="project_id", |
| 441 | group_id="group_id", |
| 442 | ) |
| 443 | assert_matches_type(RoleDeleteResponse, role, path=["response"]) |
| 444 | |
| 445 | @parametrize |
| 446 | async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None: |
| 447 | response = await async_client.admin.organization.projects.groups.roles.with_raw_response.delete( |
| 448 | role_id="role_id", |
| 449 | project_id="project_id", |
| 450 | group_id="group_id", |
| 451 | ) |
| 452 | |
| 453 | assert response.is_closed is True |
| 454 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 455 | role = response.parse() |
| 456 | assert_matches_type(RoleDeleteResponse, role, path=["response"]) |
| 457 | |
| 458 | @parametrize |
| 459 | async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None: |
| 460 | async with async_client.admin.organization.projects.groups.roles.with_streaming_response.delete( |
| 461 | role_id="role_id", |
| 462 | project_id="project_id", |
| 463 | group_id="group_id", |
| 464 | ) as response: |
| 465 | assert not response.is_closed |
| 466 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 467 | |
| 468 | role = await response.parse() |
| 469 | assert_matches_type(RoleDeleteResponse, role, path=["response"]) |
| 470 | |
| 471 | assert cast(Any, response.is_closed) is True |
| 472 | |
| 473 | @parametrize |
| 474 | async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None: |
| 475 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 476 | await async_client.admin.organization.projects.groups.roles.with_raw_response.delete( |
| 477 | role_id="role_id", |
| 478 | project_id="", |
| 479 | group_id="group_id", |
| 480 | ) |
| 481 | |
| 482 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 483 | await async_client.admin.organization.projects.groups.roles.with_raw_response.delete( |
| 484 | role_id="role_id", |
| 485 | project_id="project_id", |
| 486 | group_id="", |
| 487 | ) |
| 488 | |
| 489 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `role_id` but received ''"): |
| 490 | await async_client.admin.organization.projects.groups.roles.with_raw_response.delete( |
| 491 | role_id="", |
| 492 | project_id="project_id", |
| 493 | group_id="group_id", |
| 494 | ) |
| 495 | |