"""Integration: API CRUD smoke test — Go/Gin backend. Validates core API flow: auth → list → create → read → update → delete.""" import pytest from httpx import AsyncClient from tests.conftest import auth_header class TestInstanceFlow: """Full instance lifecycle test.""" async def test_instance_crud_flow(self, client: AsyncClient, admin_token: str): import uuid suffix = uuid.uuid4().hex[:6] # Create resp = await client.post("/api/v1/instances", headers=auth_header(admin_token), json={ "name": f"crud-test-{suffix}", "db_type": "mysql", "host": "10.0.0.99", "port": 3306, "username": "root", }) assert resp.status_code == 201 inst = resp.json() inst_id = inst["id"] # Read resp = await client.get(f"/api/v1/instances/{inst_id}", headers=auth_header(admin_token)) assert resp.status_code == 200 assert resp.json()["name"] == f"crud-test-{suffix}" # Update resp = await client.put( f"/api/v1/instances/{inst_id}", headers=auth_header(admin_token), json={"name": f"updated-{suffix}"}, ) assert resp.status_code == 200 # Delete resp = await client.delete(f"/api/v1/instances/{inst_id}", headers=auth_header(admin_token)) assert resp.status_code == 200 # Verify deleted resp = await client.get(f"/api/v1/instances/{inst_id}", headers=auth_header(admin_token)) assert resp.status_code in (404, 400) class TestWorkflowFlow: """Full workflow lifecycle test.""" async def test_workflow_crud_flow(self, client: AsyncClient, admin_token: str): import uuid suffix = uuid.uuid4().hex[:6] # Create resp = await client.post("/api/v1/workflows", headers=auth_header(admin_token), json={ "name": f"crud-wf-{suffix}", "description": "CRUD test", "is_active": True, }) assert resp.status_code == 201 wf_id = resp.json()["id"] # Read resp = await client.get(f"/api/v1/workflows/{wf_id}", headers=auth_header(admin_token)) assert resp.status_code == 200 assert resp.json()["name"] == f"crud-wf-{suffix}" # Update resp = await client.put( f"/api/v1/workflows/{wf_id}", headers=auth_header(admin_token), json={"name": f"updated-wf-{suffix}", "description": "Updated"}, ) assert resp.status_code == 200 # Delete resp = await client.delete(f"/api/v1/workflows/{wf_id}", headers=auth_header(admin_token)) assert resp.status_code == 200 class TestDashboardEndpoints: """Dashboard endpoint smoke tests.""" async def test_dashboard_stats(self, client: AsyncClient, admin_token: str): resp = await client.get("/api/v1/dashboard/stats", headers=auth_header(admin_token)) assert resp.status_code == 200 async def test_my_tickets(self, client: AsyncClient, admin_token: str): resp = await client.get("/api/v1/dashboard/my-tickets", headers=auth_header(admin_token)) assert resp.status_code == 200