Skip to content

Commit b74e4d4

Browse files
LeVinhGithubHarry Le
and
Harry Le
authored
task: Expand e2e test for section "thread" #2067
Co-authored-by: Harry Le <[email protected]>
1 parent ea24ea4 commit b74e4d4

File tree

6 files changed

+339
-0
lines changed

6 files changed

+339
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import pytest
2+
import requests
3+
from utils.test_runner import start_server, stop_server
4+
import jsonschema
5+
from utils.logger import log_response
6+
from utils.assertion import assert_equal
7+
8+
9+
class TestApiCreateThread:
10+
11+
@pytest.fixture(autouse=True)
12+
def setup_and_teardown(self):
13+
# Setup
14+
success = start_server()
15+
if not success:
16+
raise Exception("Failed to start server")
17+
18+
yield
19+
20+
# Teardown
21+
stop_server()
22+
23+
def test_api_create_thread_successfully(self):
24+
title = "New Thread"
25+
26+
data = {
27+
"metadata": {
28+
"title": title
29+
}
30+
}
31+
32+
post_thread_url = f"http://localhost:3928/v1/threads"
33+
response = requests.post(
34+
post_thread_url, json=data
35+
)
36+
json_data = response.json()
37+
log_response(json_data, "test_api_create_thread_successfully")
38+
assert_equal(response.status_code,200)
39+
40+
schema = {
41+
"$schema": "http://json-schema.org/draft-07/schema#",
42+
"type": "object",
43+
"properties": {
44+
"created_at": {
45+
"type": "integer"
46+
},
47+
"id": {
48+
"type": "string"
49+
},
50+
"metadata": {
51+
"type": "object",
52+
"properties": {
53+
"title": {
54+
"type": "string"
55+
}
56+
},
57+
"required": ["title"],
58+
},
59+
"object": {
60+
"type": "string"
61+
}
62+
},
63+
"required": ["created_at", "id", "metadata", "object"],
64+
}
65+
66+
# Validate response schema
67+
jsonschema.validate(instance=json_data, schema=schema)
68+
69+
assert_equal(json_data["metadata"]['title'], title)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import pytest
2+
import requests
3+
from utils.test_runner import start_server, stop_server
4+
import jsonschema
5+
from utils.logger import log_response
6+
from utils.assertion import assert_equal
7+
8+
9+
class TestApiDeleteThread:
10+
11+
@pytest.fixture(autouse=True)
12+
def setup_and_teardown(self):
13+
# Setup
14+
success = start_server()
15+
if not success:
16+
raise Exception("Failed to start server")
17+
18+
yield
19+
20+
# Teardown
21+
stop_server()
22+
23+
def test_api_delete_thread_successfully(self):
24+
title = "New thread"
25+
26+
data = {
27+
"metadata": {
28+
"title": title
29+
}
30+
}
31+
32+
thread_url = f"http://localhost:3928/v1/threads"
33+
response = requests.post(
34+
thread_url, json=data
35+
)
36+
json_data = response.json()
37+
log_response(json_data, "test_api_delete_thread_successfully")
38+
assert_equal(response.status_code,200)
39+
thread_id = json_data["id"]
40+
41+
thread_id_url = f"http://localhost:3928/v1/threads/{thread_id}"
42+
thread_response = requests.delete(thread_id_url)
43+
json_data_thread = thread_response.json()
44+
log_response(json_data_thread, "test_api_delete_thread_successfully")
45+
assert_equal(thread_response.status_code,200)
46+
47+
schema = {
48+
"type": "object",
49+
"properties": {
50+
"deleted": {
51+
"type": "boolean",
52+
"description": "Indicates if the thread was successfully deleted"
53+
},
54+
"id": {
55+
"type": "string",
56+
"description": "ID of the deleted thread"
57+
},
58+
"object": {
59+
"type": "string",
60+
"description": "Type of object, always 'thread.deleted'"
61+
}
62+
},
63+
"required": [
64+
"deleted",
65+
"id",
66+
"object"
67+
]
68+
}
69+
70+
# Validate response schema
71+
jsonschema.validate(instance=json_data_thread, schema=schema)
72+
73+
assert_equal(json_data_thread["deleted"], True)
74+
assert_equal(json_data_thread["id"], thread_id)
75+
assert_equal(json_data_thread["object"], "thread.deleted")
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import pytest
2+
import requests
3+
from utils.test_runner import start_server, stop_server
4+
import jsonschema
5+
from utils.logger import log_response
6+
from utils.assertion import assert_equal
7+
8+
9+
class TestApiGetListThread:
10+
11+
@pytest.fixture(autouse=True)
12+
def setup_and_teardown(self):
13+
# Setup
14+
success = start_server()
15+
if not success:
16+
raise Exception("Failed to start server")
17+
18+
yield
19+
20+
# Teardown
21+
stop_server()
22+
23+
def test_api_get_list_thread_successfully(self):
24+
title = "New Thread"
25+
26+
data = {
27+
"metadata": {
28+
"title": title
29+
}
30+
}
31+
32+
thread_url = f"http://localhost:3928/v1/threads"
33+
response = requests.post(
34+
thread_url, json=data
35+
)
36+
json_data = response.json()
37+
log_response(json_data, "test_api_get_list_thread_successfully")
38+
assert_equal(response.status_code,200)
39+
40+
list_thread_response = requests.get(thread_url)
41+
json_data_list_thread = list_thread_response.json()
42+
log_response(json_data_list_thread, "test_api_get_list_thread_successfully")
43+
assert_equal(list_thread_response.status_code,200)
44+
45+
schema = {
46+
"type": "object",
47+
"properties": {
48+
"object": {
49+
"type": "string",
50+
"description": "Type of the list response, always 'list'"
51+
},
52+
"data": {
53+
"type": "array",
54+
"description": "Array of thread objects",
55+
"items": {
56+
"type": "object",
57+
"properties": {
58+
"created_at": {
59+
"type": "integer",
60+
"description": "Unix timestamp of when the thread was created"
61+
},
62+
"id": {
63+
"type": "string",
64+
"description": "Unique identifier for the thread"
65+
},
66+
"metadata": {
67+
"type": "object",
68+
"properties": {
69+
"title": {
70+
"type": "string",
71+
"description": "Title of the thread"
72+
},
73+
"lastMessage": {
74+
"type": "string",
75+
"description": "Content of the last message in the thread"
76+
}
77+
},
78+
"description": "Metadata associated with the thread"
79+
},
80+
"object": {
81+
"type": "string",
82+
"description": "Type of object, always 'thread'"
83+
}
84+
},
85+
"required": [
86+
"created_at",
87+
"id",
88+
"object"
89+
]
90+
}
91+
}
92+
},
93+
"required": [
94+
"object",
95+
"data"
96+
]
97+
}
98+
99+
# Validate response schema
100+
jsonschema.validate(instance=json_data_list_thread, schema=schema)
101+
assert_equal(json_data_list_thread["data"][0]["metadata"]['title'], title)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import pytest
2+
import requests
3+
from utils.test_runner import start_server, stop_server
4+
import jsonschema
5+
from utils.logger import log_response
6+
from utils.assertion import assert_equal
7+
8+
9+
class TestApiGetThread:
10+
11+
@pytest.fixture(autouse=True)
12+
def setup_and_teardown(self):
13+
# Setup
14+
success = start_server()
15+
if not success:
16+
raise Exception("Failed to start server")
17+
18+
yield
19+
20+
# Teardown
21+
stop_server()
22+
23+
def test_api_get_thread_successfully(self):
24+
title = "Get specific thread"
25+
26+
data = {
27+
"metadata": {
28+
"title": title
29+
}
30+
}
31+
32+
thread_url = f"http://localhost:3928/v1/threads"
33+
response = requests.post(
34+
thread_url, json=data
35+
)
36+
json_data = response.json()
37+
log_response(json_data, "test_api_get_thread_successfully")
38+
assert_equal(response.status_code,200)
39+
thread_id = json_data["id"]
40+
41+
thread_id_url = f"http://localhost:3928/v1/threads/{thread_id}"
42+
thread_response = requests.get(thread_id_url)
43+
json_data_thread = thread_response.json()
44+
log_response(json_data_thread, "test_api_get_thread_successfully")
45+
assert_equal(thread_response.status_code,200)
46+
47+
schema = {
48+
"type": "object",
49+
"properties": {
50+
"created_at": {
51+
"type": "integer",
52+
"description": "Unix timestamp of when the thread was created"
53+
},
54+
"id": {
55+
"type": "string",
56+
"description": "Unique identifier for the thread"
57+
},
58+
"metadata": {
59+
"type": "object",
60+
"properties": {
61+
"lastMessage": {
62+
"type": "string",
63+
"description": "Content of the last message in the thread"
64+
},
65+
"title": {
66+
"type": "string",
67+
"description": "Title of the thread"
68+
}
69+
},
70+
"description": "Metadata associated with the thread"
71+
},
72+
"object": {
73+
"type": "string",
74+
"description": "Type of object, always 'thread'"
75+
}
76+
},
77+
"required": [
78+
"created_at",
79+
"id",
80+
"object"
81+
]
82+
}
83+
84+
# Validate response schema
85+
jsonschema.validate(instance=json_data_thread, schema=schema)
86+
assert_equal(json_data_thread["metadata"]['title'], title)

engine/e2e-test/runner/cortex-llamacpp-e2e-nightly.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
from test_api_post_default_engine import TestApiSetDefaultEngine
2525
from api.model.test_api_model import TestApiModel
2626
from api.model.test_api_model_import import TestApiModelImport
27+
from api.thread.test_api_create_thread import TestApiCreateThread
28+
from api.thread.test_api_delete_thread import TestApiDeleteThread
29+
from api.thread.test_api_get_thread import TestApiGetThread
30+
from api.thread.test_api_get_list_thread import TestApiGetListThread
2731

2832
###
2933
from cli.engines.test_cli_engine_get import TestCliEngineGet

engine/e2e-test/runner/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
from test_api_post_default_engine import TestApiSetDefaultEngine
2525
from api.model.test_api_model import TestApiModel
2626
from api.model.test_api_model_import import TestApiModelImport
27+
from api.thread.test_api_create_thread import TestApiCreateThread
28+
from api.thread.test_api_delete_thread import TestApiDeleteThread
29+
from api.thread.test_api_get_thread import TestApiGetThread
30+
from api.thread.test_api_get_list_thread import TestApiGetListThread
2731

2832
###
2933
from cli.engines.test_cli_engine_get import TestCliEngineGet

0 commit comments

Comments
 (0)