test_dashboard.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from fastapi.testclient import TestClient
  2. from exec_mcp.server import app
  3. from exec_mcp.repo import list_accounts
  4. client = TestClient(app)
  5. def test_health():
  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():
  10. payload = {
  11. 'display_name': 'synthetic-test-account',
  12. 'venue': 'bitstamp',
  13. 'venue_account_ref': 'synthetic-ref-001',
  14. 'api_key': 'synthetic-api-key-001',
  15. 'api_secret': 'synthetic-api-secret-001',
  16. 'description': 'test row',
  17. 'enabled': 'on',
  18. }
  19. resp = client.post('/dashboard/accounts/create', data=payload, follow_redirects=True)
  20. assert resp.status_code == 200, resp.text
  21. assert 'synthetic-test-account' in resp.text
  22. assert 'synthetic-ref-001' in resp.text
  23. resp = client.get('/dashboard')
  24. assert resp.status_code == 200
  25. assert '/dashboard/accounts/' in resp.text
  26. account_id = next(a['id'] for a in list_accounts(enabled_only=False) if a['venue_account_ref'] == 'synthetic-ref-001')
  27. resp = client.get(f'/dashboard/accounts/{account_id}/edit')
  28. assert resp.status_code == 200
  29. assert 'Edit account' in resp.text
  30. resp = client.post(
  31. f'/dashboard/accounts/{account_id}/update',
  32. data={'display_name': 'synthetic-test-account-updated', 'description': 'updated', 'enabled': 'on'},
  33. follow_redirects=True,
  34. )
  35. assert resp.status_code == 200
  36. assert 'synthetic-test-account-updated' in resp.text
  37. resp = client.post(f'/dashboard/accounts/{account_id}/delete', follow_redirects=True)
  38. assert resp.status_code == 200
  39. remaining = list_accounts(enabled_only=False)
  40. assert not any(a['id'] == account_id for a in remaining)