diff --git a/tests/integration/study_data_blueprint/test_renewable.py b/tests/integration/study_data_blueprint/test_renewable.py index 498a5b44dd..6737f53119 100644 --- a/tests/integration/study_data_blueprint/test_renewable.py +++ b/tests/integration/study_data_blueprint/test_renewable.py @@ -27,6 +27,7 @@ import json import re +import numpy as np import pytest from starlette.testclient import TestClient @@ -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 @@ -221,6 +238,7 @@ 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 @@ -228,6 +246,16 @@ def test_lifecycle( 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 # ============================= diff --git a/tests/integration/study_data_blueprint/test_st_storage.py b/tests/integration/study_data_blueprint/test_st_storage.py index 8b1c8d162d..fbe8c89e33 100644 --- a/tests/integration/study_data_blueprint/test_st_storage.py +++ b/tests/integration/study_data_blueprint/test_st_storage.py @@ -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() @@ -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 # ============================= diff --git a/tests/integration/study_data_blueprint/test_thermal.py b/tests/integration/study_data_blueprint/test_thermal.py index 7514c6dfe6..43b3c1903c 100644 --- a/tests/integration/study_data_blueprint/test_thermal.py +++ b/tests/integration/study_data_blueprint/test_thermal.py @@ -31,6 +31,7 @@ import json import re +import numpy as np import pytest from starlette.testclient import TestClient @@ -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 @@ -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 # =============================