"""App-factory tests: route registration and endpoint names are intact. These guard the Phase 1 refactor (module-level ``app`` → ``create_app()`` with routes split under ``routes/`` and ``blueprints/``). They assert that the endpoints referenced by templates via ``url_for(...)`` still resolve in the Flask url_map. Runs against in-memory SQLite (no Postgres). """ import pytest # Endpoints that templates reference via url_for(...) and that must survive # the factory refactor. Sourced from the Jinja templates. TEMPLATE_ENDPOINTS = [ "login", "signup", "admin_setup", "logout", "serve_logo", "serve_theme", "static", # API blueprint endpoints (mounted at /api/v1) "api.posts", "api.post_detail", "api.comments", "api.filters", "api.bookmarks", "api.platforms", ] def test_create_app_returns_flask_app(app): from flask import Flask assert isinstance(app, Flask) def test_api_blueprint_mounted_under_v1(app): rules = [r.rule for r in app.url_map.iter_rules()] assert any(r.startswith("/api/v1/posts") for r in rules), rules assert any(r.startswith("/api/v1/comments") for r in rules), rules @pytest.mark.parametrize("endpoint", TEMPLATE_ENDPOINTS) def test_template_endpoints_exist(app, endpoint): # Flask stores endpoints as "." for blueprint views and # bare names for app-level views. ``url_map`` has both. all_endpoints = {r.endpoint for r in app.url_map.iter_rules()} assert endpoint in all_endpoints, ( f"endpoint '{endpoint}' missing from url_map; have: {sorted(all_endpoints)[:20]}..." ) def test_no_module_level_app_object(): """Phase 1 removed the module-level ``app``; importing app.py must not start a server or expose a global Flask app.""" import app as app_module assert not hasattr(app_module, "app"), "app.py must not keep a module-level `app`"