Skip to content

Commit

Permalink
fix: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anth-volk committed Nov 27, 2024
1 parent b46cc3a commit 43d4863
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion policyengine_api/routes/economy_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

@validate_country
@economy_bp.route("/<policy_id>/over/<baseline_policy_id>", methods=["GET"])
def get_economic_impact(country_id: str, policy_id: str | int, baseline_policy_id: str | int):
def get_economic_impact(
country_id: str, policy_id: str | int, baseline_policy_id: str | int
):

policy_id = int(policy_id or get_current_law_policy_id(country_id))
baseline_policy_id = int(
Expand Down
10 changes: 6 additions & 4 deletions policyengine_api/services/policy_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ def get_policy(self, country_id: str, policy_id: int) -> dict | None:

try:
# If no policy found, this will return None
row: LegacyRow = database.query(
row: LegacyRow | None = database.query(
"SELECT * FROM policy WHERE country_id = ? AND id = ?",
(country_id, policy_id),
).fetchone()

# policy_json is JSON and must be loaded, if present; to enable,
# we must convert the row to a dictionary
policy = dict(row)
if policy and policy["policy_json"]:
policy["policy_json"] = json.loads(policy["policy_json"])
policy = None
if row:
policy = dict(row)
if policy["policy_json"]:
policy["policy_json"] = json.loads(policy["policy_json"])
return policy
except Exception as e:
print(f"Error getting policy: {str(e)}")
Expand Down

0 comments on commit 43d4863

Please sign in to comment.