Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 53e87d0

Browse files
author
Harry Le
committed
test: add more
1 parent 43a1b20 commit 53e87d0

File tree

6 files changed

+163
-7
lines changed

6 files changed

+163
-7
lines changed

engine/e2e-test/api/engines/test_api_get_default_engine.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_api_get_default_engine_successfully(self):
3333
post_install_url, json=data
3434
)
3535
assert_equal(response.status_code,200)
36+
log_response(response.json(), "test_api_get_default_engine_successfully")
3637

3738
get_list_url = f"http://localhost:3928/v1/engines/{engine}"
3839
get_default_url = f"http://localhost:3928/v1/engines/{engine}/default"
@@ -66,11 +67,7 @@ def get_request(url):
6667
# Validate response schema
6768
jsonschema.validate(instance=json_data, schema=schema)
6869

69-
assert_equal(json_data["engine"], engine)
70-
assert_equal(json_data["version"], version)
71-
assert_equal(json_data["variant"], name)
72-
73-
def test_api_get_default_engine_successfully(self):
70+
def test_api_get_default_engine_failed_invalid_engine(self):
7471
# Data test
7572
engine= "invalid"
7673

@@ -79,7 +76,7 @@ def test_api_get_default_engine_successfully(self):
7976
response_default_engine = requests.get(get_default_url)
8077
json_data_get_default = response_default_engine.json()
8178

82-
log_response(json_data_get_default, "test_api_get_default_engine_successfully")
79+
log_response(json_data_get_default, "test_api_get_default_engine_failed_invalid_engine")
8380
assert_equal(response_default_engine.status_code, 400)
8481

