openai/openai-python
Publicmirrored fromhttps://github.com/openai/openai-pythonAvailable
tests/api_resources/admin/organization/projects/test_groups.py
312lines · 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 import ( |
| 14 | ProjectGroup, |
| 15 | GroupDeleteResponse, |
| 16 | ) |
| 17 | |
| 18 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 19 | |
| 20 | |
| 21 | class TestGroups: |
| 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 | group = client.admin.organization.projects.groups.create( |
| 27 | project_id="project_id", |
| 28 | group_id="group_id", |
| 29 | role="role", |
| 30 | ) |
| 31 | assert_matches_type(ProjectGroup, group, path=["response"]) |
| 32 | |
| 33 | @parametrize |
| 34 | def test_raw_response_create(self, client: OpenAI) -> None: |
| 35 | response = client.admin.organization.projects.groups.with_raw_response.create( |
| 36 | project_id="project_id", |
| 37 | group_id="group_id", |
| 38 | role="role", |
| 39 | ) |
| 40 | |
| 41 | assert response.is_closed is True |
| 42 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 43 | group = response.parse() |
| 44 | assert_matches_type(ProjectGroup, group, path=["response"]) |
| 45 | |
| 46 | @parametrize |
| 47 | def test_streaming_response_create(self, client: OpenAI) -> None: |
| 48 | with client.admin.organization.projects.groups.with_streaming_response.create( |
| 49 | project_id="project_id", |
| 50 | group_id="group_id", |
| 51 | role="role", |
| 52 | ) as response: |
| 53 | assert not response.is_closed |
| 54 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 55 | |
| 56 | group = response.parse() |
| 57 | assert_matches_type(ProjectGroup, group, path=["response"]) |
| 58 | |
| 59 | assert cast(Any, response.is_closed) is True |
| 60 | |
| 61 | @parametrize |
| 62 | def test_path_params_create(self, client: OpenAI) -> None: |
| 63 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 64 | client.admin.organization.projects.groups.with_raw_response.create( |
| 65 | project_id="", |
| 66 | group_id="group_id", |
| 67 | role="role", |
| 68 | ) |
| 69 | |
| 70 | @parametrize |
| 71 | def test_method_list(self, client: OpenAI) -> None: |
| 72 | group = client.admin.organization.projects.groups.list( |
| 73 | project_id="project_id", |
| 74 | ) |
| 75 | assert_matches_type(SyncNextCursorPage[ProjectGroup], group, path=["response"]) |
| 76 | |
| 77 | @parametrize |
| 78 | def test_method_list_with_all_params(self, client: OpenAI) -> None: |
| 79 | group = client.admin.organization.projects.groups.list( |
| 80 | project_id="project_id", |
| 81 | after="after", |
| 82 | limit=0, |
| 83 | order="asc", |
| 84 | ) |
| 85 | assert_matches_type(SyncNextCursorPage[ProjectGroup], group, path=["response"]) |
| 86 | |
| 87 | @parametrize |
| 88 | def test_raw_response_list(self, client: OpenAI) -> None: |
| 89 | response = client.admin.organization.projects.groups.with_raw_response.list( |
| 90 | project_id="project_id", |
| 91 | ) |
| 92 | |
| 93 | assert response.is_closed is True |
| 94 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 95 | group = response.parse() |
| 96 | assert_matches_type(SyncNextCursorPage[ProjectGroup], group, path=["response"]) |
| 97 | |
| 98 | @parametrize |
| 99 | def test_streaming_response_list(self, client: OpenAI) -> None: |
| 100 | with client.admin.organization.projects.groups.with_streaming_response.list( |
| 101 | project_id="project_id", |
| 102 | ) as response: |
| 103 | assert not response.is_closed |
| 104 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 105 | |
| 106 | group = response.parse() |
| 107 | assert_matches_type(SyncNextCursorPage[ProjectGroup], group, path=["response"]) |
| 108 | |
| 109 | assert cast(Any, response.is_closed) is True |
| 110 | |
| 111 | @parametrize |
| 112 | def test_path_params_list(self, client: OpenAI) -> None: |
| 113 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 114 | client.admin.organization.projects.groups.with_raw_response.list( |
| 115 | project_id="", |
| 116 | ) |
| 117 | |
| 118 | @parametrize |
| 119 | def test_method_delete(self, client: OpenAI) -> None: |
| 120 | group = client.admin.organization.projects.groups.delete( |
| 121 | group_id="group_id", |
| 122 | project_id="project_id", |
| 123 | ) |
| 124 | assert_matches_type(GroupDeleteResponse, group, path=["response"]) |
| 125 | |
| 126 | @parametrize |
| 127 | def test_raw_response_delete(self, client: OpenAI) -> None: |
| 128 | response = client.admin.organization.projects.groups.with_raw_response.delete( |
| 129 | group_id="group_id", |
| 130 | project_id="project_id", |
| 131 | ) |
| 132 | |
| 133 | assert response.is_closed is True |
| 134 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 135 | group = response.parse() |
| 136 | assert_matches_type(GroupDeleteResponse, group, path=["response"]) |
| 137 | |
| 138 | @parametrize |
| 139 | def test_streaming_response_delete(self, client: OpenAI) -> None: |
| 140 | with client.admin.organization.projects.groups.with_streaming_response.delete( |
| 141 | group_id="group_id", |
| 142 | project_id="project_id", |
| 143 | ) as response: |
| 144 | assert not response.is_closed |
| 145 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 146 | |
| 147 | group = response.parse() |
| 148 | assert_matches_type(GroupDeleteResponse, group, path=["response"]) |
| 149 | |
| 150 | assert cast(Any, response.is_closed) is True |
| 151 | |
| 152 | @parametrize |
| 153 | def test_path_params_delete(self, client: OpenAI) -> None: |
| 154 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 155 | client.admin.organization.projects.groups.with_raw_response.delete( |
| 156 | group_id="group_id", |
| 157 | project_id="", |
| 158 | ) |
| 159 | |
| 160 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 161 | client.admin.organization.projects.groups.with_raw_response.delete( |
| 162 | group_id="", |
| 163 | project_id="project_id", |
| 164 | ) |
| 165 | |
| 166 | |
| 167 | class TestAsyncGroups: |
| 168 | parametrize = pytest.mark.parametrize( |
| 169 | "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] |
| 170 | ) |
| 171 | |
| 172 | @parametrize |
| 173 | async def test_method_create(self, async_client: AsyncOpenAI) -> None: |
| 174 | group = await async_client.admin.organization.projects.groups.create( |
| 175 | project_id="project_id", |
| 176 | group_id="group_id", |
| 177 | role="role", |
| 178 | ) |
| 179 | assert_matches_type(ProjectGroup, group, path=["response"]) |
| 180 | |
| 181 | @parametrize |
| 182 | async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None: |
| 183 | response = await async_client.admin.organization.projects.groups.with_raw_response.create( |
| 184 | project_id="project_id", |
| 185 | group_id="group_id", |
| 186 | role="role", |
| 187 | ) |
| 188 | |
| 189 | assert response.is_closed is True |
| 190 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 191 | group = response.parse() |
| 192 | assert_matches_type(ProjectGroup, group, path=["response"]) |
| 193 | |
| 194 | @parametrize |
| 195 | async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None: |
| 196 | async with async_client.admin.organization.projects.groups.with_streaming_response.create( |
| 197 | project_id="project_id", |
| 198 | group_id="group_id", |
| 199 | role="role", |
| 200 | ) as response: |
| 201 | assert not response.is_closed |
| 202 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 203 | |
| 204 | group = await response.parse() |
| 205 | assert_matches_type(ProjectGroup, group, path=["response"]) |
| 206 | |
| 207 | assert cast(Any, response.is_closed) is True |
| 208 | |
| 209 | @parametrize |
| 210 | async def test_path_params_create(self, async_client: AsyncOpenAI) -> None: |
| 211 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 212 | await async_client.admin.organization.projects.groups.with_raw_response.create( |
| 213 | project_id="", |
| 214 | group_id="group_id", |
| 215 | role="role", |
| 216 | ) |
| 217 | |
| 218 | @parametrize |
| 219 | async def test_method_list(self, async_client: AsyncOpenAI) -> None: |
| 220 | group = await async_client.admin.organization.projects.groups.list( |
| 221 | project_id="project_id", |
| 222 | ) |
| 223 | assert_matches_type(AsyncNextCursorPage[ProjectGroup], group, path=["response"]) |
| 224 | |
| 225 | @parametrize |
| 226 | async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 227 | group = await async_client.admin.organization.projects.groups.list( |
| 228 | project_id="project_id", |
| 229 | after="after", |
| 230 | limit=0, |
| 231 | order="asc", |
| 232 | ) |
| 233 | assert_matches_type(AsyncNextCursorPage[ProjectGroup], group, path=["response"]) |
| 234 | |
| 235 | @parametrize |
| 236 | async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None: |
| 237 | response = await async_client.admin.organization.projects.groups.with_raw_response.list( |
| 238 | project_id="project_id", |
| 239 | ) |
| 240 | |
| 241 | assert response.is_closed is True |
| 242 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 243 | group = response.parse() |
| 244 | assert_matches_type(AsyncNextCursorPage[ProjectGroup], group, path=["response"]) |
| 245 | |
| 246 | @parametrize |
| 247 | async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None: |
| 248 | async with async_client.admin.organization.projects.groups.with_streaming_response.list( |
| 249 | project_id="project_id", |
| 250 | ) as response: |
| 251 | assert not response.is_closed |
| 252 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 253 | |
| 254 | group = await response.parse() |
| 255 | assert_matches_type(AsyncNextCursorPage[ProjectGroup], group, path=["response"]) |
| 256 | |
| 257 | assert cast(Any, response.is_closed) is True |
| 258 | |
| 259 | @parametrize |
| 260 | async def test_path_params_list(self, async_client: AsyncOpenAI) -> None: |
| 261 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 262 | await async_client.admin.organization.projects.groups.with_raw_response.list( |
| 263 | project_id="", |
| 264 | ) |
| 265 | |
| 266 | @parametrize |
| 267 | async def test_method_delete(self, async_client: AsyncOpenAI) -> None: |
| 268 | group = await async_client.admin.organization.projects.groups.delete( |
| 269 | group_id="group_id", |
| 270 | project_id="project_id", |
| 271 | ) |
| 272 | assert_matches_type(GroupDeleteResponse, group, path=["response"]) |
| 273 | |
| 274 | @parametrize |
| 275 | async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None: |
| 276 | response = await async_client.admin.organization.projects.groups.with_raw_response.delete( |
| 277 | group_id="group_id", |
| 278 | project_id="project_id", |
| 279 | ) |
| 280 | |
| 281 | assert response.is_closed is True |
| 282 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 283 | group = response.parse() |
| 284 | assert_matches_type(GroupDeleteResponse, group, path=["response"]) |
| 285 | |
| 286 | @parametrize |
| 287 | async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None: |
| 288 | async with async_client.admin.organization.projects.groups.with_streaming_response.delete( |
| 289 | group_id="group_id", |
| 290 | project_id="project_id", |
| 291 | ) as response: |
| 292 | assert not response.is_closed |
| 293 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 294 | |
| 295 | group = await response.parse() |
| 296 | assert_matches_type(GroupDeleteResponse, group, path=["response"]) |
| 297 | |
| 298 | assert cast(Any, response.is_closed) is True |
| 299 | |
| 300 | @parametrize |
| 301 | async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None: |
| 302 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 303 | await async_client.admin.organization.projects.groups.with_raw_response.delete( |
| 304 | group_id="group_id", |
| 305 | project_id="", |
| 306 | ) |
| 307 | |
| 308 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"): |
| 309 | await async_client.admin.organization.projects.groups.with_raw_response.delete( |
| 310 | group_id="", |
| 311 | project_id="project_id", |
| 312 | ) |
| 313 | |