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

Added calculate_demo endpoint for use on API documentation page #74

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading