refactor: remove backward compatibility code for pre-launch baseline

Clean up accumulated backward-compat shims, deprecated wrappers, unused
aliases, and legacy code across the codebase. Since the platform is not
live yet, this establishes a clean baseline.

Changes:
- Delete deprecated middleware/context.py (RequestContext, get_request_context)
- Remove unused factory get_store_email_settings_service()
- Remove deprecated pagination_full macro, /admin/platform-homepage route
- Remove ConversationResponse, InvoiceSettings* unprefixed aliases
- Simplify celery_config.py (remove empty LEGACY_TASK_MODULES)
- Standardize billing exceptions: *Error aliases → *Exception names
- Consolidate duplicate TierNotFoundError/FeatureNotFoundError classes
- Remove deprecated is_admin_request() from Store/PlatformContextManager
- Remove is_platform_default field, MediaUploadResponse legacy flat fields
- Remove MediaItemResponse.url alias, update JS to use file_url
- Update all affected tests and documentation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-13 21:58:59 +01:00
parent 531487f5c9
commit 8968e7d9cd
31 changed files with 172 additions and 774 deletions

View File

@@ -6,6 +6,13 @@ from unittest.mock import MagicMock, patch
import pytest
from app.modules.billing.exceptions import (
NoActiveSubscriptionException,
PaymentSystemNotConfiguredException,
StripePriceNotConfiguredException,
SubscriptionNotCancelledException,
TierNotFoundException,
)
from app.modules.billing.models import (
AddOnProduct,
BillingHistory,
@@ -13,14 +20,7 @@ from app.modules.billing.models import (
SubscriptionStatus,
SubscriptionTier,
)
from app.modules.billing.services.billing_service import (
BillingService,
NoActiveSubscriptionError,
PaymentSystemNotConfiguredError,
StripePriceNotConfiguredError,
SubscriptionNotCancelledError,
TierNotFoundError,
)
from app.modules.billing.services.billing_service import BillingService
# ============================================================================
# Tier Lookup
@@ -41,17 +41,17 @@ class TestBillingServiceTiers:
assert tier.code == "essential"
def test_get_tier_by_code_not_found(self, db):
"""Nonexistent tier raises TierNotFoundError."""
with pytest.raises(TierNotFoundError) as exc_info:
"""Nonexistent tier raises TierNotFoundException."""
with pytest.raises(TierNotFoundException) as exc_info:
self.service.get_tier_by_code(db, "nonexistent")
assert exc_info.value.tier_code == "nonexistent"
def test_get_tier_by_code_inactive_not_returned(self, db, bs_tier_essential):
"""Inactive tier raises TierNotFoundError (only active tiers returned)."""
"""Inactive tier raises TierNotFoundException (only active tiers returned)."""
bs_tier_essential.is_active = False
db.flush()
with pytest.raises(TierNotFoundError):
with pytest.raises(TierNotFoundException):
self.service.get_tier_by_code(db, "essential")
@@ -249,8 +249,8 @@ class TestBillingServiceChangeTier:
self.service = BillingService()
def test_change_tier_no_subscription_raises(self, db, bs_tiers):
"""Raises NoActiveSubscriptionError when no subscription exists."""
with pytest.raises(NoActiveSubscriptionError):
"""Raises NoActiveSubscriptionException when no subscription exists."""
with pytest.raises(NoActiveSubscriptionException):
self.service.change_tier(db, 99999, 99999, "professional", False)
def test_change_tier_no_stripe_subscription_raises(
@@ -258,7 +258,7 @@ class TestBillingServiceChangeTier:
):
"""Raises when subscription has no stripe_subscription_id."""
# bs_subscription has no Stripe IDs
with pytest.raises(NoActiveSubscriptionError):
with pytest.raises(NoActiveSubscriptionException):
self.service.change_tier(
db,
bs_subscription.merchant_id,
@@ -270,8 +270,8 @@ class TestBillingServiceChangeTier:
def test_change_tier_nonexistent_tier_raises(
self, db, bs_stripe_subscription
):
"""Raises TierNotFoundError for nonexistent tier."""
with pytest.raises(TierNotFoundError):
"""Raises TierNotFoundException for nonexistent tier."""
with pytest.raises(TierNotFoundException):
self.service.change_tier(
db,
bs_stripe_subscription.merchant_id,
@@ -283,9 +283,9 @@ class TestBillingServiceChangeTier:
def test_change_tier_no_price_id_raises(
self, db, bs_stripe_subscription, bs_tiers
):
"""Raises StripePriceNotConfiguredError when tier has no Stripe price."""
"""Raises StripePriceNotConfiguredException when tier has no Stripe price."""
# bs_tiers have no stripe_price_* set
with pytest.raises(StripePriceNotConfiguredError):
with pytest.raises(StripePriceNotConfiguredException):
self.service.change_tier(
db,
bs_stripe_subscription.merchant_id,
@@ -382,12 +382,12 @@ class TestBillingServiceCancel:
def test_cancel_no_subscription_raises(self, db):
"""Raises when no subscription found."""
with pytest.raises(NoActiveSubscriptionError):
with pytest.raises(NoActiveSubscriptionException):
self.service.cancel_subscription(db, 99999, 99999, None, False)
def test_cancel_no_stripe_id_raises(self, db, bs_subscription):
"""Raises when subscription has no stripe_subscription_id."""
with pytest.raises(NoActiveSubscriptionError):
with pytest.raises(NoActiveSubscriptionException):
self.service.cancel_subscription(
db,
bs_subscription.merchant_id,
@@ -431,12 +431,12 @@ class TestBillingServiceReactivate:
def test_reactivate_no_subscription_raises(self, db):
"""Raises when no subscription found."""
with pytest.raises(NoActiveSubscriptionError):
with pytest.raises(NoActiveSubscriptionException):
self.service.reactivate_subscription(db, 99999, 99999)
def test_reactivate_not_cancelled_raises(self, db, bs_stripe_subscription):
"""Raises SubscriptionNotCancelledError when not cancelled."""
with pytest.raises(SubscriptionNotCancelledError):
"""Raises SubscriptionNotCancelledException when not cancelled."""
with pytest.raises(SubscriptionNotCancelledException):
self.service.reactivate_subscription(
db,
bs_stripe_subscription.merchant_id,
@@ -480,25 +480,25 @@ class TestBillingServiceCheckout:
self.service = BillingService()
def test_checkout_stripe_not_configured_raises(self, db, bs_tiers_with_stripe):
"""Raises PaymentSystemNotConfiguredError when Stripe is off."""
"""Raises PaymentSystemNotConfiguredException when Stripe is off."""
with patch(
"app.modules.billing.services.billing_service.stripe_service"
) as mock_stripe:
mock_stripe.is_configured = False
with pytest.raises(PaymentSystemNotConfiguredError):
with pytest.raises(PaymentSystemNotConfiguredException):
self.service.create_checkout_session(
db, 1, 1, "essential", False, "http://ok", "http://cancel"
)
def test_checkout_nonexistent_tier_raises(self, db):
"""Raises TierNotFoundError for nonexistent tier."""
"""Raises TierNotFoundException for nonexistent tier."""
with patch(
"app.modules.billing.services.billing_service.stripe_service"
) as mock_stripe:
mock_stripe.is_configured = True
with pytest.raises(TierNotFoundError):
with pytest.raises(TierNotFoundException):
self.service.create_checkout_session(
db, 1, 1, "nonexistent", False, "http://ok", "http://cancel"
)
@@ -518,23 +518,23 @@ class TestBillingServicePortal:
self.service = BillingService()
def test_portal_stripe_not_configured_raises(self, db):
"""Raises PaymentSystemNotConfiguredError when Stripe is off."""
"""Raises PaymentSystemNotConfiguredException when Stripe is off."""
with patch(
"app.modules.billing.services.billing_service.stripe_service"
) as mock_stripe:
mock_stripe.is_configured = False
with pytest.raises(PaymentSystemNotConfiguredError):
with pytest.raises(PaymentSystemNotConfiguredException):
self.service.create_portal_session(db, 1, 1, "http://return")
def test_portal_no_subscription_raises(self, db):
"""Raises NoActiveSubscriptionError when no subscription found."""
"""Raises NoActiveSubscriptionException when no subscription found."""
with patch(
"app.modules.billing.services.billing_service.stripe_service"
) as mock_stripe:
mock_stripe.is_configured = True
with pytest.raises(NoActiveSubscriptionError):
with pytest.raises(NoActiveSubscriptionException):
self.service.create_portal_session(db, 99999, 99999, "http://return")
def test_portal_no_customer_id_raises(self, db, bs_subscription):
@@ -544,7 +544,7 @@ class TestBillingServicePortal:
) as mock_stripe:
mock_stripe.is_configured = True
with pytest.raises(NoActiveSubscriptionError):
with pytest.raises(NoActiveSubscriptionException):
self.service.create_portal_session(
db,
bs_subscription.merchant_id,
@@ -568,12 +568,12 @@ class TestBillingServiceUpcomingInvoice:
def test_upcoming_invoice_no_subscription_raises(self, db):
"""Raises when no subscription exists."""
with pytest.raises(NoActiveSubscriptionError):
with pytest.raises(NoActiveSubscriptionException):
self.service.get_upcoming_invoice(db, 99999, 99999)
def test_upcoming_invoice_no_customer_id_raises(self, db, bs_subscription):
"""Raises when subscription has no stripe_customer_id."""
with pytest.raises(NoActiveSubscriptionError):
with pytest.raises(NoActiveSubscriptionException):
self.service.get_upcoming_invoice(
db, bs_subscription.merchant_id, bs_subscription.platform_id
)