openai/openai-python
Publicmirrored fromhttps://github.com/openai/openai-pythonAvailable
tests/api_resources/admin/organization/projects/test_model_permissions.py
271lines · 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.types.admin.organization.projects import ( |
| 13 | ProjectModelPermissions, |
| 14 | ProjectModelPermissionsDeleted, |
| 15 | ) |
| 16 | |
| 17 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 18 | |
| 19 | |
| 20 | class TestModelPermissions: |
| 21 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 22 | |
| 23 | @parametrize |
| 24 | def test_method_retrieve(self, client: OpenAI) -> None: |
| 25 | model_permission = client.admin.organization.projects.model_permissions.retrieve( |
| 26 | "project_id", |
| 27 | ) |
| 28 | assert_matches_type(ProjectModelPermissions, model_permission, path=["response"]) |
| 29 | |
| 30 | @parametrize |
| 31 | def test_raw_response_retrieve(self, client: OpenAI) -> None: |
| 32 | response = client.admin.organization.projects.model_permissions.with_raw_response.retrieve( |
| 33 | "project_id", |
| 34 | ) |
| 35 | |
| 36 | assert response.is_closed is True |
| 37 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 38 | model_permission = response.parse() |
| 39 | assert_matches_type(ProjectModelPermissions, model_permission, path=["response"]) |
| 40 | |
| 41 | @parametrize |
| 42 | def test_streaming_response_retrieve(self, client: OpenAI) -> None: |
| 43 | with client.admin.organization.projects.model_permissions.with_streaming_response.retrieve( |
| 44 | "project_id", |
| 45 | ) as response: |
| 46 | assert not response.is_closed |
| 47 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 48 | |
| 49 | model_permission = response.parse() |
| 50 | assert_matches_type(ProjectModelPermissions, model_permission, path=["response"]) |
| 51 | |
| 52 | assert cast(Any, response.is_closed) is True |
| 53 | |
| 54 | @parametrize |
| 55 | def test_path_params_retrieve(self, client: OpenAI) -> None: |
| 56 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 57 | client.admin.organization.projects.model_permissions.with_raw_response.retrieve( |
| 58 | "", |
| 59 | ) |
| 60 | |
| 61 | @parametrize |
| 62 | def test_method_update(self, client: OpenAI) -> None: |
| 63 | model_permission = client.admin.organization.projects.model_permissions.update( |
| 64 | project_id="project_id", |
| 65 | mode="allow_list", |
| 66 | model_ids=["string"], |
| 67 | ) |
| 68 | assert_matches_type(ProjectModelPermissions, model_permission, path=["response"]) |
| 69 | |
| 70 | @parametrize |
| 71 | def test_raw_response_update(self, client: OpenAI) -> None: |
| 72 | response = client.admin.organization.projects.model_permissions.with_raw_response.update( |
| 73 | project_id="project_id", |
| 74 | mode="allow_list", |
| 75 | model_ids=["string"], |
| 76 | ) |
| 77 | |
| 78 | assert response.is_closed is True |
| 79 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 80 | model_permission = response.parse() |
| 81 | assert_matches_type(ProjectModelPermissions, model_permission, path=["response"]) |
| 82 | |
| 83 | @parametrize |
| 84 | def test_streaming_response_update(self, client: OpenAI) -> None: |
| 85 | with client.admin.organization.projects.model_permissions.with_streaming_response.update( |
| 86 | project_id="project_id", |
| 87 | mode="allow_list", |
| 88 | model_ids=["string"], |
| 89 | ) as response: |
| 90 | assert not response.is_closed |
| 91 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 92 | |
| 93 | model_permission = response.parse() |
| 94 | assert_matches_type(ProjectModelPermissions, model_permission, path=["response"]) |
| 95 | |
| 96 | assert cast(Any, response.is_closed) is True |
| 97 | |
| 98 | @parametrize |
| 99 | def test_path_params_update(self, client: OpenAI) -> None: |
| 100 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 101 | client.admin.organization.projects.model_permissions.with_raw_response.update( |
| 102 | project_id="", |
| 103 | mode="allow_list", |
| 104 | model_ids=["string"], |
| 105 | ) |
| 106 | |
| 107 | @parametrize |
| 108 | def test_method_delete(self, client: OpenAI) -> None: |
| 109 | model_permission = client.admin.organization.projects.model_permissions.delete( |
| 110 | "project_id", |
| 111 | ) |
| 112 | assert_matches_type(ProjectModelPermissionsDeleted, model_permission, path=["response"]) |
| 113 | |
| 114 | @parametrize |
| 115 | def test_raw_response_delete(self, client: OpenAI) -> None: |
| 116 | response = client.admin.organization.projects.model_permissions.with_raw_response.delete( |
| 117 | "project_id", |
| 118 | ) |
| 119 | |
| 120 | assert response.is_closed is True |
| 121 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 122 | model_permission = response.parse() |
| 123 | assert_matches_type(ProjectModelPermissionsDeleted, model_permission, path=["response"]) |
| 124 | |
| 125 | @parametrize |
| 126 | def test_streaming_response_delete(self, client: OpenAI) -> None: |
| 127 | with client.admin.organization.projects.model_permissions.with_streaming_response.delete( |
| 128 | "project_id", |
| 129 | ) as response: |
| 130 | assert not response.is_closed |
| 131 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 132 | |
| 133 | model_permission = response.parse() |
| 134 | assert_matches_type(ProjectModelPermissionsDeleted, model_permission, path=["response"]) |
| 135 | |
| 136 | assert cast(Any, response.is_closed) is True |
| 137 | |
| 138 | @parametrize |
| 139 | def test_path_params_delete(self, client: OpenAI) -> None: |
| 140 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 141 | client.admin.organization.projects.model_permissions.with_raw_response.delete( |
| 142 | "", |
| 143 | ) |
| 144 | |
| 145 | |
| 146 | class TestAsyncModelPermissions: |
| 147 | parametrize = pytest.mark.parametrize( |
| 148 | "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] |
| 149 | ) |
| 150 | |
| 151 | @parametrize |
| 152 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 153 | model_permission = await async_client.admin.organization.projects.model_permissions.retrieve( |
| 154 | "project_id", |
| 155 | ) |
| 156 | assert_matches_type(ProjectModelPermissions, model_permission, path=["response"]) |
| 157 | |
| 158 | @parametrize |
| 159 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 160 | response = await async_client.admin.organization.projects.model_permissions.with_raw_response.retrieve( |
| 161 | "project_id", |
| 162 | ) |
| 163 | |
| 164 | assert response.is_closed is True |
| 165 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 166 | model_permission = response.parse() |
| 167 | assert_matches_type(ProjectModelPermissions, model_permission, path=["response"]) |
| 168 | |
| 169 | @parametrize |
| 170 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 171 | async with async_client.admin.organization.projects.model_permissions.with_streaming_response.retrieve( |
| 172 | "project_id", |
| 173 | ) as response: |
| 174 | assert not response.is_closed |
| 175 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 176 | |
| 177 | model_permission = await response.parse() |
| 178 | assert_matches_type(ProjectModelPermissions, model_permission, path=["response"]) |
| 179 | |
| 180 | assert cast(Any, response.is_closed) is True |
| 181 | |
| 182 | @parametrize |
| 183 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 184 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 185 | await async_client.admin.organization.projects.model_permissions.with_raw_response.retrieve( |
| 186 | "", |
| 187 | ) |
| 188 | |
| 189 | @parametrize |
| 190 | async def test_method_update(self, async_client: AsyncOpenAI) -> None: |
| 191 | model_permission = await async_client.admin.organization.projects.model_permissions.update( |
| 192 | project_id="project_id", |
| 193 | mode="allow_list", |
| 194 | model_ids=["string"], |
| 195 | ) |
| 196 | assert_matches_type(ProjectModelPermissions, model_permission, path=["response"]) |
| 197 | |
| 198 | @parametrize |
| 199 | async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None: |
| 200 | response = await async_client.admin.organization.projects.model_permissions.with_raw_response.update( |
| 201 | project_id="project_id", |
| 202 | mode="allow_list", |
| 203 | model_ids=["string"], |
| 204 | ) |
| 205 | |
| 206 | assert response.is_closed is True |
| 207 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 208 | model_permission = response.parse() |
| 209 | assert_matches_type(ProjectModelPermissions, model_permission, path=["response"]) |
| 210 | |
| 211 | @parametrize |
| 212 | async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None: |
| 213 | async with async_client.admin.organization.projects.model_permissions.with_streaming_response.update( |
| 214 | project_id="project_id", |
| 215 | mode="allow_list", |
| 216 | model_ids=["string"], |
| 217 | ) as response: |
| 218 | assert not response.is_closed |
| 219 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 220 | |
| 221 | model_permission = await response.parse() |
| 222 | assert_matches_type(ProjectModelPermissions, model_permission, path=["response"]) |
| 223 | |
| 224 | assert cast(Any, response.is_closed) is True |
| 225 | |
| 226 | @parametrize |
| 227 | async def test_path_params_update(self, async_client: AsyncOpenAI) -> None: |
| 228 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 229 | await async_client.admin.organization.projects.model_permissions.with_raw_response.update( |
| 230 | project_id="", |
| 231 | mode="allow_list", |
| 232 | model_ids=["string"], |
| 233 | ) |
| 234 | |
| 235 | @parametrize |
| 236 | async def test_method_delete(self, async_client: AsyncOpenAI) -> None: |
| 237 | model_permission = await async_client.admin.organization.projects.model_permissions.delete( |
| 238 | "project_id", |
| 239 | ) |
| 240 | assert_matches_type(ProjectModelPermissionsDeleted, model_permission, path=["response"]) |
| 241 | |
| 242 | @parametrize |
| 243 | async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None: |
| 244 | response = await async_client.admin.organization.projects.model_permissions.with_raw_response.delete( |
| 245 | "project_id", |
| 246 | ) |
| 247 | |
| 248 | assert response.is_closed is True |
| 249 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 250 | model_permission = response.parse() |
| 251 | assert_matches_type(ProjectModelPermissionsDeleted, model_permission, path=["response"]) |
| 252 | |
| 253 | @parametrize |
| 254 | async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None: |
| 255 | async with async_client.admin.organization.projects.model_permissions.with_streaming_response.delete( |
| 256 | "project_id", |
| 257 | ) as response: |
| 258 | assert not response.is_closed |
| 259 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 260 | |
| 261 | model_permission = await response.parse() |
| 262 | assert_matches_type(ProjectModelPermissionsDeleted, model_permission, path=["response"]) |
| 263 | |
| 264 | assert cast(Any, response.is_closed) is True |
| 265 | |
| 266 | @parametrize |
| 267 | async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None: |
| 268 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"): |
| 269 | await async_client.admin.organization.projects.model_permissions.with_raw_response.delete( |
| 270 | "", |
| 271 | ) |
| 272 | |