From d7d42eb1101ead210dfdc80977c5ea2feab8aafd Mon Sep 17 00:00:00 2001 From: Amanda Date: Tue, 13 Aug 2024 10:55:29 -0700 Subject: [PATCH] get external sub by uuid --- recurly/__init__.py | 9 +++++ .../account/external-subscriptions.xml | 2 ++ .../get-by-external-id.xml | 1 + .../external-subscription/get-by-uuid.xml | 34 +++++++++++++++++++ tests/fixtures/external-subscription/get.xml | 3 +- tests/fixtures/external-subscription/list.xml | 2 ++ tests/test_resources.py | 30 ++++++++++++++++ 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/external-subscription/get-by-uuid.xml diff --git a/recurly/__init__.py b/recurly/__init__.py index c506cb3f..ffa0b2e2 100644 --- a/recurly/__init__.py +++ b/recurly/__init__.py @@ -2301,6 +2301,7 @@ class ExternalSubscription(Resource): 'account', 'external_id', 'external_product_reference', + 'uuid', 'external_invoices', 'external_payment_phases', 'last_purchased', @@ -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. """ diff --git a/tests/fixtures/account/external-subscriptions.xml b/tests/fixtures/account/external-subscriptions.xml index f84c3b54..f30a8c3d 100644 --- a/tests/fixtures/account/external-subscriptions.xml +++ b/tests/fixtures/account/external-subscriptions.xml @@ -14,6 +14,7 @@ Content-Type: application/xml; charset=utf-8 abcd1234 + 72bb9966bb5dc3767461ce4368a6b366 false @@ -35,6 +36,7 @@ Content-Type: application/xml; charset=utf-8 efgh5678 + 72bba6cc3a2323d04632374f0fb44a5a false diff --git a/tests/fixtures/external-subscription/get-by-external-id.xml b/tests/fixtures/external-subscription/get-by-external-id.xml index 3f1f1e96..be8ccb21 100644 --- a/tests/fixtures/external-subscription/get-by-external-id.xml +++ b/tests/fixtures/external-subscription/get-by-external-id.xml @@ -14,6 +14,7 @@ Content-Type: application/xml; charset=utf-8 abcd1234 + 72bb9966bb5dc3767461ce4368a6b366 false diff --git a/tests/fixtures/external-subscription/get-by-uuid.xml b/tests/fixtures/external-subscription/get-by-uuid.xml new file mode 100644 index 00000000..bec6f67b --- /dev/null +++ b/tests/fixtures/external-subscription/get-by-uuid.xml @@ -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 + + + + + + + abcd1234 + 72bb9966bb5dc3767461ce4368a6b366 + + + false + false + false + false + app_identifier + 1 + active + + 2022-11-03T21:57:14Z + + 2022-11-03T21:57:14Z + 2022-11-03T21:57:14Z + 2022-11-03T21:57:14Z + 2022-11-04T18:11:51Z + diff --git a/tests/fixtures/external-subscription/get.xml b/tests/fixtures/external-subscription/get.xml index 448f6f18..4209a707 100644 --- a/tests/fixtures/external-subscription/get.xml +++ b/tests/fixtures/external-subscription/get.xml @@ -10,10 +10,11 @@ Content-Type: application/xml; charset=utf-8 - + abcd1234 + 72bb9966bb5dc3767461ce4368a6b366 false diff --git a/tests/fixtures/external-subscription/list.xml b/tests/fixtures/external-subscription/list.xml index c3bb44ed..f37211e7 100644 --- a/tests/fixtures/external-subscription/list.xml +++ b/tests/fixtures/external-subscription/list.xml @@ -15,6 +15,7 @@ Content-Type: application/xml; charset=utf-8 abcd1234 + 72bb9966bb5dc3767461ce4368a6b366 false @@ -37,6 +38,7 @@ Content-Type: application/xml; charset=utf-8 efgh5678 + 72bba6cc3a2323d04632374f0fb44a5a false diff --git a/tests/test_resources.py b/tests/test_resources.py index 42620cba..28e36329 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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)