Skip to content

Commit

Permalink
Merge pull request #74 from PolicyEngine/feat/add_demo_endpoint
Browse files Browse the repository at this point in the history
Added calculate_demo endpoint for use on API documentation page
  • Loading branch information
anth-volk authored Feb 2, 2024
2 parents fdaf673 + 63f5b6e commit 5ab4886
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: patch
changes:
changed:
- Added calculate_demo endpoint for use on API documentation page
7 changes: 7 additions & 0 deletions policyengine_household_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sqlalchemy.orm import DeclarativeBase
from dotenv import load_dotenv
from authlib.integrations.flask_oauth2 import ResourceProtector
from ratelimiter import RateLimiter

# Internal imports
from .auth.validation import Auth0JWTBearerTokenValidator
Expand Down Expand Up @@ -92,4 +93,10 @@ def readiness_check():
)


@app.route("/<country_id>/calculate_demo", methods=["POST"])
@RateLimiter(max_calls=1, period=1)
def calculate_demo(country_id):
return get_calculate(country_id)


print("API initialised.")
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"python-dotenv",
"pymysql",
"black==22.12.0", # This is because policyengine_canada uses black<23
"ratelimiter",
],
extras_require={
"dev": [
Expand Down
26 changes: 26 additions & 0 deletions tests/python/test_calculate_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest
import os
from tests.python.utils import client
from policyengine_household_api.api import app


def test_calc_demo(client):
"""
Ensure that calculate_demo properly calculates;
the rate limiter does not return a 4xx, but instead
waits until the rate limit has ended, preventing the
need for a further test
"""

response = client.post(
"/us/calculate_demo",
headers={
"Content-Type": "application/json",
},
data=open(
"./tests/python/data/calculate_us_1_data.json",
"r",
encoding="utf-8",
),
)
assert response.status_code == 200, response.text

0 comments on commit 5ab4886

Please sign in to comment.