test_dashboard.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from fastapi.testclient import TestClient
  2. from exec_mcp.server import app
  3. from exec_mcp import repo, storage
  4. def test_health():
  5. with TestClient(app) as client:
  6. resp = client.get('/health')
  7. assert resp.status_code == 200
  8. assert resp.json() == {'ok': True, 'server': 'exec-mcp'}
  9. def test_dashboard_account_crud_roundtrip(tmp_path, monkeypatch):
  10. db_path = tmp_path / "exec.sqlite3"
  11. monkeypatch.setattr(storage, "DB_PATH", db_path)
  12. storage.init_db()
  13. with TestClient(app) as client:
  14. payload = {
  15. 'display_name': 'synthetic-test-account',
  16. 'venue': 'bitstamp',
  17. 'venue_account_ref': 'synthetic-ref-001',
  18. 'api_key': 'synthetic-api-key-001',
  19. 'api_secret': 'synthetic-api-secret-001',
  20. 'description': 'test row',
  21. 'enabled': 'on',
  22. }
  23. resp = client.post('/dashboard/accounts/create', data=payload, follow_redirects=True)
  24. assert resp.status_code == 200, resp.text
  25. assert 'synthetic-test-account' in resp.text
  26. assert 'synthetic-ref-001' in resp.text
  27. resp = client.get('/dashboard')
  28. assert resp.status_code == 200
  29. assert '/dashboard/accounts/' in resp.text
  30. account_id = next(a['id'] for a in repo.list_accounts(enabled_only=False) if a['venue_account_ref'] == 'synthetic-ref-001')
  31. resp = client.get(f'/dashboard/accounts/{account_id}/edit')
  32. assert resp.status_code == 200
  33. assert 'Edit account' in resp.text
  34. resp = client.post(
  35. f'/dashboard/accounts/{account_id}/update',
  36. data={'display_name': 'synthetic-test-account-updated', 'description': 'updated', 'enabled': 'on'},
  37. follow_redirects=True,
  38. )
  39. assert resp.status_code == 200
  40. assert 'synthetic-test-account-updated' in resp.text
  41. resp = client.post(f'/dashboard/accounts/{account_id}/delete', follow_redirects=True)
  42. assert resp.status_code == 200
  43. remaining = repo.list_accounts(enabled_only=False)
  44. assert not any(a['id'] == account_id for a in remaining)