42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from datetime import datetime, timezone, timedelta
|
|
from app.models.subscription import Subscription
|
|
|
|
|
|
def make_sub(**kwargs):
|
|
sub = Subscription()
|
|
sub.plan = kwargs.get("plan", "free")
|
|
sub.status = kwargs.get("status", "active")
|
|
sub.current_period_end = kwargs.get("current_period_end")
|
|
return sub
|
|
|
|
|
|
def test_complimentary_is_active_but_not_paid():
|
|
sub = make_sub(plan="pro", status="complimentary")
|
|
assert sub.is_active is True
|
|
assert sub.is_paid is False
|
|
assert sub.has_pro_entitlement is True
|
|
|
|
|
|
def test_paid_pro_active():
|
|
sub = make_sub(plan="pro", status="active")
|
|
assert sub.is_paid is True
|
|
assert sub.has_pro_entitlement is True
|
|
|
|
|
|
def test_trial_unexpired_has_entitlement():
|
|
sub = make_sub(plan="pro", status="trialing", current_period_end=datetime.now(timezone.utc) + timedelta(days=5))
|
|
assert sub.is_active is True
|
|
assert sub.is_paid is False
|
|
assert sub.has_pro_entitlement is True
|
|
|
|
|
|
def test_trial_expired_no_entitlement():
|
|
sub = make_sub(plan="pro", status="trialing", current_period_end=datetime.now(timezone.utc) - timedelta(hours=1))
|
|
assert sub.has_pro_entitlement is False
|
|
|
|
|
|
def test_canceled_no_entitlement():
|
|
sub = make_sub(plan="pro", status="canceled")
|
|
assert sub.is_active is False
|
|
assert sub.has_pro_entitlement is False
|