Skip to content

Commit

Permalink
Merge pull request #697 from recurly/v2_get_external_subscription_by_…
Browse files Browse the repository at this point in the history
…external_id

V2 get external subscription by external
  • Loading branch information
amandamfielding authored Jul 3, 2024
2 parents 4b4df60 + e7cb741 commit 470ae5f
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
10 changes: 10 additions & 0 deletions recurly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,8 @@ class ExternalSubscription(Resource):
'last_purchased',
'auto_renew',
'in_grace_period',
'imported',
'test',
'app_identifier',
'quantity',
'state',
Expand All @@ -2296,6 +2298,14 @@ def get_external_payment_phase(self, external_payment_phase_uuid):
resp, elem = ExternalPaymentPhase().element_for_url(url)
return ExternalPaymentPhase().from_element(elem)

@classmethod
def get_by_external_id(cls, external_id):
"""Return a `External Subscription` instance identified by
the given external id.
"""
return cls.get("external-id-{}".format(external_id))

class ExternalProductReference(Resource):

""" A reference of a product from an external resource that is not managed by the Recurly platform and instead is managed by third-party platforms like Apple Store and Google Play. """
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/account/external-subscriptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Content-Type: application/xml; charset=utf-8
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
<imported type="boolean">false</imported>
<test type="boolean">false</test>
<app_identifier nil="nil"></app_identifier>
<quantity type="integer">1</quantity>
<state>active</state>
Expand All @@ -37,6 +39,8 @@ Content-Type: application/xml; charset=utf-8
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
<imported type="boolean">false</imported>
<test type="boolean">false</test>
<app_identifier>app_identifier</app_identifier>
<quantity type="integer">1</quantity>
<state>active</state>
Expand Down
33 changes: 33 additions & 0 deletions tests/fixtures/external-subscription/get-by-external-id.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
GET https://api.recurly.com/v2/external_subscriptions/external-id-abcd1234 HTTP/1.1
X-Api-Version: {api-version}
Accept: application/xml
Authorization: Basic YXBpa2V5Og==
User-Agent: {user-agent}


HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<external_subscription href="https://api.recurly.com/v2/external_subscriptions/sd28t3zdm59r">
<account href="https://api.recurly.com/v2/accounts/pphino"/>
<external_invoices href="https://api.recurly.com/v2/external_subscriptions/sd28t3zdm59r/external_invoices"/>
<external_payment_phases href="https://api.recurly.com/v2/external_subscriptions/sd28t3zdm59r/external_payment_phases"/>
<external_id>abcd1234</external_id>
<external_product_reference nil="nil"></external_product_reference>
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
<imported type="boolean">false</imported>
<test type="boolean">false</test>
<app_identifier>app_identifier</app_identifier>
<quantity type="integer">1</quantity>
<state>active</state>
<activated_at nil="nil"></activated_at>
<canceled_at type="datetime">2022-11-03T21:57:14Z</canceled_at>
<expires_at nil="nil"></expires_at>
<trial_started_at type="datetime">2022-11-03T21:57:14Z</trial_started_at>
<trial_ends_at type="datetime">2022-11-03T21:57:14Z</trial_ends_at>
<created_at type="datetime">2022-11-03T21:57:14Z</created_at>
<updated_at type="datetime">2022-11-04T18:11:51Z</updated_at>
</external_subscription>
2 changes: 2 additions & 0 deletions tests/fixtures/external-subscription/get.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Content-Type: application/xml; charset=utf-8
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
<imported type="boolean">false</imported>
<test type="boolean">false</test>
<app_identifier>app_identifier</app_identifier>
<quantity type="integer">1</quantity>
<state>active</state>
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/external-subscription/list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Content-Type: application/xml; charset=utf-8
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
<imported type="boolean">false</imported>
<test type="boolean">false</test>
<app_identifier nil="nil"></app_identifier>
<quantity type="integer">1</quantity>
<state>active</state>
Expand All @@ -39,6 +41,8 @@ Content-Type: application/xml; charset=utf-8
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
<imported type="boolean">false</imported>
<test type="boolean">false</test>
<app_identifier>app_identifier</app_identifier>
<quantity type="integer">1</quantity>
<state>active</state>
Expand Down
33 changes: 33 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -3413,6 +3413,8 @@ def test_external_subscriptions_on_account(self):
self.assertEqual(external_subscriptions[0].last_purchased, None)
self.assertEqual(external_subscriptions[0].auto_renew, False)
self.assertEqual(external_subscriptions[0].in_grace_period, False)
self.assertEqual(external_subscriptions[0].imported, False)
self.assertEqual(external_subscriptions[0].test, False)
self.assertEqual(external_subscriptions[0].app_identifier, None)
self.assertEqual(external_subscriptions[0].quantity, 1)
self.assertEqual(external_subscriptions[0].state, 'active')
Expand All @@ -3429,6 +3431,8 @@ def test_external_subscriptions_on_account(self):
self.assertEqual(external_subscriptions[1].last_purchased, None)
self.assertEqual(external_subscriptions[1].auto_renew, False)
self.assertEqual(external_subscriptions[1].in_grace_period, False)
self.assertEqual(external_subscriptions[1].imported, False)
self.assertEqual(external_subscriptions[1].test, False)
self.assertEqual(external_subscriptions[1].app_identifier, 'app_identifier')
self.assertEqual(external_subscriptions[1].quantity, 1)
self.assertEqual(external_subscriptions[1].state, 'active')
Expand All @@ -3452,6 +3456,8 @@ def test_list_external_subscriptions(self):
self.assertEqual(external_subscriptions[0].last_purchased, None)
self.assertEqual(external_subscriptions[0].auto_renew, False)
self.assertEqual(external_subscriptions[0].in_grace_period, False)
self.assertEqual(external_subscriptions[0].imported, False)
self.assertEqual(external_subscriptions[0].test, False)
self.assertEqual(external_subscriptions[0].app_identifier, None)
self.assertEqual(external_subscriptions[0].quantity, 1)
self.assertEqual(external_subscriptions[0].state, 'active')
Expand All @@ -3468,6 +3474,8 @@ def test_list_external_subscriptions(self):
self.assertEqual(external_subscriptions[1].last_purchased, None)
self.assertEqual(external_subscriptions[1].auto_renew, False)
self.assertEqual(external_subscriptions[1].in_grace_period, False)
self.assertEqual(external_subscriptions[1].imported, False)
self.assertEqual(external_subscriptions[1].test, False)
self.assertEqual(external_subscriptions[1].app_identifier, 'app_identifier')
self.assertEqual(external_subscriptions[1].quantity, 1)
self.assertEqual(external_subscriptions[1].state, 'active')
Expand All @@ -3489,6 +3497,31 @@ def test_get_external_subscription(self):
self.assertEqual(external_subscription.last_purchased, None)
self.assertEqual(external_subscription.auto_renew, False)
self.assertEqual(external_subscription.in_grace_period, False)
self.assertEqual(external_subscription.imported, False)
self.assertEqual(external_subscription.test, False)
self.assertEqual(external_subscription.app_identifier, 'app_identifier')
self.assertEqual(external_subscription.quantity, 1)
self.assertEqual(external_subscription.state, 'active')
self.assertEqual(external_subscription.activated_at, None)
self.assertEqual(external_subscription.canceled_at, datetime(2022, 11, 3, 21, 57, 14, tzinfo=external_subscription.canceled_at.tzinfo))
self.assertEqual(external_subscription.expires_at, None)
self.assertEqual(external_subscription.trial_started_at, datetime(2022, 11, 3, 21, 57, 14, tzinfo=external_subscription.trial_started_at.tzinfo))
self.assertEqual(external_subscription.trial_ends_at, datetime(2022, 11, 3, 21, 57, 14, tzinfo=external_subscription.trial_ends_at.tzinfo))
self.assertEqual(external_subscription.created_at, datetime(2022, 11, 3, 21, 57, 14, tzinfo=external_subscription.created_at.tzinfo))
self.assertEqual(external_subscription.updated_at, datetime(2022, 11, 4, 18, 11, 51, tzinfo=external_subscription.updated_at.tzinfo))

def test_get_external_subscription_by_external_id(self):

with self.mock_request('external-subscription/get-by-external-id.xml'):
external_subscription = ExternalSubscription.get_by_external_id('abcd1234')

self.assertEqual(external_subscription.external_id, 'abcd1234')
self.assertEqual(external_subscription.external_product_reference, None)
self.assertEqual(external_subscription.last_purchased, None)
self.assertEqual(external_subscription.auto_renew, False)
self.assertEqual(external_subscription.in_grace_period, False)
self.assertEqual(external_subscription.imported, False)
self.assertEqual(external_subscription.test, False)
self.assertEqual(external_subscription.app_identifier, 'app_identifier')
self.assertEqual(external_subscription.quantity, 1)
self.assertEqual(external_subscription.state, 'active')
Expand Down

0 comments on commit 470ae5f

Please sign in to comment.