openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.2.4

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/messages/test_files.py

128lines · modecode

1# File generated from our OpenAPI spec by Stainless.
2
3from __future__ import annotations
4
5import os
6
7import pytest
8
9from openai import OpenAI, AsyncOpenAI
10from tests.utils import assert_matches_type
11from openai._client import OpenAI, AsyncOpenAI
12from openai.pagination import SyncCursorPage, AsyncCursorPage
13from openai.types.beta.threads.messages import MessageFile
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16api_key = "My API Key"
17
18
19class TestFiles:
20 strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
21 loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
22 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
23
24 @parametrize
25 def test_method_retrieve(self, client: OpenAI) -> None:
26 file = client.beta.threads.messages.files.retrieve(
27 "file-AF1WoRqd3aJAHsqc9NY7iL8F",
28 thread_id="thread_AF1WoRqd3aJAHsqc9NY7iL8F",
29 message_id="msg_AF1WoRqd3aJAHsqc9NY7iL8F",
30 )
31 assert_matches_type(MessageFile, file, path=["response"])
32
33 @parametrize
34 def test_raw_response_retrieve(self, client: OpenAI) -> None:
35 response = client.beta.threads.messages.files.with_raw_response.retrieve(
36 "file-AF1WoRqd3aJAHsqc9NY7iL8F",
37 thread_id="thread_AF1WoRqd3aJAHsqc9NY7iL8F",
38 message_id="msg_AF1WoRqd3aJAHsqc9NY7iL8F",
39 )
40 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
41 file = response.parse()
42 assert_matches_type(MessageFile, file, path=["response"])
43
44 @parametrize
45 def test_method_list(self, client: OpenAI) -> None:
46 file = client.beta.threads.messages.files.list(
47 "string",
48 thread_id="string",
49 )
50 assert_matches_type(SyncCursorPage[MessageFile], file, path=["response"])
51
52 @parametrize
53 def test_method_list_with_all_params(self, client: OpenAI) -> None:
54 file = client.beta.threads.messages.files.list(
55 "string",
56 thread_id="string",
57 after="string",
58 before="string",
59 limit=0,
60 order="asc",
61 )
62 assert_matches_type(SyncCursorPage[MessageFile], file, path=["response"])
63
64 @parametrize
65 def test_raw_response_list(self, client: OpenAI) -> None:
66 response = client.beta.threads.messages.files.with_raw_response.list(
67 "string",
68 thread_id="string",
69 )
70 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
71 file = response.parse()
72 assert_matches_type(SyncCursorPage[MessageFile], file, path=["response"])
73
74
75class TestAsyncFiles:
76 strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
77 loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
78 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
79
80 @parametrize
81 async def test_method_retrieve(self, client: AsyncOpenAI) -> None:
82 file = await client.beta.threads.messages.files.retrieve(
83 "file-AF1WoRqd3aJAHsqc9NY7iL8F",
84 thread_id="thread_AF1WoRqd3aJAHsqc9NY7iL8F",
85 message_id="msg_AF1WoRqd3aJAHsqc9NY7iL8F",
86 )
87 assert_matches_type(MessageFile, file, path=["response"])
88
89 @parametrize
90 async def test_raw_response_retrieve(self, client: AsyncOpenAI) -> None:
91 response = await client.beta.threads.messages.files.with_raw_response.retrieve(
92 "file-AF1WoRqd3aJAHsqc9NY7iL8F",
93 thread_id="thread_AF1WoRqd3aJAHsqc9NY7iL8F",
94 message_id="msg_AF1WoRqd3aJAHsqc9NY7iL8F",
95 )
96 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
97 file = response.parse()
98 assert_matches_type(MessageFile, file, path=["response"])
99
100 @parametrize
101 async def test_method_list(self, client: AsyncOpenAI) -> None:
102 file = await client.beta.threads.messages.files.list(
103 "string",
104 thread_id="string",
105 )
106 assert_matches_type(AsyncCursorPage[MessageFile], file, path=["response"])
107
108 @parametrize
109 async def test_method_list_with_all_params(self, client: AsyncOpenAI) -> None:
110 file = await client.beta.threads.messages.files.list(
111 "string",
112 thread_id="string",
113 after="string",
114 before="string",
115 limit=0,
116 order="asc",
117 )
118 assert_matches_type(AsyncCursorPage[MessageFile], file, path=["response"])
119
120 @parametrize
121 async def test_raw_response_list(self, client: AsyncOpenAI) -> None:
122 response = await client.beta.threads.messages.files.with_raw_response.list(
123 "string",
124 thread_id="string",
125 )
126 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
127 file = response.parse()
128 assert_matches_type(AsyncCursorPage[MessageFile], file, path=["response"])
129