From 55ae09431d236c514135191b37961e56797c9ca3 Mon Sep 17 00:00:00 2001 From: Allison Date: Mon, 27 Apr 2026 16:21:34 -0400 Subject: [PATCH] fix(marketing): add template_folder + tighten blueprint registration tests - Explicit template_folder on marketing/billing/legal blueprints prevents silent template fallback in Phase 2 - Replace vacuous test assertions (len>=0, substring '/' in r) with direct url_prefix and exact-match route checks (per code review I-1, I-2, I-3) --- src/billing/__init__.py | 8 +++++++- src/legal/__init__.py | 8 +++++++- src/marketing/__init__.py | 7 ++++++- tests/test_blueprint_registration.py | 28 ++++++++++++---------------- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/billing/__init__.py b/src/billing/__init__.py index 198bed2..7efd9a7 100644 --- a/src/billing/__init__.py +++ b/src/billing/__init__.py @@ -8,4 +8,10 @@ Routes added in Tasks B-2.7 (checkout) and B-2.8 (webhook). """ from flask import Blueprint -billing_bp = Blueprint('billing', __name__, url_prefix='/checkout') +billing_bp = Blueprint( + 'billing', + __name__, + url_prefix='/checkout', + template_folder='../../templates/billing', + static_folder=None, +) diff --git a/src/legal/__init__.py b/src/legal/__init__.py index b7a7a05..ffa13c6 100644 --- a/src/legal/__init__.py +++ b/src/legal/__init__.py @@ -8,4 +8,10 @@ Routes added in Task B-2.9. """ from flask import Blueprint -legal_bp = Blueprint('legal', __name__, url_prefix='/legal') +legal_bp = Blueprint( + 'legal', + __name__, + url_prefix='/legal', + template_folder='../../templates/legal', + static_folder=None, +) diff --git a/src/marketing/__init__.py b/src/marketing/__init__.py index bfdc56e..0fe7145 100644 --- a/src/marketing/__init__.py +++ b/src/marketing/__init__.py @@ -5,7 +5,12 @@ blueprints. Routes added incrementally in Phase 2 (Tasks A-2.x). """ from flask import Blueprint -marketing_bp = Blueprint('marketing', __name__) +marketing_bp = Blueprint( + 'marketing', + __name__, + template_folder='../../templates/marketing', + static_folder=None, +) # Import routes module so it registers route handlers via decorators from . import routes # noqa: E402,F401 diff --git a/tests/test_blueprint_registration.py b/tests/test_blueprint_registration.py index 75e290b..ca33980 100644 --- a/tests/test_blueprint_registration.py +++ b/tests/test_blueprint_registration.py @@ -39,28 +39,24 @@ def test_legal_blueprint_registered(): def test_marketing_landing_route_exists(): - """The marketing blueprint should expose at least a placeholder root route.""" + """Marketing blueprint must expose root '/' route.""" rules = [str(r) for r in app.url_map.iter_rules() if r.endpoint.startswith('marketing.')] - assert any('/' in r for r in rules), ( - f"Expected marketing blueprint to have a route, found: {rules}" + assert any(r == '/' for r in rules), ( + f"Expected marketing root route '/', found: {rules}" ) def test_legal_blueprint_has_url_prefix(): - """Legal blueprint should be mounted at /legal/* prefix.""" - rules = [str(r) for r in app.url_map.iter_rules() if r.endpoint.startswith('legal.')] - assert all('/legal' in r for r in rules), ( - f"Expected /legal/ prefix on all legal routes, found: {rules}" + """Legal blueprint must be mounted with /legal url_prefix.""" + assert 'legal' in app.blueprints + assert app.blueprints['legal'].url_prefix == '/legal', ( + f"Expected legal blueprint url_prefix='/legal', got {app.blueprints['legal'].url_prefix!r}" ) def test_billing_blueprint_has_url_prefix(): - """Billing blueprint should be mounted at /checkout/* prefix. - - Phase 1 minimum: blueprint is registered but may have no routes yet. - Routes added in B-2.7 (checkout) and B-2.8 (webhook). - """ - rules = [str(r) for r in app.url_map.iter_rules() if r.endpoint.startswith('billing.')] - # Allow billing routes that don't start with /checkout (e.g. /webhooks/stripe added later) - # but at least placeholder /checkout/ route should exist - assert len(rules) >= 0 # Phase 1 minimum: blueprint registered, routes added in B-2.7 + """Billing blueprint must be mounted with /checkout url_prefix.""" + assert 'billing' in app.blueprints + assert app.blueprints['billing'].url_prefix == '/checkout', ( + f"Expected billing blueprint url_prefix='/checkout', got {app.blueprints['billing'].url_prefix!r}" + )