Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate policy endpoints to new API structure #2025

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

anth-volk
Copy link
Collaborator

Fixes #1987.

This migrates the policy endpoints to the new API structure. It also adds a series of unit tests to the new service.

@@ -12,7 +12,9 @@

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question, maybe blocking - I don't think, as currently written, this type is correct. I believe it's always str unless you use the <int:whatever> syntax

Assuming I'm correct, the suggestion is to either change the path or change the type to str. If not, excited to learn:)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire route/service combo was the first one I did, prior to many of your incredibly helpful suggestions & improvements. Let me more broadly bring this up to snuff as part of this PR.

policyengine_api/routes/policy_routes.py Show resolved Hide resolved
policyengine_api/routes/policy_routes.py Outdated Show resolved Hide resolved
policyengine_api/routes/policy_routes.py Outdated Show resolved Hide resolved
status=404,
)
else:
return Response(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment, non-blocking - again just referencing #2038 on

  1. Consistency of return values structure and
  2. globally handling exception/response mapping instead of writing one in every handler.

tests/python/test_policy_service.py Outdated Show resolved Hide resolved
tests/python/test_policy_service.py Outdated Show resolved Hide resolved
Comment on lines +49 to +51
assert result is not None
assert isinstance(result["policy_json"], dict)
assert result["policy_json"]["param"] == "value"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion, non-blocking I think you can do all this in one go with assertpy's assert_that? (not something I've used a ton). see dict-comparison

assert message == "Policy created"
assert exists is False
assert (
mock_database.query.call_count == 3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion, non-blocking I would personally just check the calls directly instead of count. (i.e. verify it made each query against the expected string). It doesn't involve much more work and it can catch issues (I.e. if I inject the wrong value into the query, etc.)

tests/python/test_yearly_var_removal.py Outdated Show resolved Hide resolved
@anth-volk anth-volk force-pushed the feat/1987-migrate-policy branch from 5a9669b to 979037a Compare January 17, 2025 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate policy endpoints to new API structure
2 participants