-
Notifications
You must be signed in to change notification settings - Fork 170
task: Expand e2e test for section "files" #2065
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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
52ce44c
test: add e2e files
f5a31c5
test: fix ci
c837a13
test: fix ci, update match condition
dcc9689
test: print log ci
e193207
test: print log ci
9125e3e
test: print path
e5a34b8
test: debug
a081f3a
test: skip
528b8d0
test: fix
c69414f
test: fix
62069cc
Merge branch 'dev' into harry/e2e-files
LeVinhGithub 4e8d46e
Merge branch 'dev' into harry/e2e-files
LeVinhGithub 32c76f5
Merge branch 'dev' into harry/e2e-files
LeVinhGithub 98b809a
test: update workflow
42353ee
Merge branch 'harry/e2e-files' of https://github.com/janhq/cortex.cpp…
472df4c
Merge branch 'dev' into harry/e2e-files
LeVinhGithub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import pytest | ||
import requests | ||
from utils.test_runner import start_server, stop_server | ||
import os | ||
import platform | ||
import jsonschema | ||
from utils.logger import log_response | ||
from utils.assertion import assert_equal | ||
import fnmatch | ||
|
||
|
||
class TestApiCreateFile: | ||
|
||
@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() | ||
|
||
@pytest.mark.skipif(platform.system() != "Linux", reason="Todo: fix later on Mac and Window") | ||
def test_api_create_file_successfully(self): | ||
# Define file path | ||
file_path_rel = os.path.join("e2e-test", "api", "files", "blank.txt") | ||
file_path = os.path.join(os.getcwd(), file_path_rel) | ||
log_response(file_path, "test_api_create_file_successfully") | ||
|
||
post_file_url = "http://127.0.0.1:3928/v1/files" | ||
with open(file_path, "rb") as file: | ||
files = {"file": ("blank.txt", file, "text/plain")} | ||
data = {"purpose": "assistants"} | ||
response = requests.post(post_file_url, files=files, data=data) | ||
log_response(response.text, "test_api_create_file_successfully") | ||
log_response(response.status_code, "test_api_create_file_successfully") | ||
|
||
json_data = response.json() | ||
log_response(json_data, "test_api_create_file_successfully") | ||
assert_equal(response.status_code, 200) | ||
|
||
# Schema to validate | ||
schema = { | ||
"type": "object", | ||
"properties": { | ||
"bytes": {"type": "integer"}, | ||
"created_at": {"type": "integer"}, | ||
"filename": {"type": "string"}, | ||
"id": {"type": "string"}, | ||
"object": {"type": "string"}, | ||
"purpose": {"type": "string"} | ||
}, | ||
"required": ["bytes", "created_at", "filename", "id", "object", "purpose"] | ||
} | ||
|
||
# Validate response schema | ||
jsonschema.validate(instance=json_data, schema=schema) | ||
|
||
# Assert content | ||
assert (fnmatch.fnmatch(json_data["filename"], "blank_*.txt") or json_data["filename"] == "blank.txt"), f"Filename {json_data['filename']} does not match pattern blank_*.txt or blank.txt" | ||
assert_equal(json_data["purpose"], "assistants") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import pytest | ||
import requests | ||
from utils.test_runner import start_server, stop_server | ||
import os | ||
import jsonschema | ||
from utils.logger import log_response | ||
from utils.assertion import assert_equal | ||
import platform | ||
|
||
|
||
class TestApiDeleteFile: | ||
|
||
@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() | ||
|
||
@pytest.mark.skipif(platform.system() != "Linux", reason="Todo: fix later on Mac and Window") | ||
def test_api_del_file_successfully(self): | ||
# Define file path | ||
file_path = os.path.join("e2e-test", "api", "files", "blank.txt") | ||
|
||
# Upload file first | ||
files = { | ||
"file": ("blank.txt", open(file_path, "rb"), "text/plain") | ||
} | ||
data = { | ||
"purpose": "assistants" | ||
} | ||
|
||
file_url = "http://127.0.0.1:3928/v1/files" | ||
response = requests.post(file_url, files=files, data=data) | ||
|
||
json_data = response.json() | ||
log_response(json_data, "test_api_del_file_successfully") | ||
assert_equal(response.status_code, 200) | ||
|
||
file_id=json_data["id"] | ||
|
||
# Delete message with id | ||
file_id_url = f"http://127.0.0.1:3928/v1/files/{file_id}" | ||
file_response = requests.delete(file_id_url) | ||
json_data_file = file_response.json() | ||
log_response(json_data_file, "test_api_del_file_successfully") | ||
assert_equal(file_response.status_code,200) | ||
|
||
|
||
# Schema to validate | ||
schema = { | ||
"properties": { | ||
"deleted": { | ||
"description": "Indicates if the file was successfully deleted", | ||
"type": "boolean" | ||
}, | ||
"id": { | ||
"description": "The ID of the deleted file", | ||
"type": "string" | ||
}, | ||
"object": { | ||
"description": "Type of object, always 'file'", | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"deleted", | ||
"id", | ||
"object" | ||
], | ||
"type": "object" | ||
} | ||
|
||
# Validate response schema | ||
jsonschema.validate(instance=json_data_file, schema=schema) | ||
|
||
# Assert content | ||
assert_equal(json_data_file["deleted"], True) | ||
assert_equal(json_data_file["id"], file_id) | ||
assert_equal(json_data_file["object"], "file") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import pytest | ||
import requests | ||
from utils.test_runner import start_server, stop_server | ||
import platform | ||
import os | ||
import jsonschema | ||
from utils.logger import log_response | ||
from utils.assertion import assert_equal | ||
import fnmatch | ||
|
||
|
||
class TestApiGetFile: | ||
|
||
@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() | ||
|
||
@pytest.mark.skipif(platform.system() != "Linux", reason="Todo: fix later on Mac and Window") | ||
def test_api_get_file_successfully(self): | ||
# Define file path | ||
file_path = os.path.join("e2e-test", "api", "files", "blank.txt") | ||
|
||
# Upload file first | ||
files = { | ||
"file": ("blank.txt", open(file_path, "rb"), "text/plain") | ||
} | ||
data = { | ||
"purpose": "assistants" | ||
} | ||
|
||
file_url = "http://127.0.0.1:3928/v1/files" | ||
response = requests.post(file_url, files=files, data=data) | ||
log_response(response.text, "test_api_get_file_successfully") | ||
|
||
json_data = response.json() | ||
log_response(json_data, "test_api_get_file_successfully") | ||
assert_equal(response.status_code, 200) | ||
|
||
file_id=json_data["id"] | ||
|
||
# Get message with id | ||
file_id_url = f"http://127.0.0.1:3928/v1/files/{file_id}" | ||
file_response = requests.get(file_id_url) | ||
json_data_file = file_response.json() | ||
log_response(json_data_file, "test_api_get_file_successfully") | ||
assert_equal(file_response.status_code,200) | ||
|
||
|
||
# Schema to validate | ||
schema = { | ||
"properties": { | ||
"bytes": { | ||
"type": "integer", | ||
"examples": [ | ||
3211109 | ||
] | ||
}, | ||
"created_at": { | ||
"type": "integer", | ||
"examples": [ | ||
1733942093 | ||
] | ||
}, | ||
"filename": { | ||
"type": "string", | ||
"examples": [ | ||
"Enterprise_Application_Infrastructure_v2_20140903_toCTC_v1.0.pdf" | ||
] | ||
}, | ||
"id": { | ||
"type": "string", | ||
"examples": [ | ||
"file-0001KNKPTDDAQSDVEQGRBTCTNJ" | ||
] | ||
}, | ||
"object": { | ||
"type": "string", | ||
"examples": [ | ||
"file" | ||
] | ||
}, | ||
"purpose": { | ||
"type": "string", | ||
"examples": [ | ||
"assistants" | ||
] | ||
} | ||
}, | ||
"type": "object" | ||
} | ||
|
||
# Validate response schema | ||
jsonschema.validate(instance=json_data_file, schema=schema) | ||
|
||
# Assert content | ||
assert (fnmatch.fnmatch(json_data["filename"], "blank_*.txt") or json_data["filename"] == "blank.txt"), f"Filename {json_data['filename']} does not match pattern blank_*.txt or blank.txt" | ||
assert_equal(json_data_file["id"], file_id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import pytest | ||
import requests | ||
from utils.test_runner import start_server, stop_server | ||
import os | ||
import platform | ||
import jsonschema | ||
from utils.logger import log_response | ||
from utils.assertion import assert_equal | ||
import fnmatch | ||
|
||
|
||
class TestApiGetListFile: | ||
|
||
@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() | ||
|
||
@pytest.mark.skipif(platform.system() != "Linux", reason="Todo: fix later on Mac and Window") | ||
def test_api_get_list_file_successfully(self): | ||
# Define file path | ||
file_path = os.path.join("e2e-test", "api", "files", "blank.txt") | ||
|
||
# Upload file first | ||
files = { | ||
"file": ("blank.txt", open(file_path, "rb"), "text/plain") | ||
} | ||
data = { | ||
"purpose": "assistants" | ||
} | ||
|
||
file_url = "http://127.0.0.1:3928/v1/files" | ||
response = requests.post(file_url, files=files, data=data) | ||
log_response(response.text, "test_api_get_list_file_successfully") | ||
|
||
json_data = response.json() | ||
log_response(json_data, "test_api_get_list_file_successfully") | ||
assert_equal(response.status_code, 200) | ||
|
||
# Get list message | ||
list_file_response = requests.get(file_url) | ||
json_data_list_file = list_file_response.json() | ||
log_response(json_data_list_file, "test_api_get_list_file_successfully") | ||
assert_equal(list_file_response.status_code,200) | ||
|
||
|
||
# Schema to validate | ||
schema = { | ||
"properties": { | ||
"data": { | ||
"items": { | ||
"properties": { | ||
"bytes": { | ||
"type": "integer", | ||
"examples": [ | ||
3211109 | ||
] | ||
}, | ||
"created_at": { | ||
"type": "integer", | ||
"examples": [ | ||
1733942093 | ||
] | ||
}, | ||
"filename": { | ||
"type": "string", | ||
"examples": [ | ||
"Enterprise_Application_Infrastructure_v2_20140903_toCTC_v1.0.pdf" | ||
] | ||
}, | ||
"id": { | ||
"type": "string", | ||
"examples": [ | ||
"file-0001KNKPTDDAQSDVEQGRBTCTNJ" | ||
] | ||
}, | ||
"object": { | ||
"type": "string", | ||
"examples": [ | ||
"file" | ||
] | ||
}, | ||
"purpose": { | ||
"type": "string", | ||
"examples": [ | ||
"assistants" | ||
] | ||
} | ||
}, | ||
"type": "object" | ||
}, | ||
"type": "array" | ||
}, | ||
"object": { | ||
"type": "string", | ||
"examples": [ | ||
"list" | ||
] | ||
} | ||
}, | ||
"type": "object" | ||
} | ||
|
||
# Validate response schema | ||
jsonschema.validate(instance=json_data_list_file, schema=schema) | ||
|
||
# Assert content | ||
assert (fnmatch.fnmatch(json_data["filename"], "blank_*.txt") or json_data["filename"] == "blank.txt"), f"Filename {json_data['filename']} does not match pattern blank_*.txt or blank.txt" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add this file to
.gitignores