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