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