style(python): apply Ruff formatting

This commit is contained in:
Adam Moussa 2026-08-03 14:24:54 -04:00
parent 308f46eafd
commit 7e4bccc804
No known key found for this signature in database
3 changed files with 15 additions and 19 deletions

View file

@ -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"),

View file

@ -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:

View file

@ -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)