From d74338ec07691fb08e572ea45d07b6fa9a23ed4d Mon Sep 17 00:00:00 2001 From: 8eth Date: Wed, 14 Feb 2024 14:48:03 -0800 Subject: [PATCH 1/2] add-revrec-for-gift-cards --- recurly/__init__.py | 3 ++ tests/fixtures/gift_cards/get.xml | 39 +++++++++++++++++ tests/fixtures/gift_cards/list.xml | 69 ++++++++++++++++++++++++++++++ tests/test_resources.py | 27 ++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 tests/fixtures/gift_cards/get.xml create mode 100644 tests/fixtures/gift_cards/list.xml diff --git a/recurly/__init__.py b/recurly/__init__.py index bf4c26ec..0db8bb90 100644 --- a/recurly/__init__.py +++ b/recurly/__init__.py @@ -787,6 +787,9 @@ class GiftCard(Resource): 'updated_at', 'unit_amount_in_cents', 'billing_info', + 'liability_gl_account_id', + 'revenue_gl_account_id', + 'performance_obligation_id' ) _classes_for_nodename = {'recipient_account': Account,'gifter_account': Account, 'delivery': Delivery} diff --git a/tests/fixtures/gift_cards/get.xml b/tests/fixtures/gift_cards/get.xml new file mode 100644 index 00000000..6e67fc84 --- /dev/null +++ b/tests/fixtures/gift_cards/get.xml @@ -0,0 +1,39 @@ +GET https://api.recurly.com/v2/gift_cards/3880289408739841209 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 + + + + + + 3880289408739841209 + ASDR63PM4JUTXW9I + test_gift_card + 1000 + USD + + email + sally@example.com + + Sally + Smith +
+ John + Congrats! +
+ 2023-08-29T18:42:23Z + 2023-08-29T18:42:23Z + 2023-08-29T18:42:23Z + + + + t5ejtge1xw0x + t5ejtgf1vxh1 + 4 +
diff --git a/tests/fixtures/gift_cards/list.xml b/tests/fixtures/gift_cards/list.xml new file mode 100644 index 00000000..afd0b6ce --- /dev/null +++ b/tests/fixtures/gift_cards/list.xml @@ -0,0 +1,69 @@ +GET https://api.recurly.com/v2/gift_cards 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 + + + + + + + 3880289408739841209 + ASDR63PM4JUTXW9I + test_gift_card + 1000 + USD + + email + sally@example.com + + Sally + Smith +
+ John + Congrats! +
+ 2023-08-29T18:42:23Z + 2023-08-29T18:42:23Z + 2023-08-29T18:42:23Z + + +
+ t5ejtge1xw0x + t5ejtgf1vxh1 + 4 + + + + + 3951365864235636055 + 6HZDUC8S1AGX7WVB + test_gift_card + 1000 + USD + + email + john@example.com + + John + Smith +
+ Sally + Hi John, Happy Birthday! I hope you have a great day! Love, Sally +
+ 2023-12-05T20:18:37Z + 2023-12-05T20:18:37Z + 2023-12-05T20:18:37Z + + +
+ t5ejtge1xw0x + t5ejtgf1vxh1 + 4 + + diff --git a/tests/test_resources.py b/tests/test_resources.py index 94d58c13..8e6a9b32 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -2901,6 +2901,33 @@ def _build_gift_card(self): gift_card.gifter_account = account return gift_card + def test_get_gift_card(self): + with self.mock_request('gift_cards/get.xml'): + gift_card = GiftCard.get(3880289408739841209) + + self.assertEqual(gift_card.id, 3880289408739841209) + self.assertEqual(gift_card.redemption_code, 'ASDR63PM4JUTXW9I') + self.assertEqual(gift_card.product_code, 'test_gift_card') + self.assertEqual(gift_card.unit_amount_in_cents, 1000) + self.assertEqual(gift_card.currency, 'USD') + self.assertEqual(gift_card.delivery.method, 'email') + self.assertEqual(gift_card.delivery.email_address, 'sally@example.com') + self.assertEqual(gift_card.delivery.first_name, 'Sally') + self.assertEqual(gift_card.delivery.last_name, 'Smith') + self.assertEqual(gift_card.delivery.gifter_name, 'John') + self.assertEqual(gift_card.delivery.personal_message, 'Congrats!') + self.assertEqual(gift_card.liability_gl_account_id, 't5ejtge1xw0x') + self.assertEqual(gift_card.revenue_gl_account_id, 't5ejtgf1vxh1') + self.assertEqual(gift_card.performance_obligation_id, '4') + + def test_list_gift_cards(self): + with self.mock_request('gift_cards/list.xml'): + gift_cards = GiftCard.all() + + self.assertEqual(len(gift_cards), 2) + self.assertIsInstance(gift_cards[0], GiftCard) + self.assertIsInstance(gift_cards[1], GiftCard) + def test_gift_cards_purchase(self): gift_card = self._build_gift_card() From 62ab220db700ab064a64473c38f7e4482796bfbe Mon Sep 17 00:00:00 2001 From: 8eth Date: Thu, 15 Feb 2024 11:20:27 -0800 Subject: [PATCH 2/2] add-revrec-for-items --- recurly/__init__.py | 3 ++ tests/fixtures/item/created-with-revrec.xml | 43 +++++++++++++++++++++ tests/fixtures/item/exists-with-revrec.xml | 19 +++++++++ tests/fixtures/item/updated-with-revrec.xml | 40 +++++++++++++++++++ tests/test_resources.py | 43 +++++++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 tests/fixtures/item/created-with-revrec.xml create mode 100644 tests/fixtures/item/exists-with-revrec.xml create mode 100644 tests/fixtures/item/updated-with-revrec.xml diff --git a/recurly/__init__.py b/recurly/__init__.py index 0db8bb90..7c23c879 100644 --- a/recurly/__init__.py +++ b/recurly/__init__.py @@ -1000,6 +1000,9 @@ class Item(Resource): 'created_at', 'updated_at', 'deleted_at', + 'liability_gl_account_id', + 'revenue_gl_account_id', + 'performance_obligation_id' ) class Adjustment(Resource): diff --git a/tests/fixtures/item/created-with-revrec.xml b/tests/fixtures/item/created-with-revrec.xml new file mode 100644 index 00000000..b7147b3e --- /dev/null +++ b/tests/fixtures/item/created-with-revrec.xml @@ -0,0 +1,43 @@ +POST https://api.recurly.com/v2/items HTTP/1.1 +X-Api-Version: {api-version} +Accept: application/xml +Authorization: Basic YXBpa2V5Og== +User-Agent: {user-agent} +Content-Type: application/xml; charset=utf-8 + + + + An item of the mocked variety + itemmock + t5ejtge1xw0x + Mock Item + 5 + t5ejtgf1vxh1 + + +HTTP/1.1 201 Created +Content-Type: application/xml; charset=utf-8 +Location: https://api.recurly.com/v2/items/itemmock + + + + itemmock + Mock Item + handcrafted-plastic-soap + An item of the mocked variety + true + 1569273867 + never + + + color + blue + + + 2019-09-23T21:25:45Z + 2019-09-23T21:25:45Z + + t5ejtge1xw0x + t5ejtgf1vxh1 + 5 + diff --git a/tests/fixtures/item/exists-with-revrec.xml b/tests/fixtures/item/exists-with-revrec.xml new file mode 100644 index 00000000..4864f3b4 --- /dev/null +++ b/tests/fixtures/item/exists-with-revrec.xml @@ -0,0 +1,19 @@ +GET https://api.recurly.com/v2/items/itemmock 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 + + + + itemmock + Mock Item + Sleek Plastic + t5ejtge1xw0x + t5ejtgf1vxh1 + 5 + diff --git a/tests/fixtures/item/updated-with-revrec.xml b/tests/fixtures/item/updated-with-revrec.xml new file mode 100644 index 00000000..89ef79b3 --- /dev/null +++ b/tests/fixtures/item/updated-with-revrec.xml @@ -0,0 +1,40 @@ +PUT https://api.recurly.com/v2/items/itemmock HTTP/1.1 +X-Api-Version: {api-version} +Accept: application/xml +Authorization: Basic YXBpa2V5Og== +User-Agent: {user-agent} +Content-Type: application/xml; charset=utf-8 + + + + A mocked description + + + + + +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + itemmock + Mock Item + handcrafted-plastic-soap + A mocked description + true + 1569273867 + never + + + color + blue + + + 2019-09-23T21:25:45Z + 2019-09-23T21:25:45Z + + + + 6 + diff --git a/tests/test_resources.py b/tests/test_resources.py index 8e6a9b32..d8eb7685 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -1712,6 +1712,49 @@ def test_item(self): with self.mock_request('item/deleted.xml'): item.delete() + def test_item_with_revrec(self): + item_code = 'item%s' % self.test_id + with self.mock_request('item/does-not-exist.xml'): + self.assertRaises(NotFoundError, Item.get, item_code) + + item = Item( + item_code=item_code, + name='Mock Item', + description='An item of the mocked variety', + liability_gl_account_id='t5ejtge1xw0x', + revenue_gl_account_id='t5ejtgf1vxh1', + performance_obligation_id='5' + ) + + with self.mock_request('item/created-with-revrec.xml'): + item.save() + + self.assertEqual(item.item_code, item_code) + self.assertEqual(item.liability_gl_account_id, 't5ejtge1xw0x') + self.assertEqual(item.revenue_gl_account_id, 't5ejtgf1vxh1') + self.assertEqual(item.performance_obligation_id, '5') + + with self.mock_request('item/exists-with-revrec.xml'): + same_item = Item.get(item_code) + + self.assertEqual(same_item.item_code, item_code) + self.assertEqual(same_item.liability_gl_account_id, 't5ejtge1xw0x') + self.assertEqual(same_item.revenue_gl_account_id, 't5ejtgf1vxh1') + self.assertEqual(same_item.performance_obligation_id, '5') + + item.description = 'A mocked description' + item.liability_gl_account_id = None + item.revenue_gl_account_id = None + item.performance_obligation_id = None + + with self.mock_request('item/updated-with-revrec.xml'): + item.save() + + self.assertEqual(item.description, 'A mocked description') + self.assertEqual(item.liability_gl_account_id, None) + self.assertEqual(item.revenue_gl_account_id, None) + self.assertEqual(item.performance_obligation_id, '6') + def test_custom_field_definition(self): """Test custom field definitions list""" with self.mock_request('custom_field_definitions/list.xml'):