|
9 | 9 | from recurly import Account, AddOn, Address, Adjustment, BillingInfo, Coupon, Item, Plan, Redemption, Subscription, \ |
10 | 10 | SubscriptionAddOn, Transaction, MeasuredUnit, Usage, GiftCard, Delivery, ShippingAddress, AccountAcquisition, \ |
11 | 11 | Purchase, Invoice, InvoiceCollection, CreditPayment, CustomField, ExportDate, ExportDateFile, DunningCampaign, \ |
12 | | - DunningCycle, InvoiceTemplate |
| 12 | + DunningCycle, InvoiceTemplate, PlanRampInterval |
13 | 13 | from recurly import Money, NotFoundError, ValidationError, BadRequestError, PageError |
14 | 14 | from recurly import recurly_logging as logging |
15 | 15 | from recurlytests import RecurlyTest |
@@ -1471,6 +1471,57 @@ def test_plan(self): |
1471 | 1471 | plan = Plan.get(plan_code) |
1472 | 1472 | self.assertTrue(plan.tax_exempt) |
1473 | 1473 |
|
| 1474 | + def test_plan_with_ramps(self): |
| 1475 | + plan_code = 'plan%s' % self.test_id |
| 1476 | + with self.mock_request('plan/does-not-exist.xml'): |
| 1477 | + self.assertRaises(NotFoundError, Plan.get, plan_code) |
| 1478 | + |
| 1479 | + ramp_interval_1 = PlanRampInterval( |
| 1480 | + unit_amount_in_cents=Money(USD=2000), |
| 1481 | + starting_billing_cycle=1, |
| 1482 | + ) |
| 1483 | + ramp_interval_2 = PlanRampInterval( |
| 1484 | + unit_amount_in_cents=Money(USD=3000), |
| 1485 | + starting_billing_cycle=2, |
| 1486 | + ) |
| 1487 | + ramp_intervals = [ramp_interval_1, ramp_interval_2] |
| 1488 | + |
| 1489 | + plan = Plan( |
| 1490 | + plan_code=plan_code, |
| 1491 | + name='Mock Plan', |
| 1492 | + setup_fee_in_cents=Money(200), |
| 1493 | + pricing_model='ramp', |
| 1494 | + ramp_intervals=ramp_intervals, |
| 1495 | + total_billing_cycles=10 |
| 1496 | + ) |
| 1497 | + with self.mock_request('plan/created_with_ramps.xml'): |
| 1498 | + plan.save() |
| 1499 | + |
| 1500 | + self.assertEqual(plan.plan_code, plan_code) |
| 1501 | + self.assertEqual(len(plan.ramp_intervals), len(ramp_intervals)) |
| 1502 | + self.assertEqual(plan.pricing_model, 'ramp') |
| 1503 | + |
| 1504 | + self.assertEqual(plan.plan_code, plan_code) |
| 1505 | + |
| 1506 | + with self.mock_request('plan/exists_with_ramps.xml'): |
| 1507 | + same_plan = Plan.get(plan_code) |
| 1508 | + self.assertEqual(same_plan.plan_code, plan_code) |
| 1509 | + self.assertEqual(len(plan.ramp_intervals), len(ramp_intervals)) |
| 1510 | + self.assertEqual(plan.pricing_model, 'ramp') |
| 1511 | + |
| 1512 | + plan.ramp_intervals = [ |
| 1513 | + PlanRampInterval( |
| 1514 | + starting_billing_cycle=1, |
| 1515 | + unit_amount_in_cents=Money(USD=3000) |
| 1516 | + ), |
| 1517 | + PlanRampInterval( |
| 1518 | + starting_billing_cycle=2, |
| 1519 | + unit_amount_in_cents=Money(USD=4000) |
| 1520 | + ), |
| 1521 | + ] |
| 1522 | + with self.mock_request('plan/updated_with_ramps.xml'): |
| 1523 | + plan.save() |
| 1524 | + |
1474 | 1525 | def test_preview_subscription_change(self): |
1475 | 1526 | with self.mock_request('subscription/show.xml'): |
1476 | 1527 | sub = Subscription.get('123456789012345678901234567890ab') |
|
0 commit comments