8582
assert_equal(json_data_get_default["message"], f"Engine {engine} is not supported yet!")
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import pytest
2+
import requests
3+
from utils.test_runner import start_server, stop_server
4+
import jsonschema
5+
from tenacity import retry, wait_exponential, stop_after_attempt
6+
from utils.logger import log_response
7+
from utils.assertion import assert_equal, assert_contains
8+
9+
10+
class TestApiEngineRelease:
11+
12+
@pytest.fixture(autouse=True)
13+
def setup_and_teardown(self):
14+
# Setup
15+
success = start_server()
16+
if not success:
17+
raise Exception("Failed to start server")
18+
19+
yield
20+
21+
# Teardown
22+
stop_server()
23+
24+
def test_api_get_engine_release_successfully(self):
25+
# Data test
26+
engine= "llama-cpp"
27+
get_release_url = f"http://localhost:3928/v1/engines/{engine}/releases"
28+
29+
@retry(
30+
wait=wait_exponential(multiplier=2, min=2, max=30),
31+
stop=stop_after_attempt(5)
32+
)
33+
def get_request(url):
34+
response = requests.get(url)
35+
assert len(response.json()) > 0
36+
37+
get_request(get_release_url)
38+
39+
response_engine_release = requests.get(get_release_url)
40+
json_data = response_engine_release.json()
41+
42+
log_response(json_data, "test_api_get_engine_release_successfully")
43+
assert_equal(response_engine_release.status_code, 200)
44+
45+
schema = {
46+
"$schema": "http://json-schema.org/draft-07/schema#",
47+
"type": "array",
48+
"items": {
49+
"type": "object",
50+
"properties": {
51+
"draft": { "type": "boolean" },
52+
"name": { "type": "string" },
53+
"prerelease": { "type": "boolean" },
54+
"published_at": { "type": "string", "format": "date-time" },
55+
"url": { "type": "string", "format": "uri" }
56+
},
57+
"required": ["draft", "name", "prerelease", "published_at", "url"]
58+
}
59+
}
60+
61+
# Validate response schema
62+
jsonschema.validate(instance=json_data, schema=schema)
63+
64+
def test_api_ge_engine_release_failed_invalid_engine(self):
65+
# Data test
66+
engine= "invalid"
67+
68+
get_default_url = f"http://localhost:3928/v1/engines/{engine}/releases"
69+
70+
response_default_engine = requests.get(get_default_url)
71+
json_data_get_default = response_default_engine.json()
72+
73+
log_response(json_data_get_default, "test_api_ge_engine_release_failed_invalid_engine")
74+
assert_equal(response_default_engine.status_code, 400)
75+
76+
assert_contains(json_data_get_default["message"], "Not Found")
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import pytest
2+
import requests
3+
from utils.test_runner import start_server, stop_server
4+
import jsonschema
5+
from tenacity import retry, wait_exponential, stop_after_attempt
6+
from utils.logger import log_response
7+
from utils.assertion import assert_equal, assert_contains
8+
9+
10+
class TestApiEngineReleaseLatest:
11+
12+
@pytest.fixture(autouse=True)
13+
def setup_and_teardown(self):
14+
# Setup
15+
success = start_server()
16+
if not success:
17+
raise Exception("Failed to start server")
18+
19+
yield
20+
21+
# Teardown
22+
stop_server()
23+
24+
def test_api_get_engine_release_latest_successfully(self):
25+
# Data test
26+
engine= "llama-cpp"
27+
get_release_url = f"http://localhost:3928/v1/engines/{engine}/releases/latest"
28+
29+
@retry(
30+
wait=wait_exponential(multiplier=2, min=2, max=30),
31+
stop=stop_after_attempt(5)
32+
)
33+
def get_request(url):
34+
response = requests.get(url)
35+
assert len(response.json()) > 0
36+
37+
get_request(get_release_url)
38+
39+
response_engine_release = requests.get(get_release_url)
40+
json_data = response_engine_release.json()
41+
42+
log_response(json_data, "test_api_get_engine_release_latest_successfully")
43+
assert_equal(response_engine_release.status_code, 200)
44+
45+
schema = {
46+
"$schema": "https://json-schema.org/draft/2020-12/schema",
47+
"type": "array",
48+
"items": {
49+
"type": "object",
50+
"properties": {
51+
"created_at": {
52+
"type": "string",
53+
"format": "date-time"
54+
},
55+
"download_count": {
56+
"type": "integer",
57+
"minimum": 0
58+
},
59+
"name": {
60+
"type": "string"
61+
},
62+
"size": {
63+
"type": "integer",
64+
"minimum": 0
65+
}
66+
},
67+
"required": ["created_at", "download_count", "name", "size"]
68+
}
69+
}
70+
71+
72+
# Validate response schema
73+
jsonschema.validate(instance=json_data, schema=schema)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
### e2e tests are expensive, have to keep engines tests in order
1919
from api.engines.test_api_get_list_engine import TestApiEngineList
2020
from api.engines.test_api_engine_install_nightly import TestApiEngineInstall
21+
from api.engines.test_api_get_default_engine import TestApiDefaultEngine
22+
from api.engines.test_api_get_engine_release import TestApiEngineRelease
23+
from api.engines.test_api_get_engine_release_latest import TestApiEngineReleaseLatest
2124
from api.model.test_api_model import TestApiModel
2225
from api.model.test_api_model_import import TestApiModelImport
2326

engine/e2e-test/runner/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
### e2e tests are expensive, have to keep engines tests in order
1919
from api.engines.test_api_get_list_engine import TestApiEngineList
2020
from api.engines.test_api_engine import TestApiEngine
21+
from api.engines.test_api_get_default_engine import TestApiDefaultEngine
22+
from api.engines.test_api_get_engine_release import TestApiEngineRelease
23+
from api.engines.test_api_get_engine_release_latest import TestApiEngineReleaseLatest
2124
from api.model.test_api_model import TestApiModel
2225
from api.model.test_api_model_import import TestApiModelImport
2326

engine/e2e-test/utils/assertion.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
def assert_equal(actual, expected):
22
"""Custom assertion to compare actual and expected values."""
3-
assert actual == expected, f"Assertion failed: Expected {expected}, but got {actual}"
3+
assert actual == expected, f"Assertion failed: Expected '{expected}', but got '{actual}'"
4+
5+
def assert_contains(main_string, sub_string):
6+
"""Custom assertion to compare actual and expected values."""
7+
assert sub_string in main_string, f"Assertion failed: Expected '{main_string}' has '{sub_string}'"

0 commit comments

Comments
 (0)