| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- from fastapi.testclient import TestClient
- from exec_mcp.server import app
- from exec_mcp import repo, storage
- def test_health():
- with TestClient(app) as client:
- resp = client.get('/health')
- assert resp.status_code == 200
- assert resp.json() == {'ok': True, 'server': 'exec-mcp'}
- def test_dashboard_account_crud_roundtrip(tmp_path, monkeypatch):
- db_path = tmp_path / "exec.sqlite3"
- monkeypatch.setattr(storage, "DB_PATH", db_path)
- storage.init_db()
- with TestClient(app) as client:
- 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 repo.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 = repo.list_accounts(enabled_only=False)
- assert not any(a['id'] == account_id for a in remaining)
|