Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Tiered Pricing Plans #629

Open
wants to merge 14 commits into
base: original
Choose a base branch
from
Prev Previous commit
Next Next commit
Add Test Cases for Models
jksimoniii committed Feb 1, 2019
commit 76cc607e80a0a6e94a52a078e7797d73d05dd12d
21 changes: 20 additions & 1 deletion pinax/stripe/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -26,8 +26,9 @@
InvoiceItem,
Plan,
Subscription,
Tier,
Transfer,
UserAccount
UserAccount,
)

try:
@@ -74,6 +75,18 @@ def test_plan_stripe_plan_with_account(self, RetrieveMock):
self.assertTrue(RetrieveMock.call_args_list, [
call("plan", stripe_account="acct_A")])

def test_plan_calculate_total_amount_per_unit_billing_scheme(self):
quantity = 10
p = Plan(amount=decimal.Decimal("5"), stripe_id="plan", billing_scheme=Plan.BILLING_SCHEME_PER_UNIT)
self.assertEqual(p.calculate_total_amount(quantity), decimal.Decimal("50"))

@patch("pinax.stripe.models.Tier.pricing")
def test_plan_calculate_total_amount_tiered_billing_scheme(self, TierPricingMock):
quantity = 10
p = Plan(amount=0, stripe_id="plan", billing_scheme=Plan.BILLING_SCHEME_TIERED)
p.calculate_total_amount(quantity)
TierPricingMock.calculate_final_cost.assert_called_with(p, quantity, p.tiers_mode)

def test_plan_per_account(self):
Plan.objects.create(stripe_id="plan", amount=decimal.Decimal("100"), interval="monthly", interval_count=1)
account = Account.objects.create(stripe_id="acct_A")
@@ -302,6 +315,12 @@ def test_blank_with_null(self):
if f.null:
self.assertTrue(f.blank, msg="%s.%s should be blank=True" % (klass.__name__, f.name))

def test_tier_calculate_cost(self):
quantity = 12
p = Plan.objects.create(stripe_id="plan", amount=0, interval="monthly", interval_count=1)
t = Tier(plan=p, amount=4, flat_amount=20)
self.assertEqual(t.calculate_cost(quantity), 68)


class StripeObjectTests(TestCase):