fix(ci): keep the subscriber-alert rule importable without the stripe SDK
The minimal CI env has no stripe package, and the new test imported cloud.billing, which does. The rule is a pure function of the subscription state, so it now lives in cloud/config.py next to the state tuples it belongs with, and billing.py imports it from there.
This commit is contained in:
parent
03c8a1f887
commit
2607d1252e
3 changed files with 19 additions and 18 deletions
|
|
@ -16,7 +16,8 @@ from fastapi import APIRouter, Request, HTTPException
|
|||
from pydantic import BaseModel
|
||||
from sqlalchemy import select
|
||||
|
||||
from .config import settings, PLAN_MINUTES, TRIAL_DAYS, SUBSCRIPTION_LOOKUP_KEYS, TOPUP_LOOKUP_KEYS
|
||||
from .config import (settings, PLAN_MINUTES, TRIAL_DAYS, SUBSCRIPTION_LOOKUP_KEYS,
|
||||
TOPUP_LOOKUP_KEYS, new_subscriber_label)
|
||||
from . import analytics, config, database
|
||||
from .models import User, Subscription, CreditTopup, StripeEvent, SignupAttribution
|
||||
from .auth import get_current_user_required
|
||||
|
|
@ -490,19 +491,6 @@ def _sub_period(sub_obj: dict):
|
|||
return start, end
|
||||
|
||||
|
||||
def new_subscriber_label(status: str) -> str | None:
|
||||
"""Alert text for a brand-new subscription row, or None to stay silent.
|
||||
|
||||
Only states where a payment method actually went through count: an
|
||||
'incomplete' row is a checkout that has not been paid (yet), not a sale.
|
||||
"""
|
||||
if status == "trialing":
|
||||
return "trial started — card on file"
|
||||
if status == "active":
|
||||
return status
|
||||
return None
|
||||
|
||||
|
||||
async def _upsert_subscription(sub_obj: dict, event_created: datetime):
|
||||
price_id = _sub_price_id(sub_obj)
|
||||
info = plan_info_for_price(price_id)
|
||||
|
|
|
|||
|
|
@ -61,6 +61,21 @@ BILLING_ATTENTION_STATES = ("past_due", "unpaid", "incomplete", "paused")
|
|||
# within 24h), so blocking that would only stop the retry.
|
||||
CHECKOUT_BLOCKING_STATES = ("active", "trialing", "past_due", "unpaid", "paused")
|
||||
|
||||
def new_subscriber_label(status: str):
|
||||
"""Admin-alert text for a brand-new subscription row, or None to stay silent.
|
||||
|
||||
Only states where a payment method actually went through count. Stripe
|
||||
creates the row as 'incomplete' seconds after the Checkout page opens,
|
||||
before the user types anything; announcing that is announcing a click.
|
||||
Lives here (not in billing.py) so the test runs without the stripe SDK.
|
||||
"""
|
||||
if status == "trialing":
|
||||
return "trial started — card on file"
|
||||
if status == "active":
|
||||
return status
|
||||
return None
|
||||
|
||||
|
||||
# Smallest slice of a long video worth offering instead of the quota wall.
|
||||
# A user whose remaining minutes cannot cover the whole source is offered its
|
||||
# first N minutes (N = what they have left) so they see clips before paying:
|
||||
|
|
|
|||
|
|
@ -86,10 +86,8 @@ class TestNewSubscriberAlert:
|
|||
"""The 'New subscriber' admin alert must mean money, not a click on pay."""
|
||||
|
||||
def test_incomplete_is_silent(self):
|
||||
from cloud.billing import new_subscriber_label
|
||||
assert new_subscriber_label("incomplete") is None
|
||||
assert config.new_subscriber_label("incomplete") is None
|
||||
|
||||
@pytest.mark.parametrize("status", ["active", "trialing"])
|
||||
def test_paid_states_alert(self, status):
|
||||
from cloud.billing import new_subscriber_label
|
||||
assert new_subscriber_label(status)
|
||||
assert config.new_subscriber_label(status)
|
||||
|
|
|
|||
Loading…
Reference in a new issue