Skip to content

Commit c085d1d

Browse files
committed
feat: Return household JSON in household updater func and update test
1 parent 6487058 commit c085d1d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

policyengine_api/routes/household_routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def update_household(country_id: str, household_id: int) -> Response:
133133
raise NotFound(f"Household #{household_id} not found.")
134134

135135
# Next, update the household
136-
household_service.update_household(
136+
updated_household: dict = household_service.update_household(
137137
country_id, household_id, household_json, label
138138
)
139139
return Response(
@@ -143,6 +143,7 @@ def update_household(country_id: str, household_id: int) -> Response:
143143
"message": None,
144144
"result": {
145145
"household_id": household_id,
146+
"household_json": updated_household["household_json"],
146147
},
147148
}
148149
),

policyengine_api/services/household_service.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def update_household(
9090
household_id: str,
9191
household_json: dict,
9292
label: str,
93-
) -> None:
93+
) -> dict:
9494
"""
9595
Update a household with the given data.
9696
@@ -116,6 +116,12 @@ def update_household(
116116
household_id,
117117
),
118118
)
119+
120+
# Fetch the updated JSON back from the table
121+
updated_household: dict = self.get_household(
122+
country_id, household_id
123+
)
124+
return updated_household
119125
except Exception as e:
120126
print(
121127
f"Error updating household #{household_id}. Details: {str(e)}"

tests/python/test_household.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def test_update_household_success(
132132
assert response.status_code == 200
133133
assert data["status"] == "ok"
134134
assert data["result"]["household_id"] == "1"
135+
assert data["result"]["household_json"] == updated_data["data"]
135136

136137
def test_update_nonexistent_household(self, rest_client, mock_database):
137138
"""Test updating a non-existent household."""

0 commit comments

Comments
 (0)