Skip to content

task: Expand e2e test for section "thread" #2067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions engine/e2e-test/api/thread/test_api_create_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import pytest
import requests
from utils.test_runner import start_server, stop_server
import jsonschema
from utils.logger import log_response
from utils.assertion import assert_equal


class TestApiCreateThread:

@pytest.fixture(autouse=True)
def setup_and_teardown(self):
# Setup
success = start_server()
if not success:
raise Exception("Failed to start server")

yield

# Teardown
stop_server()

def test_api_create_thread_successfully(self):
title = "New Thread"

data = {
"metadata": {
"title": title
}
}

post_thread_url = f"http://localhost:3928/v1/threads"
response = requests.post(
post_thread_url, json=data
)
json_data = response.json()
log_response(json_data, "test_api_create_thread_successfully")
assert_equal(response.status_code,200)

schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"created_at": {
"type": "integer"
},
"id": {
"type": "string"
},
"metadata": {
"type": "object",
"properties": {
"title": {
"type": "string"
}
},
"required": ["title"],
},
"object": {
"type": "string"
}
},
"required": ["created_at", "id", "metadata", "object"],
}

# Validate response schema
jsonschema.validate(instance=json_data, schema=schema)

assert_equal(json_data["metadata"]['title'], title)
75 changes: 75 additions & 0 deletions engine/e2e-test/api/thread/test_api_delete_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import pytest
import requests
from utils.test_runner import start_server, stop_server
import jsonschema
from utils.logger import log_response
from utils.assertion import assert_equal


class TestApiDeleteThread:

@pytest.fixture(autouse=True)
def setup_and_teardown(self):
# Setup
success = start_server()
if not success:
raise Exception("Failed to start server")

yield

# Teardown
stop_server()

def test_api_delete_thread_successfully(self):
title = "New thread"

data = {
"metadata": {
"title": title
}
}

thread_url = f"http://localhost:3928/v1/threads"
response = requests.post(
thread_url, json=data
)
json_data = response.json()
log_response(json_data, "test_api_delete_thread_successfully")
assert_equal(response.status_code,200)
thread_id = json_data["id"]

thread_id_url = f"http://localhost:3928/v1/threads/{thread_id}"
thread_response = requests.delete(thread_id_url)
json_data_thread = thread_response.json()
log_response(json_data_thread, "test_api_delete_thread_successfully")
assert_equal(thread_response.status_code,200)

schema = {
"type": "object",
"properties": {
"deleted": {
"type": "boolean",
"description": "Indicates if the thread was successfully deleted"
},
"id": {
"type": "string",
"description": "ID of the deleted thread"
},
"object": {
"type": "string",
"description": "Type of object, always 'thread.deleted'"
}
},
"required": [
"deleted",
"id",
"object"
]
}

# Validate response schema
jsonschema.validate(instance=json_data_thread, schema=schema)

assert_equal(json_data_thread["deleted"], True)
assert_equal(json_data_thread["id"], thread_id)
assert_equal(json_data_thread["object"], "thread.deleted")
101 changes: 101 additions & 0 deletions engine/e2e-test/api/thread/test_api_get_list_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import pytest
import requests
from utils.test_runner import start_server, stop_server
import jsonschema
from utils.logger import log_response
from utils.assertion import assert_equal


class TestApiGetListThread:

@pytest.fixture(autouse=True)
def setup_and_teardown(self):
# Setup
success = start_server()
if not success:
raise Exception("Failed to start server")

yield

# Teardown
stop_server()

def test_api_get_list_thread_successfully(self):
title = "New Thread"

data = {
"metadata": {
"title": title
}
}

thread_url = f"http://localhost:3928/v1/threads"
response = requests.post(
thread_url, json=data
)
json_data = response.json()
log_response(json_data, "test_api_get_list_thread_successfully")
assert_equal(response.status_code,200)

list_thread_response = requests.get(thread_url)
json_data_list_thread = list_thread_response.json()
log_response(json_data_list_thread, "test_api_get_list_thread_successfully")
assert_equal(list_thread_response.status_code,200)

