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

Get external sub by uuid #701

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions recurly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,7 @@ class ExternalSubscription(Resource):
'account',
'external_id',
'external_product_reference',
'uuid',
'external_invoices',
'external_payment_phases',
'last_purchased',
Expand Down Expand Up @@ -2334,6 +2335,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 @@ -14,6 +14,7 @@ Content-Type: application/xml; charset=utf-8
<account href="https://api.recurly.com/v2/accounts/testmock"/>
<external_invoices href="https://api.recurly.com/v2/external_subscriptions/ru8jbrg7i3c0/external_invoices"/>
<external_id>abcd1234</external_id>
<uuid>72bb9966bb5dc3767461ce4368a6b366</uuid>
<external_product_reference nil="nil"></external_product_reference>
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
Expand All @@ -35,6 +36,7 @@ Content-Type: application/xml; charset=utf-8
<account href="https://api.recurly.com/v2/accounts/testmock"/>
<external_invoices href="https://api.recurly.com/v2/external_subscriptions/ru8jbrg7i3c0/external_invoices"/>
<external_id>efgh5678</external_id>
<uuid>72bba6cc3a2323d04632374f0fb44a5a</uuid>
<external_product_reference nil="nil"></external_product_reference>
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Content-Type: application/xml; charset=utf-8
<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>
<uuid>72bb9966bb5dc3767461ce4368a6b366</uuid>
<external_product_reference nil="nil"></external_product_reference>
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
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>
<uuid>72bb9966bb5dc3767461ce4368a6b366</uuid>
<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>
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,10 +10,11 @@ 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>
<uuid>72bb9966bb5dc3767461ce4368a6b366</uuid>
<external_product_reference nil="nil"></external_product_reference>
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
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 @@ -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_payment_phases href="https://api.recurly.com/v2/external_subscriptions/ru8jbrg7i3c0/external_payment_phases"/>
<external_id>abcd1234</external_id>
<uuid>72bb9966bb5dc3767461ce4368a6b366</uuid>
<external_product_reference nil="nil"></external_product_reference>
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
Expand All @@ -37,6 +38,7 @@ Content-Type: application/xml; charset=utf-8
<external_invoices href="https://api.recurly.com/v2/external_subscriptions/ru2208s6hmf0/external_invoices"/>
<external_payment_phases href="https://api.recurly.com/v2/external_subscriptions/ru2208s6hmf0/external_payment_phases"/>
<external_id>efgh5678</external_id>
<uuid>72bba6cc3a2323d04632374f0fb44a5a</uuid>
<external_product_reference nil="nil"></external_product_reference>
<last_purchased nil="nil"></last_purchased>
<auto_renew type="boolean">false</auto_renew>
Expand Down
30 changes: 30 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -3475,6 +3475,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 @@ -3493,6 +3494,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 @@ -3518,6 +3520,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 @@ -3536,6 +3539,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 @@ -3559,6 +3563,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 @@ -3582,6 +3587,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
Loading