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