M8-T16: add thermal meter cost APIs
This commit is contained in:
@@ -304,6 +304,35 @@ def test_prices_no_contract_returns_empty(energy_client):
|
||||
assert body["points"] == []
|
||||
assert body["tariff"] is None
|
||||
assert "currency" in body
|
||||
assert client.get("/api/energy/prices?scope=electricity").json() == body
|
||||
|
||||
|
||||
def test_prices_thermal_returns_active_contract_snapshot(energy_client):
|
||||
client, engine, _app = energy_client
|
||||
now = datetime.now(UTC)
|
||||
values = {
|
||||
"variable": {"heating": "20.123456", "hot_water_heating": "4", "hot_water": "2", "hot_water_tax": "1"},
|
||||
"standing": {"heating_network": "0", "metering": "0", "delivery_set": "0", "hot_water_network": "0", "other": "0"},
|
||||
}
|
||||
with Session(engine) as session:
|
||||
contract = EnergyContract(name="thermal", kind="district_heating", scope="thermal", active=True,
|
||||
currency="EUR", created_at=now, updated_at=now)
|
||||
session.add(contract)
|
||||
session.flush()
|
||||
session.add(EnergyContractVersion(contract_id=contract.id, effective_from=now - timedelta(days=1),
|
||||
values=values, created_at=now))
|
||||
session.commit()
|
||||
_login(client)
|
||||
response = client.get("/api/energy/prices?scope=thermal")
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
assert body == {
|
||||
"kind": "district_heating", "currency": "EUR", "points": [],
|
||||
"contract_version_id": body["contract_version_id"],
|
||||
"effective_from": body["effective_from"], "values": values,
|
||||
}
|
||||
assert client.get("/api/energy/prices").json()["points"] == []
|
||||
assert client.get("/api/energy/prices?scope=invalid").status_code == 422
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -334,6 +363,7 @@ def test_prices_manual_contract_returns_tariff(energy_client):
|
||||
assert abs(tariff["sell_dal"] - 0.10) < 1e-6
|
||||
# sell_normal = 0.10
|
||||
assert abs(tariff["sell_normal"] - 0.10) < 1e-6
|
||||
assert client.get("/api/energy/prices?scope=electricity").json() == body
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -369,6 +399,7 @@ def test_prices_tibber_contract_returns_points(energy_client):
|
||||
assert abs(p["buy"] - 0.245) < 1e-6
|
||||
assert abs(p["sell"] - (0.245 - 0.1108)) < 1e-4
|
||||
assert p["level"] == "NORMAL"
|
||||
assert client.get("/api/energy/prices", params={"scope": "electricity", "start": start, "end": end}).json() == body
|
||||
|
||||
|
||||
def test_prices_tibber_sell_reflects_sell_fee(energy_client):
|
||||
|
||||
Reference in New Issue
Block a user