mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
@@ -5,8 +5,9 @@ import pytest
|
||||
INSTALL_PATH = "/app"
|
||||
sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
|
||||
|
||||
from helper import get_setting_value
|
||||
from api_server.api_server_start import app
|
||||
from helper import get_setting_value # noqa: E402 [flake8 lint suppression]
|
||||
from api_server.api_server_start import app # noqa: E402 [flake8 lint suppression]
|
||||
|
||||
|
||||
# ----------------------------
|
||||
# Fixtures
|
||||
@@ -15,14 +16,17 @@ from api_server.api_server_start import app
|
||||
def api_token():
|
||||
return get_setting_value("API_TOKEN")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with app.test_client() as client:
|
||||
yield client
|
||||
|
||||
|
||||
def auth_headers(token):
|
||||
return {"Authorization": f"Bearer {token}"}
|
||||
|
||||
|
||||
# ----------------------------
|
||||
# Logs Endpoint Tests
|
||||
# ----------------------------
|
||||
@@ -31,16 +35,18 @@ def test_clean_log(client, api_token):
|
||||
assert resp.status_code == 200
|
||||
assert resp.json.get("success") is True
|
||||
|
||||
|
||||
def test_clean_log_not_allowed(client, api_token):
|
||||
resp = client.delete("/logs?file=not_allowed.log", headers=auth_headers(api_token))
|
||||
assert resp.status_code == 400
|
||||
assert resp.json.get("success") is False
|
||||
|
||||
|
||||
# ----------------------------
|
||||
# Execution Queue Endpoint Tests
|
||||
# ----------------------------
|
||||
def test_add_to_execution_queue(client, api_token):
|
||||
action_name = f"test_action_{random.randint(0,9999)}"
|
||||
action_name = f"test_action_{random.randint(0, 9999)}"
|
||||
resp = client.post(
|
||||
"/logs/add-to-execution-queue",
|
||||
json={"action": action_name},
|
||||
@@ -50,6 +56,7 @@ def test_add_to_execution_queue(client, api_token):
|
||||
assert resp.json.get("success") is True
|
||||
assert action_name in resp.json.get("message", "")
|
||||
|
||||
|
||||
def test_add_to_execution_queue_missing_action(client, api_token):
|
||||
resp = client.post(
|
||||
"/logs/add-to-execution-queue",
|
||||
|
||||
Reference in New Issue
Block a user