from fastapi.testclient import TestClient from exec_mcp.server import app from exec_mcp.repo import list_accounts client = TestClient(app) def test_health(): resp = client.get('/health') assert resp.status_code == 200 assert resp.json() == {'ok': True, 'server': 'exec-mcp'} def test_dashboard_account_crud_roundtrip(): payload = { 'display_name': 'synthetic-test-account', 'venue': 'bitstamp', 'venue_account_ref': 'synthetic-ref-001', 'api_key': 'synthetic-api-key-001', 'api_secret': 'synthetic-api-secret-001', 'description': 'test row', 'enabled': 'on', } resp = client.post('/dashboard/accounts/create', data=payload, follow_redirects=True) assert resp.status_code == 200, resp.text assert 'synthetic-test-account' in resp.text assert 'synthetic-ref-001' in resp.text resp = client.get('/dashboard') assert resp.status_code == 200 assert '/dashboard/accounts/' in resp.text account_id = next(a['id'] for a in list_accounts(enabled_only=False) if a['venue_account_ref'] == 'synthetic-ref-001') resp = client.get(f'/dashboard/accounts/{account_id}/edit') assert resp.status_code == 200 assert 'Edit account' in resp.text resp = client.post( f'/dashboard/accounts/{account_id}/update', data={'display_name': 'synthetic-test-account-updated', 'description': 'updated', 'enabled': 'on'}, follow_redirects=True, ) assert resp.status_code == 200 assert 'synthetic-test-account-updated' in resp.text resp = client.post(f'/dashboard/accounts/{account_id}/delete', follow_redirects=True) assert resp.status_code == 200 remaining = list_accounts(enabled_only=False) assert not any(a['id'] == account_id for a in remaining)