Skip to content

Commit

Permalink
get external sub by uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
amandamfielding committed Aug 14, 2024
1 parent 7f547e5 commit b753919
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 1 deletion.
9 changes: 9 additions & 0 deletions recurly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,7 @@ class ExternalSubscription(Resource):
'account',
'external_id',
'external_product_reference',
'uuid',
'external_invoices',
'external_payment_phases',
'last_purchased',
Expand Down Expand Up @@ -2310,6 +2311,14 @@ def get_by_external_id(cls, external_id):
"""
return cls.get("external-id-{}".format(external_id))

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

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
2 changes: 2 additions & 0 deletions tests/fixtures/account/external-subscriptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Content-Type: application/xml; charset=utf-8
<external_invoices href="https://api.recurly.com/v2/external_subscriptions/ru8jbrg7i3c0/external_invoices"/>
<external_id>abcd1234</external_id>
<external_product_reference nil="nil"></external_product_reference>
<uuid>72bb9966bb5dc3767461ce4368a6b366</uuid>
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
Expand All @@ -36,6 +37,7 @@ Content-Type: application/xml; charset=utf-8
<external_invoices href="https://api.recurly.com/v2/external_subscriptions/ru8jbrg7i3c0/external_invoices"/>
<external_id>efgh5678</external_id>
<external_product_reference nil="nil"></external_product_reference>
<uuid>72bba6cc3a2323d04632374f0fb44a5a</uuid>
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Content-Type: application/xml; charset=utf-8
<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>
<uuid>72bb9966bb5dc3767461ce4368a6b366</uuid>
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
Expand Down
34 changes: 34 additions & 0 deletions tests/fixtures/external-subscription/get-by-uuid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
GET https://api.recurly.com/v2/external_subscriptions/uuid-72bb9966bb5dc3767461ce4368a6b366 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/testmock"/>
<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>
<uuid>72bb9966bb5dc3767461ce4368a6b366</uuid>
<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>
3 changes: 2 additions & 1 deletion tests/fixtures/external-subscription/get.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ 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"/>
<account href="https://api.recurly.com/v2/accounts/testmock"/>
<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>
<uuid>72bb9966bb5dc3767461ce4368a6b366</uuid>
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/external-subscription/list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Content-Type: application/xml; charset=utf-8
<external_payment_phases href="https://api.recurly.com/v2/external_subscriptions/ru8jbrg7i3c0/external_payment_phases"/>
<external_id>abcd1234</external_id>
<external_product_reference nil="nil"></external_product_reference>
<uuid>72bb9966bb5dc3767461ce4368a6b366</uuid>
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
Expand All @@ -38,6 +39,7 @@ Content-Type: application/xml; charset=utf-8
<external_payment_phases href="https://api.recurly.com/v2/external_subscriptions/ru2208s6hmf0/external_payment_phases"/>
<external_id>efgh5678</external_id>
<external_product_reference nil="nil"></external_product_reference>
<uuid>72bba6cc3a2323d04632374f0fb44a5a</uuid>
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
<in_grace_period type="boolean">false</in_grace_period>
Expand Down
30 changes: 30 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -3422,6 +3422,7 @@ def test_external_subscriptions_on_account(self):

self.assertEqual(external_subscriptions[0].external_id, 'abcd1234')
self.assertEqual(external_subscriptions[0].external_product_reference, None)
self.assertEqual(external_subscriptions[0].uuid, '72bb9966bb5dc3767461ce4368a6b366')
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)
Expand All @@ -3440,6 +3441,7 @@ def test_external_subscriptions_on_account(self):

self.assertEqual(external_subscriptions[1].external_id, 'efgh5678')
self.assertEqual(external_subscriptions[1].external_product_reference, None)
self.assertEqual(external_subscriptions[1].uuid, '72bba6cc3a2323d04632374f0fb44a5a')
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)
Expand All @@ -3465,6 +3467,7 @@ def test_list_external_subscriptions(self):

self.assertEqual(external_subscriptions[0].external_id, 'abcd1234')
self.assertEqual(external_subscriptions[0].external_product_reference, None)
self.assertEqual(external_subscriptions[0].uuid, '72bb9966bb5dc3767461ce4368a6b366')
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)
Expand All @@ -3483,6 +3486,7 @@ def test_list_external_subscriptions(self):

self.assertEqual(external_subscriptions[1].external_id, 'efgh5678')
self.assertEqual(external_subscriptions[1].external_product_reference, None)
self.assertEqual(external_subscriptions[1].uuid, '72bba6cc3a2323d04632374f0fb44a5a')
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)
Expand All @@ -3506,6 +3510,7 @@ def test_get_external_subscription(self):

self.assertEqual(external_subscription.external_id, 'abcd1234')
self.assertEqual(external_subscription.external_product_reference, None)
self.assertEqual(external_subscription.uuid, '72bb9966bb5dc3767461ce4368a6b366')
self.assertEqual(external_subscription.last_purchased, None)
self.assertEqual(external_subscription.auto_renew, False)
self.assertEqual(external_subscription.in_grace_period, False)
Expand All @@ -3529,6 +3534,31 @@ def test_get_external_subscription_by_external_id(self):

self.assertEqual(external_subscription.external_id, 'abcd1234')
self.assertEqual(external_subscription.external_product_reference, None)
self.assertEqual(external_subscription.uuid, '72bb9966bb5dc3767461ce4368a6b366')
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-uuid.xml'):
external_subscription = ExternalSubscription.get_by_uuid('72bb9966bb5dc3767461ce4368a6b366')

self.assertEqual(external_subscription.external_id, 'abcd1234')
self.assertEqual(external_subscription.external_product_reference, None)
self.assertEqual(external_subscription.uuid, '72bb9966bb5dc3767461ce4368a6b366')
self.assertEqual(external_subscription.last_purchased, None)
self.assertEqual(external_subscription.auto_renew, False)
self.assertEqual(external_subscription.in_grace_period, False)
Expand Down

0 comments on commit b753919

Please sign in to comment.