diff --git a/.vscode/settings.json b/.vscode/settings.json index 65a6d92..133e687 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,10 +1,56 @@ { - "python.testing.pytestArgs": [ - "tests" - ], - "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true, - "python.analysis.typeCheckingMode": "basic", - "python.terminal.activateEnvironment": true, - "python-envs.defaultEnvManager": "uv", + "editor.formatOnSave": true, + "[python]": { + "editor.defaultFormatter": "charliermarsh.ruff", + "editor.codeActionsOnSave": { + "source.fixAll": "explicit", + "source.organizeImports": "explicit" + } + }, + "[json]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "notebook.formatOnSave.enabled": true, + "notebook.codeActionsOnSave": { + // "notebook.source.fixAll": "explicit", + // "notebook.source.organizeImports": "explicit" + }, + "notebook.output.wordWrap": true, + "notebook.output.textLineLimit": 200, + "jupyter.debugJustMyCode": false, + "python.testing.pytestEnabled": true, + "python.testing.pytestArgs": [ + "tests" + ], + "files.exclude": { + "**/*.egg-info": true, + "**/htmlcov": true, + "**/~$*": true, + "**/.coverage.*": true, + "**/.venv": true, + "**/__pycache__": true, + "**/.mypy_cache": true, + "**/.pytest_cache": true, + } +} + +// .vscode/launch.json +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Debug Tests", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "purpose": [ + "debug-test" + ], + "console": "integratedTerminal", + "justMyCode": false, + "env": { + "PYTEST_ADDOPTS": "--no-cov" + } + } + ] } \ No newline at end of file diff --git a/src/alpine_bits_python/api.py b/src/alpine_bits_python/api.py index 4947695..7865c25 100644 --- a/src/alpine_bits_python/api.py +++ b/src/alpine_bits_python/api.py @@ -9,13 +9,7 @@ from functools import partial from typing import Any import httpx -from fastapi import ( - APIRouter, - Depends, - FastAPI, - HTTPException, - Request, -) +from fastapi import APIRouter, Depends, FastAPI, HTTPException, Request from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import HTMLResponse, Response from fastapi.security import HTTPBasic, HTTPBasicCredentials @@ -28,22 +22,12 @@ from .alpinebits_server import ( AlpineBitsServer, Version, ) -from .auth import ( - generate_api_key, - generate_unique_id, - validate_api_key, -) +from .auth import generate_api_key, generate_unique_id, validate_api_key from .config_loader import load_config -from .db import ( - Base, - get_database_url, -) -from .db import ( - Customer as DBCustomer, -) -from .db import ( - Reservation as DBReservation, -) +from .db import Base +from .db import Customer as DBCustomer +from .db import Reservation as DBReservation +from .db import get_database_url from .rate_limit import ( BURST_RATE_LIMIT, DEFAULT_RATE_LIMIT, @@ -326,8 +310,7 @@ async def health_check(request: Request): # Extracted business logic for handling Wix form submissions async def process_wix_form_submission(request: Request, data: dict[str, Any], db): - """Shared business logic for handling Wix form submissions (test and production). - """ + """Shared business logic for handling Wix form submissions (test and production).""" timestamp = datetime.now().isoformat() _LOGGER.info(f"Received Wix form data at {timestamp}") @@ -807,6 +790,11 @@ async def alpinebits_server_handshake( "X-AlpineBits-Server-Version": "2024-10", } + if is_compressed: + # Compress response if client sent compressed request + response_xml = gzip.compress(response_xml.encode("utf-8")) + headers["Content-Encoding"] = "gzip" + return Response( content=response_xml, status_code=response.status_code, headers=headers ) @@ -847,12 +835,9 @@ app.include_router(api_router) @app.get("/", response_class=HTMLResponse) async def landing_page(): - """Serve the under construction landing page at the root route - """ + """Serve the under construction landing page at the root route.""" try: # Get the path to the HTML file - import os - html_path = os.path.join(os.path.dirname(__file__), "templates", "index.html") with open(html_path, encoding="utf-8") as f: