mirror of
https://github.com/azaion/detections.git
synced 2026-04-22 22:36:32 +00:00
86b8f076b7
- Modified the health endpoint to return "None" for AI availability when inference is not initialized, improving clarity on system status. - Enhanced the test documentation to include handling of skipped tests, emphasizing the need for investigation before proceeding. - Updated test assertions to ensure proper execution order and prevent premature engine initialization. - Refactored test cases to streamline performance testing and improve readability, removing unnecessary complexity. These changes aim to enhance the robustness of the health check and improve the overall testing framework.
50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
import os
|
|
|
|
import pytest
|
|
import requests
|
|
|
|
|
|
def test_nft_sec_01_malformed_multipart(base_url, http_client):
|
|
url = f"{base_url.rstrip('/')}/detect"
|
|
r1 = requests.post(
|
|
url,
|
|
data=b"not-multipart-body",
|
|
headers={"Content-Type": "multipart/form-data"},
|
|
timeout=30,
|
|
)
|
|
assert r1.status_code in (400, 422)
|
|
r2 = requests.post(
|
|
url,
|
|
data=b"does-not-match-boundary",
|
|
headers={"Content-Type": "multipart/form-data; boundary=----abc"},
|
|
timeout=30,
|
|
)
|
|
assert r2.status_code in (400, 422)
|
|
r3 = requests.post(
|
|
url,
|
|
files={"file": ("", b"", "")},
|
|
timeout=30,
|
|
)
|
|
assert r3.status_code in (400, 422)
|
|
assert http_client.get("/health").status_code == 200
|
|
|
|
|
|
@pytest.mark.slow
|
|
@pytest.mark.timeout(300)
|
|
def test_nft_sec_02_oversized_request(http_client):
|
|
large = os.urandom(50 * 1024 * 1024)
|
|
try:
|
|
r = http_client.post(
|
|
"/detect",
|
|
files={"file": ("large.jpg", large, "image/jpeg")},
|
|
timeout=180,
|
|
)
|
|
except requests.RequestException:
|
|
pass
|
|
else:
|
|
assert r.status_code != 500
|
|
assert r.status_code in (413, 400, 422)
|
|
assert http_client.get("/health").status_code == 200
|
|
|
|
|