34 lines
956 B
Python
34 lines
956 B
Python
|
|
from fastapi.testclient import TestClient
|
||
|
|
from main import app
|
||
|
|
import sys
|
||
|
|
import os
|
||
|
|
|
||
|
|
# Add project root to sys.path
|
||
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||
|
|
|
||
|
|
client = TestClient(app)
|
||
|
|
|
||
|
|
def test_get_stats():
|
||
|
|
response = client.get("/server/process/stats")
|
||
|
|
print(f"Stats response status: {response.status_code}")
|
||
|
|
print(f"Stats response body: {response.json()}")
|
||
|
|
assert response.status_code == 200
|
||
|
|
data = response.json()
|
||
|
|
assert "pid" in data
|
||
|
|
assert "cpu_percent" in data
|
||
|
|
assert "memory_mb" in data
|
||
|
|
|
||
|
|
def test_control_invalid():
|
||
|
|
response = client.post("/server/process/invalid_action")
|
||
|
|
print(f"Invalid action response: {response.status_code}")
|
||
|
|
assert response.status_code == 400
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
print("Running API tests...")
|
||
|
|
try:
|
||
|
|
test_get_stats()
|
||
|
|
test_control_invalid()
|
||
|
|
print("Tests passed!")
|
||
|
|
except Exception as e:
|
||
|
|
print(f"Tests failed: {e}")
|