openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
codex/bedrock-thin-provider-rewrite

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api_resources/admin/organization/test_audit_logs.py

115lines · modecode

1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5import os
6from typing import Any, cast
7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
12from openai.pagination import SyncConversationCursorPage, AsyncConversationCursorPage
13from openai.types.admin.organization import AuditLogListResponse
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16
17
18class TestAuditLogs:
19 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
20
21 @parametrize
22 def test_method_list(self, client: OpenAI) -> None:
23 audit_log = client.admin.organization.audit_logs.list()
24 assert_matches_type(SyncConversationCursorPage[AuditLogListResponse], audit_log, path=["response"])
25
26 @parametrize
27 def test_method_list_with_all_params(self, client: OpenAI) -> None:
28 audit_log = client.admin.organization.audit_logs.list(
29 actor_emails=["string"],
30 actor_ids=["string"],
31 after="after",
32 before="before",
33 effective_at={
34 "gt": 0,
35 "gte": 0,
36 "lt": 0,
37 "lte": 0,
38 },
39 event_types=["api_key.created"],
40 limit=0,
41 project_ids=["string"],
42 resource_ids=["string"],
43 )
44 assert_matches_type(SyncConversationCursorPage[AuditLogListResponse], audit_log, path=["response"])
45
46 @parametrize
47 def test_raw_response_list(self, client: OpenAI) -> None:
48 response = client.admin.organization.audit_logs.with_raw_response.list()
49
50 assert response.is_closed is True
51 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
52 audit_log = response.parse()
53 assert_matches_type(SyncConversationCursorPage[AuditLogListResponse], audit_log, path=["response"])
54
55 @parametrize
56 def test_streaming_response_list(self, client: OpenAI) -> None:
57 with client.admin.organization.audit_logs.with_streaming_response.list() as response:
58 assert not response.is_closed
59 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
60
61 audit_log = response.parse()
62 assert_matches_type(SyncConversationCursorPage[AuditLogListResponse], audit_log, path=["response"])
63
64 assert cast(Any, response.is_closed) is True
65
66
67class TestAsyncAuditLogs:
68 parametrize = pytest.mark.parametrize(
69 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
70 )
71
72 @parametrize
73 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
74 audit_log = await async_client.admin.organization.audit_logs.list()
75 assert_matches_type(AsyncConversationCursorPage[AuditLogListResponse], audit_log, path=["response"])
76
77 @parametrize
78 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
79 audit_log = await async_client.admin.organization.audit_logs.list(
80 actor_emails=["string"],
81 actor_ids=["string"],
82 after="after",
83 before="before",
84 effective_at={
85 "gt": 0,
86 "gte": 0,
87 "lt": 0,
88 "lte": 0,
89 },
90 event_types=["api_key.created"],
91 limit=0,
92 project_ids=["string"],
93 resource_ids=["string"],
94 )
95 assert_matches_type(AsyncConversationCursorPage[AuditLogListResponse], audit_log, path=["response"])
96
97 @parametrize
98 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
99 response = await async_client.admin.organization.audit_logs.with_raw_response.list()
100
101 assert response.is_closed is True
102 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
103 audit_log = response.parse()
104 assert_matches_type(AsyncConversationCursorPage[AuditLogListResponse], audit_log, path=["response"])
105
106 @parametrize
107 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
108 async with async_client.admin.organization.audit_logs.with_streaming_response.list() as response:
109 assert not response.is_closed
110 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
111
112 audit_log = await response.parse()
113 assert_matches_type(AsyncConversationCursorPage[AuditLogListResponse], audit_log, path=["response"])
114
115 assert cast(Any, response.is_closed) is True
116