diff --git a/recurly/__init__.py b/recurly/__init__.py index ada9b20e..2c8432b6 100644 --- a/recurly/__init__.py +++ b/recurly/__init__.py @@ -2278,6 +2278,8 @@ class ExternalSubscription(Resource): 'last_purchased', 'auto_renew', 'in_grace_period', + 'import', + 'test', 'app_identifier', 'quantity', 'state', @@ -2296,6 +2298,22 @@ def get_external_payment_phase(self, external_payment_phase_uuid): resp, elem = ExternalPaymentPhase().element_for_url(url) return ExternalPaymentPhase().from_element(elem) + @property + def is_import(self): + return getattr(self, 'import') + + @is_import.setter + def is_import(self, value): + setattr(self, 'import', value) + + @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. """ diff --git a/tests/fixtures/account/external-subscriptions.xml b/tests/fixtures/account/external-subscriptions.xml index c0d6094f..261298d6 100644 --- a/tests/fixtures/account/external-subscriptions.xml +++ b/tests/fixtures/account/external-subscriptions.xml @@ -18,6 +18,8 @@ Content-Type: application/xml; charset=utf-8 false false + false + false 1 active @@ -37,6 +39,8 @@ Content-Type: application/xml; charset=utf-8 false false + false + false app_identifier 1 active diff --git a/tests/fixtures/external-subscription/get.xml b/tests/fixtures/external-subscription/get.xml index 476a7f99..0b3c5e11 100644 --- a/tests/fixtures/external-subscription/get.xml +++ b/tests/fixtures/external-subscription/get.xml @@ -18,6 +18,8 @@ Content-Type: application/xml; charset=utf-8 false false + false + false app_identifier 1 active diff --git a/tests/fixtures/external-subscription/list.xml b/tests/fixtures/external-subscription/list.xml index cbe5c7a9..a9c5af7a 100644 --- a/tests/fixtures/external-subscription/list.xml +++ b/tests/fixtures/external-subscription/list.xml @@ -19,6 +19,8 @@ Content-Type: application/xml; charset=utf-8 false false + false + false 1 active @@ -39,6 +41,8 @@ Content-Type: application/xml; charset=utf-8 false false + false + false app_identifier 1 active diff --git a/tests/test_resources.py b/tests/test_resources.py index 6d1f0eaa..cca53525 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -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].is_import, 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') @@ -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].is_import, 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') @@ -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].is_import, 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') @@ -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].is_import, 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') @@ -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.is_import, 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.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.is_import, 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')