diff --git a/recurly/__init__.py b/recurly/__init__.py index ffbd97cf..ae34f33d 100644 --- a/recurly/__init__.py +++ b/recurly/__init__.py @@ -403,6 +403,10 @@ def generate(self, amount): return Page.page_for_url(response.getheader('Location')) + def restore(self): + url = urljoin(self._url, '%s/restore' % self.coupon_code) + self.put(url) + class Redemption(Resource): """A particular application of a coupon to a customer account.""" diff --git a/tests/fixtures/coupon/restored.xml b/tests/fixtures/coupon/restored.xml new file mode 100644 index 00000000..bcc97c93 --- /dev/null +++ b/tests/fixtures/coupon/restored.xml @@ -0,0 +1,45 @@ +PUT https://api.recurly.com/v2/coupons/couponmock/restore HTTP/1.1 +X-Api-Version: 2.1 +Accept: application/xml +Authorization: Basic YXBpa2V5Og== +User-Agent: recurly-python/{version} +Content-Type: application/xml; charset=utf-8 + + + + New Name Restore + New Description Restore + New Description Restore + + +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 +Location: https://api.recurly.com/v2/coupons/couponmock + + + + couponmock + New Name Restore + dollars + New Description Restore + New Description Restore + + + false + + + true + 2011-09-19T19:01:21Z + forever + + + true + account + + 1000 + + 1 + + + + diff --git a/tests/fixtures/coupon/updated.xml b/tests/fixtures/coupon/updated.xml new file mode 100644 index 00000000..e8fa6638 --- /dev/null +++ b/tests/fixtures/coupon/updated.xml @@ -0,0 +1,45 @@ +PUT https://api.recurly.com/v2/coupons/couponmock HTTP/1.1 +X-Api-Version: 2.1 +Accept: application/xml +Authorization: Basic YXBpa2V5Og== +User-Agent: recurly-python/{version} +Content-Type: application/xml; charset=utf-8 + + + + New Name + New Description + New Description + + +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 +Location: https://api.recurly.com/v2/coupons/couponmock + + + + couponmock + New Name + dollars + New Description + New Description + + + false + + + true + 2011-09-19T19:01:21Z + forever + + + true + account + + 1000 + + 1 + + + + diff --git a/tests/test_resources.py b/tests/test_resources.py index a14ffde9..92080216 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -419,6 +419,28 @@ def test_coupon(self): with self.mock_request('coupon/account-created.xml'): account.save() + coupon.name = 'New Name' + coupon.invoice_description = 'New Description' + coupon.hosted_description = 'New Description' + + with self.mock_request('coupon/updated.xml'): + coupon.save() + + self.assertEqual(coupon.name, 'New Name') + self.assertEqual(coupon.invoice_description, 'New Description') + self.assertEqual(coupon.hosted_description, 'New Description') + + coupon.name = 'New Name Restore' + coupon.invoice_description = 'New Description Restore' + coupon.hosted_description = 'New Description Restore' + + with self.mock_request('coupon/restored.xml'): + coupon.restore() + + self.assertEqual(coupon.name, 'New Name Restore') + self.assertEqual(coupon.invoice_description, 'New Description Restore') + self.assertEqual(coupon.hosted_description, 'New Description Restore') + try: redemption = Redemption(