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