schema = {
"type": "object",
"properties": {
"object": {
"type": "string",
"description": "Type of the list response, always 'list'"
},
"data": {
"type": "array",
"description": "Array of thread objects",
"items": {
"type": "object",
"properties": {
"created_at": {
"type": "integer",
"description": "Unix timestamp of when the thread was created"
},
"id": {
"type": "string",
"description": "Unique identifier for the thread"
},
"metadata": {
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "Title of the thread"
},
"lastMessage": {
"type": "string",
"description": "Content of the last message in the thread"
}
},
"description": "Metadata associated with the thread"
},
"object": {
"type": "string",
"description": "Type of object, always 'thread'"
}
},
"required": [
"created_at",
"id",
"object"
]
}
}
},
"required": [
"object",
"data"
]
}

# Validate response schema
jsonschema.validate(instance=json_data_list_thread, schema=schema)
assert_equal(json_data_list_thread["data"][0]["metadata"]['title'], title)
86 changes: 86 additions & 0 deletions engine/e2e-test/api/thread/test_api_get_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import pytest
import requests
from utils.test_runner import start_server, stop_server
import jsonschema
from utils.logger import log_response
from utils.assertion import assert_equal


class TestApiGetThread:

@pytest.fixture(autouse=True)
def setup_and_teardown(self):
# Setup
success = start_server()
if not success:
raise Exception("Failed to start server")

yield

# Teardown
stop_server()

def test_api_get_thread_successfully(self):
title = "Get specific thread"

data = {
"metadata": {
"title": title
}
}

thread_url = f"http://localhost:3928/v1/threads"
response = requests.post(
thread_url, json=data
)
json_data = response.json()
log_response(json_data, "test_api_get_thread_successfully")
assert_equal(response.status_code,200)
thread_id = json_data["id"]

thread_id_url = f"http://localhost:3928/v1/threads/{thread_id}"
thread_response = requests.get(thread_id_url)
json_data_thread = thread_response.json()
log_response(json_data_thread, "test_api_get_thread_successfully")
assert_equal(thread_response.status_code,200)

schema = {
"type": "object",
"properties": {
"created_at": {
"type": "integer",
"description": "Unix timestamp of when the thread was created"
},
"id": {
"type": "string",
"description": "Unique identifier for the thread"
},
"metadata": {
"type": "object",
"properties": {
"lastMessage": {
"type": "string",
"description": "Content of the last message in the thread"
},
"title": {
"type": "string",
"description": "Title of the thread"
}
},
"description": "Metadata associated with the thread"
},
"object": {
"type": "string",
"description": "Type of object, always 'thread'"
}
},
"required": [
"created_at",
"id",
"object"
]
}

# Validate response schema
jsonschema.validate(instance=json_data_thread, schema=schema)
assert_equal(json_data_thread["metadata"]['title'], title)
4 changes: 4 additions & 0 deletions engine/e2e-test/runner/cortex-llamacpp-e2e-nightly.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
from test_api_post_default_engine import TestApiSetDefaultEngine
from api.model.test_api_model import TestApiModel
from api.model.test_api_model_import import TestApiModelImport
from api.thread.test_api_create_thread import TestApiCreateThread
from api.thread.test_api_delete_thread import TestApiDeleteThread
from api.thread.test_api_get_thread import TestApiGetThread
from api.thread.test_api_get_list_thread import TestApiGetListThread

###
from cli.engines.test_cli_engine_get import TestCliEngineGet
Expand Down
4 changes: 4 additions & 0 deletions engine/e2e-test/runner/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
from test_api_post_default_engine import TestApiSetDefaultEngine
from api.model.test_api_model import TestApiModel
from api.model.test_api_model_import import TestApiModelImport
from api.thread.test_api_create_thread import TestApiCreateThread
from api.thread.test_api_delete_thread import TestApiDeleteThread
from api.thread.test_api_get_thread import TestApiGetThread
from api.thread.test_api_get_list_thread import TestApiGetListThread

###
from cli.engines.test_cli_engine_get import TestCliEngineGet
Expand Down
Loading