fix: bypass subscription check in middleware tests
Some checks failed
Some checks failed
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:
@@ -65,13 +65,20 @@ def client(db):
|
|||||||
# Patch get_db in middleware modules - they have their own imports
|
# Patch get_db in middleware modules - they have their own imports
|
||||||
# The middleware calls: db_gen = get_db(); db = next(db_gen)
|
# The middleware calls: db_gen = get_db(); db = next(db_gen)
|
||||||
# Also patch settings.platform_domain so subdomain detection works with test hosts
|
# 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.platform_context.get_db", override_get_db):
|
||||||
with patch("middleware.store_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.theme_context.get_db", override_get_db):
|
||||||
with patch("middleware.store_context.settings") as mock_settings:
|
with patch("middleware.store_context.settings") as mock_settings:
|
||||||
mock_settings.platform_domain = "platform.com"
|
with patch("middleware.storefront_access.SKIP_PATH_PREFIXES", test_skip_prefixes):
|
||||||
client = TestClient(app)
|
mock_settings.platform_domain = "platform.com"
|
||||||
yield client
|
client = TestClient(app)
|
||||||
|
yield client
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
if get_db in app.dependency_overrides:
|
if get_db in app.dependency_overrides:
|
||||||
|
|||||||
Reference in New Issue
Block a user