Skip to content

Commit

Permalink
test: add unit test to check that RHS matrices are renamed according …
Browse files Browse the repository at this point in the history
…to update rules
  • Loading branch information
laurent-laporte-pro committed Jun 28, 2024
1 parent 16cbadd commit f3b5f93
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 141 deletions.
36 changes: 25 additions & 11 deletions tests/integration/prepare_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def generate_snapshot(self, variant_id: str, denormalize: bool = False, from_scr
task = wait_task_completion(self.client, self.user_access_token, task_id, timeout=20)
assert task.status == TaskStatus.COMPLETED

def create_area(self, study_id: str, *, name: str, country: str = "FR") -> str:
def create_area(self, study_id: str, *, name: str, country: str = "FR") -> t.Dict[str, t.Any]:
"""
Create an area in a study.
Expand All @@ -174,16 +174,16 @@ def create_area(self, study_id: str, *, name: str, country: str = "FR") -> str:
country: Country of the area.
Returns:
The ID of the created area.
The area properties.
"""
res = self.client.post(
f"/v1/studies/{study_id}/areas",
headers=self.headers,
json={"name": name, "type": "AREA", "metadata": {"country": country}},
)
res.raise_for_status()
area_id = t.cast(str, res.json()["id"])
return area_id
properties = t.cast(t.Dict[str, t.Any], res.json())
return properties

def update_general_data(self, study_id: str, **data: t.Any) -> None:
"""
Expand All @@ -200,7 +200,7 @@ def update_general_data(self, study_id: str, **data: t.Any) -> None:
)
res.raise_for_status()

def create_link(self, study_id: str, area1_id: str, area2_id: str) -> str:
def create_link(self, study_id: str, area1_id: str, area2_id: str) -> t.Dict[str, t.Any]:
"""
Create a link between two areas in a study.
Expand All @@ -210,7 +210,7 @@ def create_link(self, study_id: str, area1_id: str, area2_id: str) -> str:
area2_id: The ID of the second area.
Returns:
The ID of the created link.
The link properties.
"""
# Create a link between the two areas
res = self.client.post(
Expand All @@ -219,10 +219,11 @@ def create_link(self, study_id: str, area1_id: str, area2_id: str) -> str:
json={"area1": area1_id, "area2": area2_id},
)
assert res.status_code == 200, res.json()
link_id = f"{area1_id}%{area2_id}"
return link_id
properties = t.cast(t.Dict[str, t.Any], res.json())
properties["id"] = f"{area1_id}%{area2_id}"
return properties

def create_thermal(self, study_id: str, area1_id: str, *, name: str, **kwargs: t.Any) -> str:
def create_thermal(self, study_id: str, area1_id: str, *, name: str, **kwargs: t.Any) -> t.Dict[str, t.Any]:
"""
Create a thermal cluster in an area.
Expand All @@ -231,15 +232,18 @@ def create_thermal(self, study_id: str, area1_id: str, *, name: str, **kwargs: t
area1_id: The ID of the area.
name: The name of the cluster.
**kwargs: Additional cluster data.
Returns:
The cluster properties.
"""
res = self.client.post(
f"/v1/studies/{study_id}/areas/{area1_id}/clusters/thermal",
headers=self.headers,
json={"name": name, **kwargs},
)
res.raise_for_status()
cluster_id = t.cast(str, res.json()["id"])
return cluster_id
properties = t.cast(t.Dict[str, t.Any], res.json())
return properties

def get_thermals(self, study_id: str, area1_id: str) -> t.List[t.Dict[str, t.Any]]:
"""
Expand Down Expand Up @@ -327,3 +331,13 @@ def get_binding_constraints(self, study_id: str) -> t.List[t.Dict[str, t.Any]]:
res.raise_for_status()
binding_constraints_list = t.cast(t.List[t.Dict[str, t.Any]], res.json())
return binding_constraints_list

def drop_all_commands(self, variant_id: str) -> None:
"""
Drop all commands of a variant.
Args:
variant_id: The ID of the variant.
"""
res = self.client.delete(f"/v1/studies/{variant_id}/commands", headers=self.headers)
res.raise_for_status()
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_download_matrices(self, client: TestClient, user_access_token: str, stu
variant_id = preparer.create_variant(study_820_id, name="New Variant")

# Create a new area to implicitly create normalized matrices
area_id = preparer.create_area(variant_id, name="Mayenne", country="France")
area_id = preparer.create_area(variant_id, name="Mayenne", country="France")["id"]

# Change study start_date
preparer.update_general_data(variant_id, firstMonth="July")
Expand Down
Loading

0 comments on commit f3b5f93

Please sign in to comment.