fix(tests): remove stale onboarding redirect tests and mock billing limits
Some checks failed
Some checks failed
Remove marketplace page redirect-to-onboarding tests that no longer match the route behavior. Add can_create_store mock to tenancy store creation tests to bypass billing limit checks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -302,19 +302,6 @@ class TestOnboardingPageRoutes:
|
|||||||
class TestMarketplacePageRoutes:
|
class TestMarketplacePageRoutes:
|
||||||
"""Tests for GET /store/{store_code}/marketplace."""
|
"""Tests for GET /store/{store_code}/marketplace."""
|
||||||
|
|
||||||
def test_redirects_to_onboarding_when_not_completed(
|
|
||||||
self, client, db, mp_auth, mp_store, mp_store_with_marketplace,
|
|
||||||
mp_onboarding_not_completed,
|
|
||||||
):
|
|
||||||
"""Marketplace page redirects to onboarding when not completed."""
|
|
||||||
response = client.get(
|
|
||||||
f"/store/{mp_store.subdomain}/marketplace",
|
|
||||||
headers=mp_auth,
|
|
||||||
follow_redirects=False,
|
|
||||||
)
|
|
||||||
assert response.status_code == 302
|
|
||||||
assert f"/store/{mp_store.subdomain}/onboarding" in response.headers["location"]
|
|
||||||
|
|
||||||
def test_renders_when_onboarding_completed(
|
def test_renders_when_onboarding_completed(
|
||||||
self, client, db, mp_auth, mp_store, mp_store_with_marketplace,
|
self, client, db, mp_auth, mp_store, mp_store_with_marketplace,
|
||||||
mp_onboarding_completed,
|
mp_onboarding_completed,
|
||||||
@@ -327,18 +314,6 @@ class TestMarketplacePageRoutes:
|
|||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
def test_redirects_when_no_onboarding_record(
|
|
||||||
self, client, db, mp_auth, mp_store, mp_store_with_marketplace,
|
|
||||||
):
|
|
||||||
"""Marketplace page redirects when no onboarding record (not completed)."""
|
|
||||||
response = client.get(
|
|
||||||
f"/store/{mp_store.subdomain}/marketplace",
|
|
||||||
headers=mp_auth,
|
|
||||||
follow_redirects=False,
|
|
||||||
)
|
|
||||||
assert response.status_code == 302
|
|
||||||
assert f"/store/{mp_store.subdomain}/onboarding" in response.headers["location"]
|
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Letzshop page tests
|
# Letzshop page tests
|
||||||
@@ -350,19 +325,6 @@ class TestMarketplacePageRoutes:
|
|||||||
class TestLetzshopPageRoutes:
|
class TestLetzshopPageRoutes:
|
||||||
"""Tests for GET /store/{store_code}/letzshop."""
|
"""Tests for GET /store/{store_code}/letzshop."""
|
||||||
|
|
||||||
def test_redirects_to_onboarding_when_not_completed(
|
|
||||||
self, client, db, mp_auth, mp_store, mp_store_with_marketplace,
|
|
||||||
mp_onboarding_not_completed,
|
|
||||||
):
|
|
||||||
"""Letzshop page redirects to onboarding when not completed."""
|
|
||||||
response = client.get(
|
|
||||||
f"/store/{mp_store.subdomain}/letzshop",
|
|
||||||
headers=mp_auth,
|
|
||||||
follow_redirects=False,
|
|
||||||
)
|
|
||||||
assert response.status_code == 302
|
|
||||||
assert f"/store/{mp_store.subdomain}/onboarding" in response.headers["location"]
|
|
||||||
|
|
||||||
def test_renders_when_onboarding_completed(
|
def test_renders_when_onboarding_completed(
|
||||||
self, client, db, mp_auth, mp_store, mp_store_with_marketplace,
|
self, client, db, mp_auth, mp_store, mp_store_with_marketplace,
|
||||||
mp_onboarding_completed,
|
mp_onboarding_completed,
|
||||||
@@ -374,15 +336,3 @@ class TestLetzshopPageRoutes:
|
|||||||
follow_redirects=False,
|
follow_redirects=False,
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
def test_redirects_when_no_onboarding_record(
|
|
||||||
self, client, db, mp_auth, mp_store, mp_store_with_marketplace,
|
|
||||||
):
|
|
||||||
"""Letzshop page redirects when no onboarding record (not completed)."""
|
|
||||||
response = client.get(
|
|
||||||
f"/store/{mp_store.subdomain}/letzshop",
|
|
||||||
headers=mp_auth,
|
|
||||||
follow_redirects=False,
|
|
||||||
)
|
|
||||||
assert response.status_code == 302
|
|
||||||
assert f"/store/{mp_store.subdomain}/onboarding" in response.headers["location"]
|
|
||||||
|
|||||||
@@ -186,42 +186,15 @@ class TestOnboardingPageGuard:
|
|||||||
@pytest.mark.unit
|
@pytest.mark.unit
|
||||||
@pytest.mark.marketplace
|
@pytest.mark.marketplace
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
class TestMarketplacePageOnboardingGate:
|
class TestMarketplacePageRendering:
|
||||||
"""Test that marketplace page redirects to onboarding when not completed."""
|
"""Test that marketplace page renders correctly."""
|
||||||
|
|
||||||
@patch("app.modules.marketplace.routes.pages.store.OnboardingService")
|
|
||||||
@patch("app.modules.marketplace.routes.pages.store.get_store_context")
|
@patch("app.modules.marketplace.routes.pages.store.get_store_context")
|
||||||
@patch("app.modules.marketplace.routes.pages.store.templates")
|
@patch("app.modules.marketplace.routes.pages.store.templates")
|
||||||
async def test_redirects_to_onboarding_when_not_completed(
|
async def test_renders_marketplace_page(
|
||||||
self, mock_templates, mock_ctx, mock_onboarding_cls, db
|
self, mock_templates, mock_ctx, db
|
||||||
):
|
):
|
||||||
"""Redirect to onboarding if onboarding not completed."""
|
"""Render marketplace page."""
|
||||||
mock_svc = MagicMock()
|
|
||||||
mock_svc.is_completed.return_value = False
|
|
||||||
mock_onboarding_cls.return_value = mock_svc
|
|
||||||
|
|
||||||
user = _make_user_context()
|
|
||||||
response = await store_marketplace_page(
|
|
||||||
request=_make_request(),
|
|
||||||
store_code="teststore",
|
|
||||||
current_user=user,
|
|
||||||
db=db,
|
|
||||||
)
|
|
||||||
assert isinstance(response, RedirectResponse)
|
|
||||||
assert response.status_code == 302
|
|
||||||
assert "/store/teststore/onboarding" in response.headers["location"]
|
|
||||||
|
|
||||||
@patch("app.modules.marketplace.routes.pages.store.OnboardingService")
|
|
||||||
@patch("app.modules.marketplace.routes.pages.store.get_store_context")
|
|
||||||
@patch("app.modules.marketplace.routes.pages.store.templates")
|
|
||||||
async def test_renders_marketplace_when_onboarding_completed(
|
|
||||||
self, mock_templates, mock_ctx, mock_onboarding_cls, db
|
|
||||||
):
|
|
||||||
"""Render marketplace page if onboarding is completed."""
|
|
||||||
mock_svc = MagicMock()
|
|
||||||
mock_svc.is_completed.return_value = True
|
|
||||||
mock_onboarding_cls.return_value = mock_svc
|
|
||||||
|
|
||||||
mock_ctx.return_value = {"request": _make_request()}
|
mock_ctx.return_value = {"request": _make_request()}
|
||||||
mock_templates.TemplateResponse.return_value = "rendered"
|
mock_templates.TemplateResponse.return_value = "rendered"
|
||||||
|
|
||||||
@@ -246,42 +219,15 @@ class TestMarketplacePageOnboardingGate:
|
|||||||
@pytest.mark.unit
|
@pytest.mark.unit
|
||||||
@pytest.mark.marketplace
|
@pytest.mark.marketplace
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
class TestLetzshopPageOnboardingGate:
|
class TestLetzshopPageRendering:
|
||||||
"""Test that letzshop page redirects to onboarding when not completed."""
|
"""Test that letzshop page renders correctly."""
|
||||||
|
|
||||||
@patch("app.modules.marketplace.routes.pages.store.OnboardingService")
|
|
||||||
@patch("app.modules.marketplace.routes.pages.store.get_store_context")
|
@patch("app.modules.marketplace.routes.pages.store.get_store_context")
|
||||||
@patch("app.modules.marketplace.routes.pages.store.templates")
|
@patch("app.modules.marketplace.routes.pages.store.templates")
|
||||||
async def test_redirects_to_onboarding_when_not_completed(
|
async def test_renders_letzshop_page(
|
||||||
self, mock_templates, mock_ctx, mock_onboarding_cls, db
|
self, mock_templates, mock_ctx, db
|
||||||
):
|
):
|
||||||
"""Redirect to onboarding if onboarding not completed."""
|
"""Render letzshop page."""
|
||||||
mock_svc = MagicMock()
|
|
||||||
mock_svc.is_completed.return_value = False
|
|
||||||
mock_onboarding_cls.return_value = mock_svc
|
|
||||||
|
|
||||||
user = _make_user_context()
|
|
||||||
response = await store_letzshop_page(
|
|
||||||
request=_make_request(),
|
|
||||||
store_code="teststore",
|
|
||||||
current_user=user,
|
|
||||||
db=db,
|
|
||||||
)
|
|
||||||
assert isinstance(response, RedirectResponse)
|
|
||||||
assert response.status_code == 302
|
|
||||||
assert "/store/teststore/onboarding" in response.headers["location"]
|
|
||||||
|
|
||||||
@patch("app.modules.marketplace.routes.pages.store.OnboardingService")
|
|
||||||
@patch("app.modules.marketplace.routes.pages.store.get_store_context")
|
|
||||||
@patch("app.modules.marketplace.routes.pages.store.templates")
|
|
||||||
async def test_renders_letzshop_when_onboarding_completed(
|
|
||||||
self, mock_templates, mock_ctx, mock_onboarding_cls, db
|
|
||||||
):
|
|
||||||
"""Render letzshop page if onboarding is completed."""
|
|
||||||
mock_svc = MagicMock()
|
|
||||||
mock_svc.is_completed.return_value = True
|
|
||||||
mock_onboarding_cls.return_value = mock_svc
|
|
||||||
|
|
||||||
mock_ctx.return_value = {"request": _make_request()}
|
mock_ctx.return_value = {"request": _make_request()}
|
||||||
mock_templates.TemplateResponse.return_value = "rendered"
|
mock_templates.TemplateResponse.return_value = "rendered"
|
||||||
|
|
||||||
|
|||||||
@@ -193,7 +193,8 @@ class TestMerchantStoreServiceCreate:
|
|||||||
assert result["is_active"] is True
|
assert result["is_active"] is True
|
||||||
assert result["is_verified"] is False
|
assert result["is_verified"] is False
|
||||||
|
|
||||||
def test_create_store_duplicate_code(self, db, merchant_owner, merchant_store):
|
@patch.object(MerchantStoreService, "can_create_store", return_value=(True, None))
|
||||||
|
def test_create_store_duplicate_code(self, _mock_limit, db, merchant_owner, merchant_store):
|
||||||
"""Test creating store with duplicate store code."""
|
"""Test creating store with duplicate store code."""
|
||||||
store_data = {
|
store_data = {
|
||||||
"name": "Another Store",
|
"name": "Another Store",
|
||||||
@@ -206,7 +207,8 @@ class TestMerchantStoreServiceCreate:
|
|||||||
with pytest.raises(StoreAlreadyExistsException):
|
with pytest.raises(StoreAlreadyExistsException):
|
||||||
self.service.create_store(db, merchant_owner.id, store_data)
|
self.service.create_store(db, merchant_owner.id, store_data)
|
||||||
|
|
||||||
def test_create_store_duplicate_subdomain(self, db, merchant_owner, merchant_store):
|
@patch.object(MerchantStoreService, "can_create_store", return_value=(True, None))
|
||||||
|
def test_create_store_duplicate_subdomain(self, _mock_limit, db, merchant_owner, merchant_store):
|
||||||
"""Test creating store with duplicate subdomain."""
|
"""Test creating store with duplicate subdomain."""
|
||||||
store_data = {
|
store_data = {
|
||||||
"name": "Another Store",
|
"name": "Another Store",
|
||||||
@@ -219,7 +221,8 @@ class TestMerchantStoreServiceCreate:
|
|||||||
with pytest.raises(StoreValidationException):
|
with pytest.raises(StoreValidationException):
|
||||||
self.service.create_store(db, merchant_owner.id, store_data)
|
self.service.create_store(db, merchant_owner.id, store_data)
|
||||||
|
|
||||||
def test_create_store_nonexistent_merchant(self, db):
|
@patch.object(MerchantStoreService, "can_create_store", return_value=(True, None))
|
||||||
|
def test_create_store_nonexistent_merchant(self, _mock_limit, db):
|
||||||
"""Test creating store for non-existent merchant."""
|
"""Test creating store for non-existent merchant."""
|
||||||
store_data = {
|
store_data = {
|
||||||
"name": "No Merchant Store",
|
"name": "No Merchant Store",
|
||||||
@@ -232,7 +235,8 @@ class TestMerchantStoreServiceCreate:
|
|||||||
with pytest.raises(MerchantNotFoundException):
|
with pytest.raises(MerchantNotFoundException):
|
||||||
self.service.create_store(db, 99999, store_data)
|
self.service.create_store(db, 99999, store_data)
|
||||||
|
|
||||||
def test_create_store_creates_default_roles(self, db, merchant_owner):
|
@patch.object(MerchantStoreService, "can_create_store", return_value=(True, None))
|
||||||
|
def test_create_store_creates_default_roles(self, _mock_limit, db, merchant_owner):
|
||||||
"""Test that default roles are created for new store."""
|
"""Test that default roles are created for new store."""
|
||||||
from app.modules.tenancy.models.store import Role
|
from app.modules.tenancy.models.store import Role
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user