diff --git a/CHANGELOG b/CHANGELOG index 795baab5..246a91b4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ - Added support for Fulfillment.update_tracking ([#432](https://github.com/Shopify/shopify_python_api/pull/432)) - Add FulfillmentEvent resource ([#454](https://github.com/Shopify/shopify_python_api/pull/454)) - Fix for being unable to get the len() of a filter ([#456](https://github.com/Shopify/shopify_python_api/pull/456)) +- Add ApplicationCredit resource ([#457](https://github.com/Shopify/shopify_python_api/pull/457)) == Version 8.2.0 - [Feature] Add support for Dynamic API Versioning. When the library is initialized, it will now make a request to diff --git a/shopify/resources/__init__.py b/shopify/resources/__init__.py index 803c5351..16220739 100644 --- a/shopify/resources/__init__.py +++ b/shopify/resources/__init__.py @@ -17,6 +17,7 @@ from .tax_line import TaxLine from .script_tag import ScriptTag from .application_charge import ApplicationCharge +from .application_credit import ApplicationCredit from .recurring_application_charge import RecurringApplicationCharge from .usage_charge import UsageCharge from .asset import Asset diff --git a/shopify/resources/application_credit.py b/shopify/resources/application_credit.py new file mode 100644 index 00000000..83b8de1f --- /dev/null +++ b/shopify/resources/application_credit.py @@ -0,0 +1,4 @@ +from ..base import ShopifyResource + +class ApplicationCredit(ShopifyResource): + pass diff --git a/test/application_credit_test.py b/test/application_credit_test.py new file mode 100644 index 00000000..630d023d --- /dev/null +++ b/test/application_credit_test.py @@ -0,0 +1,38 @@ +import shopify +import json +from test.test_helper import TestCase + +class ApplicationCreditTest(TestCase): + def test_get_application_credit(self): + self.fake('application_credits/445365009', method='GET', body=self.load_fixture('application_credit'), code=200) + application_credit = shopify.ApplicationCredit.find(445365009) + self.assertEqual('5.00', application_credit.amount) + + def test_get_all_application_credits(self): + self.fake('application_credits', method='GET', body=self.load_fixture('application_credits'), code=200) + application_credits = shopify.ApplicationCredit.find() + self.assertEqual(1, len(application_credits)) + self.assertEqual(445365009, application_credits[0].id) + + def test_create_application_credit(self): + self.fake( + 'application_credits', + method='POST', + body=self.load_fixture('application_credit'), + headers={'Content-type': 'application/json'}, + code=201 + ) + + application_credit = shopify.ApplicationCredit.create({ + 'description': 'application credit for refund', + 'amount': 5.0 + }) + + expected_body = { + "application_credit": { + "description": "application credit for refund", + "amount": 5.0 + } + } + + self.assertEqual(expected_body, json.loads(self.http.request.data.decode("utf-8"))) diff --git a/test/fixtures/application_credit.json b/test/fixtures/application_credit.json new file mode 100644 index 00000000..4d6c3de0 --- /dev/null +++ b/test/fixtures/application_credit.json @@ -0,0 +1,8 @@ +{ + "application_credit": { + "id": 445365009, + "amount": "5.00", + "description": "credit for application refund", + "test": null + } +} diff --git a/test/fixtures/application_credits.json b/test/fixtures/application_credits.json new file mode 100644 index 00000000..b487a523 --- /dev/null +++ b/test/fixtures/application_credits.json @@ -0,0 +1,10 @@ +{ + "application_credits": [ + { + "id": 445365009, + "amount": "5.00", + "description": "credit for application refund", + "test": null + } + ] +} diff --git a/test/fulfillment_event_test.py b/test/fulfillment_event_test.py index 1ba9a73e..c58cc6eb 100644 --- a/test/fulfillment_event_test.py +++ b/test/fulfillment_event_test.py @@ -1,6 +1,5 @@ import shopify from test.test_helper import TestCase -from pyactiveresource.activeresource import ActiveResource class FulFillmentEventTest(TestCase): def test_get_fulfillment_event(self): @@ -21,4 +20,3 @@ def test_error_on_incorrect_status(self): fulfillment_event = shopify.FulfillmentEvent.find(12584341209251, order_id='2776493818019', fulfillment_id='2608403447971') fulfillment_event.status = incorrect_status fulfillment_event.save() -