-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_files.py
78 lines (56 loc) · 2.12 KB
/
test_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import openai
import openai_responses
from openai_responses import OpenAIMock
@openai_responses.mock()
def test_create_file(openai_mock: OpenAIMock):
client = openai.Client(api_key="sk-fake123")
file = client.files.create(
file=open("examples/example.json", "rb"),
purpose="fine-tune",
)
assert file.filename == "example.json"
assert openai_mock.files.create.route.call_count == 1
@openai_responses.mock()
def test_list_files(openai_mock: OpenAIMock):
client = openai.Client(api_key="sk-fake123")
for _ in range(10):
client.files.create(
file=open("examples/example.json", "rb"),
purpose="fine-tune",
)
files = client.files.list()
assert len(files.data) == 10
assert openai_mock.files.create.route.call_count == 10
assert openai_mock.files.list.route.call_count == 1
@openai_responses.mock()
def test_retrieve_file(openai_mock: OpenAIMock):
client = openai.Client(api_key="sk-fake123")
file = client.files.create(
file=open("examples/example.json", "rb"),
purpose="fine-tune",
)
found = client.files.retrieve(file.id)
assert found.id == file.id
assert file.filename == "example.json"
assert found.filename == file.filename
assert openai_mock.files.create.route.call_count == 1
assert openai_mock.files.retrieve.route.call_count == 1
@openai_responses.mock()
def test_delete_file(openai_mock: OpenAIMock):
client = openai.Client(api_key="sk-fake123")
file = client.files.create(
file=open("examples/example.json", "rb"),
purpose="fine-tune",
)
assert client.files.delete(file.id).deleted
assert openai_mock.files.create.route.call_count == 1
assert openai_mock.files.delete.route.call_count == 1
@openai_responses.mock()
def test_retrieve_file_content(openai_mock: OpenAIMock):
client = openai.Client(api_key="sk-fake123")
file = client.files.create(
file=open("examples/example.json", "rb"),
purpose="fine-tune",
)
res = client.files.content(file.id)
assert res.content == b'{\n "foo": "bar",\n "fizz": "buzz"\n}'