add tests for machines api
This commit is contained in:
9
pkgs/clan-cli/tests/api.py
Normal file
9
pkgs/clan-cli/tests/api.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from clan_cli.webui.app import app
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def api() -> TestClient:
|
||||
return TestClient(app)
|
||||
@@ -4,6 +4,7 @@ import sys
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), "helpers"))
|
||||
|
||||
pytest_plugins = [
|
||||
"api",
|
||||
"temporary_dir",
|
||||
"clan_flake",
|
||||
"root",
|
||||
|
||||
21
pkgs/clan-cli/tests/test_api_machines.py
Normal file
21
pkgs/clan-cli/tests/test_api_machines.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from pathlib import Path
|
||||
|
||||
from api import TestClient
|
||||
|
||||
|
||||
def test_machines(api: TestClient, clan_flake: Path) -> None:
|
||||
response = api.get("/api/machines")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"machines": []}
|
||||
|
||||
response = api.post("/api/machines", json={"name": "test"})
|
||||
assert response.status_code == 201
|
||||
assert response.json() == {"machine": {"name": "test", "status": "unknown"}}
|
||||
|
||||
response = api.get("/api/machines/test")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"machine": {"name": "test", "status": "unknown"}}
|
||||
|
||||
response = api.get("/api/machines")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"machines": [{"name": "test", "status": "unknown"}]}
|
||||
Reference in New Issue
Block a user