Skip to content

Commit

Permalink
fix(table-mode): correct the update of the `average_spilled_energy_co…
Browse files Browse the repository at this point in the history
…st` field in table mode (#2062)
  • Loading branch information
laurent-laporte-pro authored Jun 11, 2024
1 parent 3290eca commit 5555bab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 32 deletions.
2 changes: 1 addition & 1 deletion antarest/study/business/area_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def update_areas_props(
if old_area.average_spilled_energy_cost != new_area.average_spilled_energy_cost:
commands.append(
UpdateConfig(
target=f"input/thermal/areas/spilledenergycost:{area_id}",
target=f"input/thermal/areas/spilledenergycost/{area_id}",
data=new_area.average_spilled_energy_cost,
command_context=command_context,
)
Expand Down
51 changes: 20 additions & 31 deletions tests/integration/study_data_blueprint/test_table_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TestTableMode:
def test_lifecycle__nominal(
self, client: TestClient, user_access_token: str, study_id: str, study_version: int
) -> None:
user_headers = {"Authorization": f"Bearer {user_access_token}"}
client.headers = {"Authorization": f"Bearer {user_access_token}"}

# In order to test the table mode for renewable clusters and short-term storage,
# it is required that the study is either in version 8.1 for renewable energies
Expand All @@ -36,7 +36,6 @@ def test_lifecycle__nominal(
if study_version:
res = client.put(
f"/v1/studies/{study_id}/upgrade",
headers={"Authorization": f"Bearer {user_access_token}"},
params={"target_version": study_version},
)
assert res.status_code == 200, res.json()
Expand All @@ -53,10 +52,7 @@ def test_lifecycle__nominal(
# =================

# Get the schema of the areas table
res = client.get(
"/v1/table-schema/areas",
headers=user_headers,
)
res = client.get("/v1/table-schema/areas")
assert res.status_code == 200, res.json()
actual = res.json()
assert set(actual["properties"]) == {
Expand Down Expand Up @@ -88,7 +84,6 @@ def test_lifecycle__nominal(

res = client.put(
f"/v1/studies/{study_id}/table-mode/areas",
headers=user_headers,
json={
"de": _de_values,
"es": _es_values,
Expand Down Expand Up @@ -152,18 +147,31 @@ def test_lifecycle__nominal(
actual = res.json()
assert actual == expected_areas

res = client.get(f"/v1/studies/{study_id}/table-mode/areas", headers=user_headers)
res = client.get(f"/v1/studies/{study_id}/table-mode/areas")
assert res.status_code == 200, res.json()
actual = res.json()
assert actual == expected_areas

# Specific tests for averageSpilledEnergyCost and averageUnsuppliedEnergyCost
_de_values = {
"averageSpilledEnergyCost": 123,
"averageUnsuppliedEnergyCost": 456,
}
res = client.put(
f"/v1/studies/{study_id}/table-mode/areas",
json={"de": _de_values},
)
assert res.status_code == 200, res.json()
actual = res.json()["de"]
assert actual["averageSpilledEnergyCost"] == 123
assert actual["averageUnsuppliedEnergyCost"] == 456

# Table Mode - Links
# ==================

# Get the schema of the links table
res = client.get(
"/v1/table-schema/links",
headers=user_headers,
)
assert res.status_code == 200, res.json()
actual = res.json()
Expand All @@ -184,7 +192,6 @@ def test_lifecycle__nominal(

res = client.put(
f"/v1/studies/{study_id}/table-mode/links",
headers=user_headers,
json={
"de / fr": {
"colorRgb": "#FFA500",
Expand Down Expand Up @@ -280,7 +287,7 @@ def test_lifecycle__nominal(
del expected_result["de / it"]
assert actual == expected_result

res = client.get(f"/v1/studies/{study_id}/table-mode/links", headers=user_headers)
res = client.get(f"/v1/studies/{study_id}/table-mode/links")
assert res.status_code == 200, res.json()
actual = res.json()
# asserts the `de / it` link is not removed.
Expand All @@ -292,7 +299,6 @@ def test_lifecycle__nominal(
# Get the schema of the thermals table
res = client.get(
"/v1/table-schema/thermals",
headers=user_headers,
)
assert res.status_code == 200, res.json()
actual = res.json()
Expand Down Expand Up @@ -349,7 +355,6 @@ def test_lifecycle__nominal(

res = client.put(
f"/v1/studies/{study_id}/table-mode/thermals",
headers=user_headers,
json={
"de / 01_solar": _solar_values,
"de / 02_wind_on": _wind_on_values,
Expand Down Expand Up @@ -433,7 +438,6 @@ def test_lifecycle__nominal(

res = client.get(
f"/v1/studies/{study_id}/table-mode/thermals",
headers=user_headers,
params={"columns": ",".join(["group", "unitCount", "nominalCapacity", "so2"])},
)
assert res.status_code == 200, res.json()
Expand Down Expand Up @@ -497,7 +501,6 @@ def test_lifecycle__nominal(
}
res = client.post(
f"/v1/studies/{study_id}/commands",
headers={"Authorization": f"Bearer {user_access_token}"},
json=[{"action": "update_config", "args": args}],
)
assert res.status_code == 200, res.json()
Expand Down Expand Up @@ -557,15 +560,13 @@ def test_lifecycle__nominal(
for generator_id, generator in generators.items():
res = client.post(
f"/v1/studies/{study_id}/areas/{area_id}/clusters/renewable",
headers=user_headers,
json=generator,
)
res.raise_for_status()

# Get the schema of the renewables table
res = client.get(
"/v1/table-schema/renewables",
headers=user_headers,
)
assert res.status_code == 200, res.json()
actual = res.json()
Expand All @@ -584,7 +585,6 @@ def test_lifecycle__nominal(
# Update some generators using the table mode
res = client.put(
f"/v1/studies/{study_id}/table-mode/renewables",
headers=user_headers,
json={
"fr / Dieppe": {"enabled": False},
"fr / La Rochelle": {"enabled": True, "nominalCapacity": 3.1, "unitCount": 2},
Expand All @@ -595,7 +595,6 @@ def test_lifecycle__nominal(

res = client.get(
f"/v1/studies/{study_id}/table-mode/renewables",
headers=user_headers,
params={"columns": ",".join(["group", "enabled", "unitCount", "nominalCapacity"])},
)
assert res.status_code == 200, res.json()
Expand All @@ -618,7 +617,6 @@ def test_lifecycle__nominal(
# Get the schema of the short-term storages table
res = client.get(
"/v1/table-schema/st-storages",
headers=user_headers,
)
assert res.status_code == 200, res.json()
actual = res.json()
Expand Down Expand Up @@ -682,7 +680,6 @@ def test_lifecycle__nominal(
for storage_id, storage in storages.items():
res = client.post(
f"/v1/studies/{study_id}/areas/{area_id}/storages",
headers=user_headers,
json=storage,
)
res.raise_for_status()
Expand All @@ -696,7 +693,6 @@ def test_lifecycle__nominal(

res = client.put(
f"/v1/studies/{study_id}/table-mode/st-storages",
headers=user_headers,
json={
"fr / siemens": _fr_siemes_values,
"fr / tesla": _fr_tesla_values,
Expand Down Expand Up @@ -765,7 +761,6 @@ def test_lifecycle__nominal(

res = client.get(
f"/v1/studies/{study_id}/table-mode/st-storages",
headers=user_headers,
params={
"columns": ",".join(
[
Expand Down Expand Up @@ -816,7 +811,6 @@ def test_lifecycle__nominal(
fr_id = "fr"
res = client.post(
f"/v1/studies/{study_id}/areas/{fr_id}/clusters/thermal",
headers=user_headers,
json={
"name": "Cluster 1",
"group": "Nuclear",
Expand All @@ -835,7 +829,6 @@ def test_lifecycle__nominal(
"time_step": "hourly",
"operator": "less",
},
headers=user_headers,
)
assert res.status_code == 200, res.json()

Expand All @@ -849,14 +842,12 @@ def test_lifecycle__nominal(
"comments": "This is a binding constraint",
"filter_synthesis": "hourly, daily, weekly",
},
headers=user_headers,
)
assert res.status_code == 200, res.json()

# Get the schema of the binding constraints table
res = client.get(
"/v1/table-schema/binding-constraints",
headers=user_headers,
)
assert res.status_code == 200, res.json()
actual = res.json()
Expand Down Expand Up @@ -884,7 +875,6 @@ def test_lifecycle__nominal(

res = client.put(
f"/v1/studies/{study_id}/table-mode/binding-constraints",
headers=user_headers,
json={
"binding constraint 1": _bc1_values,
"binding constraint 2": _bc2_values,
Expand Down Expand Up @@ -920,7 +910,6 @@ def test_lifecycle__nominal(

res = client.get(
f"/v1/studies/{study_id}/table-mode/binding-constraints",
headers=user_headers,
params={"columns": ""},
)
assert res.status_code == 200, res.json()
Expand All @@ -933,8 +922,8 @@ def test_table_type_aliases(client: TestClient, user_access_token: str) -> None:
"""
Ensure that we can use the old table type aliases to get the schema of the tables.
"""
user_headers = {"Authorization": f"Bearer {user_access_token}"}
client.headers = {"Authorization": f"Bearer {user_access_token}"}
# do not use `pytest.mark.parametrize`, because it is too slow
for table_type in ["area", "link", "cluster", "renewable", "binding constraint"]:
res = client.get(f"/v1/table-schema/{table_type}", headers=user_headers)
res = client.get(f"/v1/table-schema/{table_type}")
assert res.status_code == 200, f"Failed to get schema for {table_type}: {res.json()}"

0 comments on commit 5555bab

Please sign in to comment.