Files
ems-core/backend/tests/test_monitoring.py
Du Wenbo 92ec910a13 ems-core v1.0.0: Standard EMS platform core
Shared backend + frontend for multi-customer EMS deployments.
- 12 enterprise modules: quota, cost, charging, maintenance, analysis, etc.
- 120+ API endpoints, 37 database tables
- Customer config mechanism (CUSTOMER env var + YAML config)
- Collectors: Modbus TCP, MQTT, HTTP API, Sungrow iSolarCloud
- Frontend: React 19 + Ant Design + ECharts + Three.js
- Infrastructure: Redis cache, rate limiting, aggregation engine

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 18:14:11 +08:00

45 lines
1.6 KiB
Python

import pytest
from conftest import auth_header
class TestDeviceRealtime:
async def test_get_device_realtime(self, client, admin_user, admin_token, seed_devices, seed_energy_data):
device = seed_devices[0]
resp = await client.get(
f"/api/v1/monitoring/devices/{device.id}/realtime",
headers=auth_header(admin_token),
)
assert resp.status_code == 200
body = resp.json()
assert "device" in body
assert "data" in body
assert body["device"]["id"] == device.id
async def test_get_device_realtime_no_device(self, client, admin_user, admin_token):
resp = await client.get(
"/api/v1/monitoring/devices/99999/realtime",
headers=auth_header(admin_token),
)
assert resp.status_code == 200
body = resp.json()
assert body["device"] is None
async def test_get_device_realtime_unauthenticated(self, client):
resp = await client.get("/api/v1/monitoring/devices/1/realtime")
assert resp.status_code == 401
class TestEnergyFlow:
async def test_get_energy_flow(self, client, admin_user, admin_token, seed_devices, seed_energy_data):
resp = await client.get("/api/v1/monitoring/energy-flow", headers=auth_header(admin_token))
assert resp.status_code == 200
body = resp.json()
assert "nodes" in body
assert "links" in body
assert len(body["nodes"]) == 4
assert len(body["links"]) == 4
async def test_get_energy_flow_unauthenticated(self, client):
resp = await client.get("/api/v1/monitoring/energy-flow")
assert resp.status_code == 401