fix: bypass subscription check in middleware tests
Some checks failed
CI / ruff (push) Successful in 11s
CI / pytest (push) Successful in 38m19s
CI / validate (push) Failing after 23s
CI / dependency-scanning (push) Successful in 30s
CI / docs (push) Has been skipped
CI / deploy (push) Has been skipped

The StorefrontAccessMiddleware was blocking middleware test routes
(/middleware-test/*) with 403 because test stores have no subscriptions.
These tests verify store context detection and theme loading, not
subscription access. Patch SKIP_PATH_PREFIXES in the test conftest to
let test routes through.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-18 23:47:10 +01:00
parent d9fc52d47a
commit 573b0180ad

View File

@@ -65,13 +65,20 @@ def client(db):
# Patch get_db in middleware modules - they have their own imports
# The middleware calls: db_gen = get_db(); db = next(db_gen)
# Also patch settings.platform_domain so subdomain detection works with test hosts
# Also bypass StorefrontAccessMiddleware subscription check for test routes —
# these tests verify store context detection, not subscription access.
from middleware.storefront_access import SKIP_PATH_PREFIXES
test_skip_prefixes = SKIP_PATH_PREFIXES + ("/middleware-test/",)
with patch("middleware.platform_context.get_db", override_get_db):
with patch("middleware.store_context.get_db", override_get_db):
with patch("middleware.theme_context.get_db", override_get_db):
with patch("middleware.store_context.settings") as mock_settings:
mock_settings.platform_domain = "platform.com"
client = TestClient(app)
yield client
with patch("middleware.storefront_access.SKIP_PATH_PREFIXES", test_skip_prefixes):
mock_settings.platform_domain = "platform.com"
client = TestClient(app)
yield client
# Clean up
if get_db in app.dependency_overrides: