Skip to content

Commit

Permalink
test(clusters): add test for matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Mar 6, 2024
1 parent 9c2628b commit f3b8406
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 5 deletions.
30 changes: 29 additions & 1 deletion tests/integration/study_data_blueprint/test_renewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import json
import re

import numpy as np
import pytest
from starlette.testclient import TestClient

Expand Down Expand Up @@ -133,7 +134,23 @@ def test_lifecycle(
# RENEWABLE CLUSTER MATRICES
# =============================

# TODO: add unit tests for renewable cluster matrices
matrix = np.random.randint(0, 2, size=(8760, 1)).tolist()
matrix_path = f"input/renewables/series/{area_id}/{fr_solar_pv_id.lower()}/series"
args = {"target": matrix_path, "matrix": matrix}
res = client.post(
f"/v1/studies/{study_id}/commands",
json=[{"action": "replace_matrix", "args": args}],
headers={"Authorization": f"Bearer {user_access_token}"},
)
assert res.status_code in {200, 201}, res.json()

res = client.get(
f"/v1/studies/{study_id}/raw",
params={"path": matrix_path},
headers={"Authorization": f"Bearer {user_access_token}"},
)
assert res.status_code == 200
assert res.json()["data"] == matrix

# ==================================
# RENEWABLE CLUSTER LIST / GROUPS
Expand Down Expand Up @@ -221,13 +238,24 @@ def test_lifecycle(
f"/v1/studies/{study_id}/areas/{area_id}/renewable/{fr_solar_pv_id}?new_cluster_name={new_name}",
headers={"Authorization": f"Bearer {user_access_token}"},
)
# asserts the config is the same
assert res.status_code in {200, 201}
duplicated_config = copy.deepcopy(fr_solar_pv_cfg)
duplicated_config["name"] = new_name
duplicated_id = transform_name_to_id(new_name, lower=False)
duplicated_config["id"] = duplicated_id
assert res.json() == duplicated_config

# asserts the matrix has also been duplicated
new_cluster_matrix_path = f"input/renewables/series/{area_id}/{duplicated_id.lower()}/series"
res = client.get(
f"/v1/studies/{study_id}/raw",
params={"path": new_cluster_matrix_path},
headers={"Authorization": f"Bearer {user_access_token}"},
)
assert res.status_code == 200
assert res.json()["data"] == matrix

# =============================
# RENEWABLE CLUSTER DELETION
# =============================
Expand Down
17 changes: 14 additions & 3 deletions tests/integration/study_data_blueprint/test_st_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ def test_lifecycle__nominal(
# =============================

# updating the matrix of a short-term storage
array = np.random.rand(8760, 1) * 1000
array = np.random.randint(0, 1000, size=(8760, 1))
array_list = array.tolist()
res = client.put(
f"/v1/studies/{study_id}/areas/{area_id}/storages/{siemens_battery_id}/series/inflows",
headers={"Authorization": f"Bearer {user_access_token}"},
json={
"index": list(range(array.shape[0])),
"columns": list(range(array.shape[1])),
"data": array.tolist(),
"data": array_list,
},
)
assert res.status_code == 200, res.json()
Expand Down Expand Up @@ -242,11 +243,21 @@ def test_lifecycle__nominal(
headers={"Authorization": f"Bearer {user_access_token}"},
)
assert res.status_code in {200, 201}
# asserts the config is the same
duplicated_config = copy.deepcopy(siemens_config)
duplicated_config["name"] = new_name # type: ignore
duplicated_config["id"] = transform_name_to_id(new_name) # type: ignore
duplicated_id = transform_name_to_id(new_name)
duplicated_config["id"] = duplicated_id # type: ignore
assert res.json() == duplicated_config

# asserts the matrix has also been duplicated
res = client.get(
f"/v1/studies/{study_id}/areas/{area_id}/storages/{duplicated_id}/series/inflows",
headers={"Authorization": f"Bearer {user_access_token}"},
)
assert res.status_code == 200
assert res.json()["data"] == array_list

# =============================
# SHORT-TERM STORAGE DELETION
# =============================
Expand Down
30 changes: 29 additions & 1 deletion tests/integration/study_data_blueprint/test_thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import json
import re

import numpy as np
import pytest
from starlette.testclient import TestClient

Expand Down Expand Up @@ -456,7 +457,23 @@ def test_lifecycle(
# THERMAL CLUSTER MATRICES
# =============================

# TODO: add unit tests for thermal cluster matrices
matrix = np.random.randint(0, 2, size=(8760, 1)).tolist()
matrix_path = f"input/thermal/prepro/{area_id}/{fr_gas_conventional_id.lower()}/data"
args = {"target": matrix_path, "matrix": matrix}
res = client.post(
f"/v1/studies/{study_id}/commands",
json=[{"action": "replace_matrix", "args": args}],
headers={"Authorization": f"Bearer {user_access_token}"},
)
assert res.status_code in {200, 201}, res.json()

res = client.get(
f"/v1/studies/{study_id}/raw",
params={"path": matrix_path},
headers={"Authorization": f"Bearer {user_access_token}"},
)
assert res.status_code == 200
assert res.json()["data"] == matrix

# ==================================
# THERMAL CLUSTER LIST / GROUPS
Expand Down Expand Up @@ -547,12 +564,23 @@ def test_lifecycle(
headers={"Authorization": f"Bearer {user_access_token}"},
)
assert res.status_code in {200, 201}
# asserts the config is the same
duplicated_config = copy.deepcopy(fr_gas_conventional_cfg)
duplicated_config["name"] = new_name # type: ignore
duplicated_id = transform_name_to_id(new_name, lower=False)
duplicated_config["id"] = duplicated_id # type: ignore
assert res.json() == duplicated_config

# asserts the matrix has also been duplicated
new_cluster_matrix_path = f"input/thermal/prepro/{area_id}/{duplicated_id.lower()}/data"
res = client.get(
f"/v1/studies/{study_id}/raw",
params={"path": new_cluster_matrix_path},
headers={"Authorization": f"Bearer {user_access_token}"},
)
assert res.status_code == 200
assert res.json()["data"] == matrix

# =============================
# THERMAL CLUSTER DELETION
# =============================
Expand Down

0 comments on commit f3b8406

Please sign in to comment.