Skip to content

Commit 2493daa

Browse files
committed
test: fix testcase
1 parent 54c2ac4 commit 2493daa

File tree

9 files changed

+71
-82
lines changed

9 files changed

+71
-82
lines changed

test/config.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from dotenv import load_dotenv
3+
import taskingai
34

45
load_dotenv()
56

@@ -14,6 +15,14 @@ class Config:
1415
if not chat_completion_model_id:
1516
raise ValueError("chat_completion_model_id is not defined")
1617

17-
sleep_time = 1
18+
taskingai_host = os.environ.get("TASKINGAI_HOST")
19+
if not taskingai_host:
20+
raise ValueError("taskingai_host is not defined")
21+
22+
taskingai_apikey = os.environ.get("TASKINGAI_API_KEY")
23+
if not taskingai_apikey:
24+
raise ValueError("taskingai_apikey is not defined")
1825

26+
taskingai.init(api_key=taskingai_apikey, host=taskingai_host)
1927

28+
sleep_time = 1

test/run_test.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ export PYTHONPATH="${PYTHONPATH}:${parent_dir}"
44

55
echo "Starting tests..."
66

7-
pytest -m test_sync -q --tb=no
8-
pytest -m test_async -q --tb=no
7+
pytest ./test/testcase/test_sync
8+
sleep 5
9+
pytest ./test/testcase/test_async
910

1011
echo "Tests completed."
1112

test/testcase/test_async/test_async_assistant.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,18 @@ async def test_a_delete_assistant(self):
113113

114114
assistants = await a_list_assistants(limit=100)
115115
old_nums = len(assistants)
116-
for i, v in enumerate(assistants):
116+
for index, v in enumerate(assistants):
117117
assistant_id = v.assistant_id
118118

119119
# Delete an assistant.
120120

121121
await a_delete_assistant(assistant_id=str(assistant_id))
122122

123123
# List assistants.
124-
125-
new_assistants = await a_list_assistants()
126-
assistant_ids = [j.assistant_id for j in new_assistants]
127-
pytest.assume(assistant_id not in assistant_ids)
128-
new_nums = len(new_assistants)
129-
pytest.assume(new_nums == old_nums - 1 - i)
124+
if index == old_nums - 1:
125+
new_assistants = await a_list_assistants()
126+
new_nums = len(new_assistants)
127+
pytest.assume(new_nums == 0)
130128

131129

132130
@pytest.mark.test_async
@@ -210,12 +208,10 @@ async def test_a_delete_chat(self):
210208
await a_delete_chat(assistant_id=self.assistant_id, chat_id=str(chat_id))
211209

212210
# List chats.
213-
214-
new_chats = await a_list_chats(assistant_id=self.assistant_id)
215-
chat_ids = [i.chat_id for i in new_chats]
216-
pytest.assume(chat_id not in chat_ids)
217-
new_nums = len(new_chats)
218-
pytest.assume(new_nums == old_nums - 1 - index)
211+
if index == old_nums - 1:
212+
new_chats = await a_list_chats(assistant_id=self.assistant_id)
213+
new_nums = len(new_chats)
214+
pytest.assume(new_nums == 0)
219215

220216

221217
@pytest.mark.test_async

test/testcase/test_async/test_async_retrieval.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,16 @@ async def test_a_update_collection(self):
106106
async def test_a_delete_collection(self):
107107
# List collections.
108108
old_res = await a_list_collections(order="desc", limit=100, after=None, before=None)
109-
109+
old_nums = len(old_res)
110110
for index, collection in enumerate(old_res):
111111
collection_id = collection.collection_id
112112
# Delete a collection.
113113
await a_delete_collection(collection_id=collection_id)
114-
115-
new_collections = await a_list_collections(order="desc", limit=100, after=None, before=None)
116-
# List collections.
117-
collection_ids = [c.collection_id for c in new_collections]
118-
pytest.assume(collection_id not in collection_ids)
114+
if index == old_nums - 1:
115+
new_collections = await a_list_collections(order="desc", limit=100, after=None, before=None)
116+
# List collections.
117+
new_nums = len(new_collections)
118+
pytest.assume(new_nums == 0)
119119

120120

121121
@pytest.mark.test_async
@@ -234,13 +234,13 @@ async def test_a_delete_record(self):
234234
await a_delete_record(collection_id=self.collection_id, record_id=record_id)
235235

236236
# List records.
237-
238-
new_records = await a_list_records(collection_id=self.collection_id, order="desc", limit=20, after=None,
239-
before=None)
240-
record_ids = [record.record_id for record in new_records]
241-
pytest.assume(record_id not in record_ids)
242-
new_nums = len(new_records)
243-
pytest.assume(new_nums == old_nums - 1 - index)
237+
if index == old_nums - 1:
238+
new_records = await a_list_records(collection_id=self.collection_id, order="desc", limit=20, after=None,
239+
before=None)
240+
record_ids = [record.record_id for record in new_records]
241+
pytest.assume(record_id not in record_ids)
242+
new_nums = len(new_records)
243+
pytest.assume(new_nums == 0)
244244

245245

246246
@pytest.mark.test_async
@@ -352,9 +352,7 @@ async def test_delete_chunk(self):
352352
delete_chunk(collection_id=self.collection_id, chunk_id=chunk_id)
353353

354354
# List chunks.
355-
356-
new_chunks = list_chunks(collection_id=self.collection_id)
357-
chunk_ids = [chunk.chunk_id for chunk in new_chunks]
358-
pytest.assume(chunk_id not in chunk_ids)
359-
new_nums = len(new_chunks)
360-
pytest.assume(new_nums == old_nums - 1 - index)
355+
if index == old_nums-1:
356+
new_chunks = list_chunks(collection_id=self.collection_id)
357+
new_nums = len(new_chunks)
358+
pytest.assume(new_nums == 0)

