From b2ff1a1304f96c158de5df38579b2c63c0346f41 Mon Sep 17 00:00:00 2001 From: 8eth Date: Wed, 7 Feb 2024 15:21:02 -0800 Subject: [PATCH] add-revrec-for-plans --- recurly/__init__.py | 6 ++ tests/fixtures/plan/created-with-revrec.xml | 76 +++++++++++++++++++++ tests/fixtures/plan/exists_with_revrec.xml | 57 ++++++++++++++++ tests/fixtures/plan/updated_with_revrec.xml | 67 ++++++++++++++++++ tests/test_resources.py | 61 +++++++++++++++++ 5 files changed, 267 insertions(+) create mode 100644 tests/fixtures/plan/created-with-revrec.xml create mode 100644 tests/fixtures/plan/exists_with_revrec.xml create mode 100644 tests/fixtures/plan/updated_with_revrec.xml diff --git a/recurly/__init__.py b/recurly/__init__.py index 29f54d02..642b8d80 100644 --- a/recurly/__init__.py +++ b/recurly/__init__.py @@ -1527,6 +1527,12 @@ class Plan(Resource): 'trial_interval_unit', 'accounting_code', 'setup_fee_accounting_code', + 'liability_gl_account_id', + 'revenue_gl_account_id', + 'performance_obligation_id', + 'setup_fee_liability_gl_account_id', + 'setup_fee_revenue_gl_account_id', + 'setup_fee_performance_obligation_id', 'created_at', 'updated_at', 'tax_exempt', diff --git a/tests/fixtures/plan/created-with-revrec.xml b/tests/fixtures/plan/created-with-revrec.xml new file mode 100644 index 00000000..5906909c --- /dev/null +++ b/tests/fixtures/plan/created-with-revrec.xml @@ -0,0 +1,76 @@ +POST https://api.recurly.com/v2/plans 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 + + + + t5ejtge1xw0x + RevRec Plan + 5 + planmock + t5ejtgf1vxh1 + + 200 + + t5ejtge1xw0x + 5 + t5ejtgf1vxh1 + + 1000 + + + +HTTP/1.1 201 Created +Content-Type: application/xml; charset=utf-8 +Location: https://api.recurly.com/v2/plans/planmock + + + + + planmock + RevRec Plan + + + + false + false + false + false + unit + + 1 + months + 0 + days + 1 + + + t5ejtge1xw0x + t5ejtgf1vxh1 + 5 + t5ejtge1xw0x + t5ejtgf1vxh1 + 5 + false + 2024-02-06T21:47:46Z + 2024-02-06T21:47:46Z + true + fixed + + + evenly + evenly + true + false + + + 1000 + + + 200 + + + diff --git a/tests/fixtures/plan/exists_with_revrec.xml b/tests/fixtures/plan/exists_with_revrec.xml new file mode 100644 index 00000000..13147ec0 --- /dev/null +++ b/tests/fixtures/plan/exists_with_revrec.xml @@ -0,0 +1,57 @@ +GET https://api.recurly.com/v2/plans/planmock 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 + + + + + planmock + RevRec Plan + + + + false + false + false + false + unit + + 1 + months + 0 + days + 1 + + + t5ejtge1xw0x + t5ejtgf1vxh1 + 5 + t5ejtge1xw0x + t5ejtgf1vxh1 + 5 + false + 2024-02-06T21:47:46Z + 2024-02-06T21:47:46Z + true + fixed + + + evenly + evenly + true + false + + + 1000 + + + 200 + + + diff --git a/tests/fixtures/plan/updated_with_revrec.xml b/tests/fixtures/plan/updated_with_revrec.xml new file mode 100644 index 00000000..010066e9 --- /dev/null +++ b/tests/fixtures/plan/updated_with_revrec.xml @@ -0,0 +1,67 @@ +PUT https://api.recurly.com/v2/plans/planmock 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 + + + + + + + + + + + +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + planmock + RevRec Plan + + + + false + false + false + false + unit + + 1 + months + 0 + days + 1 + + + + + 6 + + + 4 + false + 2024-02-06T22:01:53Z + 2024-02-06T22:01:53Z + true + fixed + + + evenly + evenly + true + false + + + 1000 + + + 200 + + + diff --git a/tests/test_resources.py b/tests/test_resources.py index d77e5dd2..d24f037d 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -1841,6 +1841,67 @@ def test_plan_with_ramps(self): with self.mock_request('plan/updated_with_ramps.xml'): plan.save() + def test_plan_with_revrec(self): + plan_code = 'plan%s' % self.test_id + with self.mock_request('plan/does-not-exist.xml'): + self.assertRaises(NotFoundError, Plan.get, plan_code) + + plan = Plan( + name='RevRec Plan', + plan_code=plan_code, + setup_fee_in_cents=Money(200), + unit_amount_in_cents=Money(1000), + liability_gl_account_id='t5ejtge1xw0x', + revenue_gl_account_id='t5ejtgf1vxh1', + performance_obligation_id='5', + setup_fee_liability_gl_account_id='t5ejtge1xw0x', + setup_fee_revenue_gl_account_id='t5ejtgf1vxh1', + setup_fee_performance_obligation_id='5' + ) + + with self.mock_request('plan/created-with-revrec.xml'): + plan.save() + + self.assertEqual(plan.plan_code, plan_code) + self.assertEqual(plan.name, 'RevRec Plan') + self.assertEqual(plan.liability_gl_account_id, 't5ejtge1xw0x') + self.assertEqual(plan.revenue_gl_account_id, 't5ejtgf1vxh1') + self.assertEqual(plan.performance_obligation_id, '5') + self.assertEqual(plan.setup_fee_liability_gl_account_id, 't5ejtge1xw0x') + self.assertEqual(plan.setup_fee_revenue_gl_account_id, 't5ejtgf1vxh1') + self.assertEqual(plan.setup_fee_performance_obligation_id, '5') + + with self.mock_request('plan/exists_with_revrec.xml'): + same_plan = Plan.get(plan_code) + + self.assertEqual(plan.plan_code, plan_code) + self.assertEqual(plan.name, 'RevRec Plan') + self.assertEqual(plan.liability_gl_account_id, 't5ejtge1xw0x') + self.assertEqual(plan.revenue_gl_account_id, 't5ejtgf1vxh1') + self.assertEqual(plan.performance_obligation_id, '5') + self.assertEqual(plan.setup_fee_liability_gl_account_id, 't5ejtge1xw0x') + self.assertEqual(plan.setup_fee_revenue_gl_account_id, 't5ejtgf1vxh1') + self.assertEqual(plan.setup_fee_performance_obligation_id, '5') + + plan.liability_gl_account_id = None + plan.revenue_gl_account_id = None + plan.performance_obligation_id = None + plan.setup_fee_liability_gl_account_id = None + plan.setup_fee_revenue_gl_account_id = None + plan.setup_fee_performance_obligation_id = None + + with self.mock_request('plan/updated_with_revrec.xml'): + plan.save() + + self.assertEqual(plan.plan_code, plan_code) + self.assertEqual(plan.name, 'RevRec Plan') + self.assertEqual(plan.liability_gl_account_id, None) + self.assertEqual(plan.revenue_gl_account_id, None) + self.assertEqual(plan.performance_obligation_id, '6') + self.assertEqual(plan.setup_fee_liability_gl_account_id, None) + self.assertEqual(plan.setup_fee_revenue_gl_account_id, None) + self.assertEqual(plan.setup_fee_performance_obligation_id, '4') + def test_preview_subscription_change(self): with self.mock_request('subscription/show.xml'): sub = Subscription.get('123456789012345678901234567890ab')