diff --git a/engine/e2e-test/api/thread/test_api_create_thread.py b/engine/e2e-test/api/thread/test_api_create_thread.py new file mode 100644 index 000000000..f459c482c --- /dev/null +++ b/engine/e2e-test/api/thread/test_api_create_thread.py @@ -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) \ No newline at end of file diff --git a/engine/e2e-test/api/thread/test_api_delete_thread.py b/engine/e2e-test/api/thread/test_api_delete_thread.py new file mode 100644 index 000000000..36f010d12 --- /dev/null +++ b/engine/e2e-test/api/thread/test_api_delete_thread.py @@ -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") \ No newline at end of file diff --git a/engine/e2e-test/api/thread/test_api_get_list_thread.py b/engine/e2e-test/api/thread/test_api_get_list_thread.py new file mode 100644 index 000000000..9473dda65 --- /dev/null +++ b/engine/e2e-test/api/thread/test_api_get_list_thread.py @@ -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) \ No newline at end of file diff --git a/engine/e2e-test/api/thread/test_api_get_thread.py b/engine/e2e-test/api/thread/test_api_get_thread.py new file mode 100644 index 000000000..0848de651 --- /dev/null +++ b/engine/e2e-test/api/thread/test_api_get_thread.py @@ -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) \ No newline at end of file diff --git a/engine/e2e-test/runner/cortex-llamacpp-e2e-nightly.py b/engine/e2e-test/runner/cortex-llamacpp-e2e-nightly.py index 2bf3af09b..ba648320c 100644 --- a/engine/e2e-test/runner/cortex-llamacpp-e2e-nightly.py +++ b/engine/e2e-test/runner/cortex-llamacpp-e2e-nightly.py @@ -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 diff --git a/engine/e2e-test/runner/main.py b/engine/e2e-test/runner/main.py index 009f4d718..0dca86d21 100644 --- a/engine/e2e-test/runner/main.py +++ b/engine/e2e-test/runner/main.py @@ -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