test/testcase/test_async/test_async_tool.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,7 @@ async def test_a_delete_action(self):
214214
# Delete an action.
215215

216216
await a_delete_action(action_id=action_id)
217-
218-
new_actions = await a_list_actions()
219-
action_ids = [action.action_id for action in new_actions]
220-
pytest.assume(action_id not in action_ids)
221-
new_nums = len(new_actions)
222-
pytest.assume(new_nums == old_nums - 1 - index)
223-
224-
225-
226-
217+
if index == old_nums - 1:
218+
new_actions = await a_list_actions()
219+
new_nums = len(new_actions)
220+
pytest.assume(new_nums == 0)

test/testcase/test_sync/test_sync_assistant.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,10 @@ def test_delete_assistant(self):
111111
delete_assistant(assistant_id=str(assistant_id))
112112

113113
# List assistants.
114-
115-
new_assistants = list_assistants()
116-
assistant_ids = [j.assistant_id for j in new_assistants]
117-
pytest.assume(assistant_id not in assistant_ids)
118-
new_nums = len(new_assistants)
119-
pytest.assume(new_nums == old_nums - 1 - i)
114+
if i == old_nums-1:
115+
new_assistants = list_assistants()
116+
new_nums = len(new_assistants)
117+
pytest.assume(new_nums == 0)
120118

121119

122120
@pytest.mark.test_sync
@@ -195,12 +193,10 @@ def test_delete_chat(self, assistant_id):
195193
delete_chat(assistant_id=assistant_id, chat_id=str(chat_id))
196194

197195
# List chats.
198-
199-
new_chats = list_chats(assistant_id=assistant_id)
200-
chat_ids = [i.chat_id for i in new_chats]
201-
pytest.assume(chat_id not in chat_ids)
202-
new_nums = len(new_chats)
203-
pytest.assume(new_nums == old_nums - 1 - index)
196+
if index == old_nums-1:
197+
new_chats = list_chats(assistant_id=assistant_id)
198+
new_nums = len(new_chats)
199+
pytest.assume(new_nums == 0)
204200

205201

206202
@pytest.mark.test_sync

test/testcase/test_sync/test_sync_retrieval.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,13 @@ def test_delete_collection(self):
109109
# Delete a collection.
110110

111111
delete_collection(collection_id=collection_id)
112+
if index == old_nums-1:
113+
new_collections = list_collections(order="desc", limit=100, after=None, before=None)
112114

113-
new_collections = list_collections(order="desc", limit=100, after=None, before=None)
115+
# List collections.
114116

115-
# List collections.
116-
117-
collection_ids = [collection.collection_id for collection in new_collections]
118-
pytest.assume(collection_id not in collection_ids)
119-
new_nums = len(new_collections)
120-
pytest.assume(new_nums == old_nums - 1 - index)
117+
new_nums = len(new_collections)
118+
pytest.assume(new_nums == 0)
121119

122120

123121
@pytest.mark.test_sync
@@ -229,13 +227,12 @@ def test_delete_record(self, collection_id):
229227
delete_record(collection_id=collection_id, record_id=record_id)
230228

231229
# List records.
230+
if index == old_nums-1:
231+
new_records = list_records(collection_id=collection_id, order="desc", limit=20, after=None,
232+
before=None)
232233

233-
new_records = list_records(collection_id=collection_id, order="desc", limit=20, after=None,
234-
before=None)
235-
record_ids = [record.record_id for record in new_records]
236-
pytest.assume(record_id not in record_ids)
237-
new_nums = len(new_records)
238-
pytest.assume(new_nums == old_nums - 1 - index)
234+
new_nums = len(new_records)
235+
pytest.assume(new_nums == 0)
239236

240237

241238
@pytest.mark.test_sync
@@ -340,9 +337,7 @@ def test_delete_chunk(self, collection_id):
340337
delete_chunk(collection_id=collection_id, chunk_id=chunk_id)
341338

342339
# List chunks.
343-
344-
new_chunks = list_chunks(collection_id=collection_id)
345-
chunk_ids = [chunk.chunk_id for chunk in new_chunks]
346-
pytest.assume(chunk_id not in chunk_ids)
347-
new_nums = len(new_chunks)
348-
pytest.assume(new_nums == old_nums - 1 - index)
340+
if index == old_nums-1:
341+
new_chunks = list_chunks(collection_id=collection_id)
342+
new_nums = len(new_chunks)
343+
pytest.assume(new_nums == 0)

test/testcase/test_sync/test_sync_tool.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ def test_delete_action(self):
207207
# Delete an action.
208208

209209
delete_action(action_id=action_id)
210-
new_actions = list_actions(limit=100)
211-
action_ids = [action.action_id for action in new_actions]
212-
pytest.assume(action_id not in action_ids)
213-
new_nums = len(new_actions)
214-
pytest.assume(new_nums == old_nums - 1 - index)
210+
211+
if index == old_nums-1:
212+
new_actions = list_actions(limit=100)
213+
new_nums = len(new_actions)
214+
pytest.assume(new_nums == 0)

test_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ pytest-tornasync>=0.6.0
1515
pytest-trio==0.8.0
1616
pytest-twisted==1.14.0
1717
Twisted==24.3.0
18-
dotenv==1.0.0
18+
python-dotenv==1.0.0

0 commit comments

Comments
 (0)