diff --git a/functions/submit_order/handler.py b/functions/submit_order/handler.py index b022c5e..5f3efb2 100644 --- a/functions/submit_order/handler.py +++ b/functions/submit_order/handler.py @@ -220,9 +220,7 @@ def handle_publish_settings(): return response( 200, { - "bulk_discount_percent": float( - settings.get("bulk_discount_percent", 0) - ), + "bulk_discount_percent": float(settings.get("bulk_discount_percent", 0)), "company_subsidy_percent": float( settings.get("company_subsidy_percent", 0) ), @@ -236,14 +234,14 @@ def handle_publish_menu(event): body = json.loads(event.get("body", "{}")) except json.JSONDecodeError: return response(400, {"error": "Invalid JSON"}) - + if not isinstance(body, dict): return response(400, {"error": "Request body must be a JSON object"}) - + meals = body.get("meals") if not isinstance(meals, list) or not meals: return response(400, {"error": "At least one meal is required"}) - + for meal in meals: price = meal.get("price") if isinstance(meal, dict) else None if ( @@ -256,7 +254,7 @@ def handle_publish_menu(event): return response( 400, {"error": "Each meal requires a name and non-negative price"} ) - + week = current_week() menu = { "scraped_at": body.get("scraped_at"), diff --git a/scripts/upload_menu.py b/scripts/upload_menu.py index 15520f9..b9b5f12 100644 --- a/scripts/upload_menu.py +++ b/scripts/upload_menu.py @@ -39,7 +39,7 @@ def signed_request( SigV4Auth(credentials.get_frozen_credentials(), "execute-api", region).add_auth( request ) - + prepared = request.prepare() http_request = urllib.request.Request( prepared.url, @@ -52,13 +52,13 @@ def signed_request( return json.loads(response.read()) except urllib.error.HTTPError as exc: detail = exc.read().decode(errors="replace") - raise RuntimeError(f"Publication API returned HTTP {exc.code}: {detail}") from exc + raise RuntimeError( + f"Publication API returned HTTP {exc.code}: {detail}" + ) from exc def get_settings(api_url: str, region: str) -> dict: - return signed_request( - api_url, "/api/publish/settings", method="GET", region=region - ) + return signed_request(api_url, "/api/publish/settings", method="GET", region=region) def publish_menu(api_url: str, region: str) -> dict: @@ -81,9 +81,7 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument("action", choices=("settings", "publish")) parser.add_argument("--api-url", required=True) - parser.add_argument( - "--region", default=os.environ.get("AWS_REGION", "us-east-1") - ) + parser.add_argument("--region", default=os.environ.get("AWS_REGION", "us-east-1")) args = parser.parse_args() try: diff --git a/tests/test_generate_form.py b/tests/test_generate_form.py index 04658f6..dd07dce 100644 --- a/tests/test_generate_form.py +++ b/tests/test_generate_form.py @@ -189,16 +189,16 @@ class TestGenerateFormStructural: if route == "/api/publish/settings" else " AdminOrders:" ) - route_config = template.split(f"Path: {route}", 1)[1].split( - next_event, 1 - )[0] + route_config = template.split(f"Path: {route}", 1)[1].split(next_event, 1)[ + 0 + ] assert "Authorizer: AWS_IAM" in route_config assert route in script assert "scripts/upload_menu.py settings" in workflow assert "scripts/upload_menu.py publish" in workflow assert "aws dynamodb" not in workflow - assert "boto3.resource(\"dynamodb\")" not in script + assert 'boto3.resource("dynamodb")' not in script def test_local_and_google_render(self): local = _render(google=False)