|
11 | 11 | Purchase, Invoice, InvoiceCollection, CreditPayment, CustomField, ExportDate, ExportDateFile, DunningCampaign, \
|
12 | 12 | DunningCycle, GeneralLedgerAccount, InvoiceTemplate, PerformanceObligation, PlanRampInterval, SubRampInterval, ExternalSubscription, ExternalProduct, \
|
13 | 13 | ExternalProductReference, ExternalPaymentPhase, CustomFieldDefinition, ExternalInvoice, ExternalCharge, ExternalAccount, \
|
14 |
| - GatewayAttributes, BusinessEntity |
| 14 | + GatewayAttributes, BusinessEntity, ProrationSettings |
15 | 15 | from recurly import Money, NotFoundError, ValidationError, BadRequestError, PageError
|
16 | 16 | from recurly import recurly_logging as logging
|
17 |
| -from recurlytests import RecurlyTest |
| 17 | +from recurlytests import RecurlyTest, xml |
| 18 | +from defusedxml import ElementTree |
18 | 19 |
|
19 | 20 | recurly.SUBDOMAIN = 'api'
|
20 | 21 |
|
@@ -2189,6 +2190,43 @@ def test_subscribe_multiple_errors(self):
|
2189 | 2190 | except e:
|
2190 | 2191 | self.fail("Failed subscription did not raise a Validation error")
|
2191 | 2192 |
|
| 2193 | + def test_subscription_change_proration(self): |
| 2194 | + |
| 2195 | + plan = Plan( |
| 2196 | + plan_code='basicplan', |
| 2197 | + name='Basic Plan', |
| 2198 | + setup_fee_in_cents=Money(0), |
| 2199 | + unit_amount_in_cents=Money(1000), |
| 2200 | + ) |
| 2201 | + with self.mock_request('subscription/plan-created.xml'): |
| 2202 | + plan.save() |
| 2203 | + |
| 2204 | + account = Account(account_code='subscribe%s' % self.test_id) |
| 2205 | + with self.mock_request('subscription/account-created.xml'): |
| 2206 | + account.save() |
| 2207 | + |
| 2208 | + manualsub = Subscription( |
| 2209 | + plan_code='basicplan', |
| 2210 | + currency='USD', |
| 2211 | + net_terms=10, |
| 2212 | + net_terms_type='net', |
| 2213 | + po_number='1000', |
| 2214 | + collection_method='manual' |
| 2215 | + ) |
| 2216 | + with self.mock_request('subscription/subscribed-manual.xml'): |
| 2217 | + account.subscribe(manualsub) |
| 2218 | + |
| 2219 | + manualsub.proration_settings = ProrationSettings(credit='none', charge='full_amount') |
| 2220 | + proration_xml = ElementTree.tostring(manualsub.proration_settings.to_element(), encoding='UTF-8') |
| 2221 | + self.assertEqual( |
| 2222 | + proration_xml, |
| 2223 | + xml('<proration_settings><charge>full_amount</charge><credit>none</credit></proration_settings>') |
| 2224 | + ) |
| 2225 | + |
| 2226 | + assert isinstance(manualsub.proration_settings, ProrationSettings) |
| 2227 | + ElementTree.tostring(account.to_element(), encoding='UTF-8') |
| 2228 | + |
| 2229 | + |
2192 | 2230 | def test_subscription_with_plan_ramp(self):
|
2193 | 2231 | plan_code = 'plan%s' % self.test_id
|
2194 | 2232 | logging.basicConfig(level=logging.DEBUG) # make sure it's init'ed
|
|
0 commit comments