Skip to content

Commit

Permalink
Merge pull request #78 from recurly/sub_previews
Browse files Browse the repository at this point in the history
Adding preview to subscriptions
  • Loading branch information
dickfickling committed Jun 25, 2014
2 parents 385c773 + 841ff24 commit 2516818
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 41 deletions.
7 changes: 7 additions & 0 deletions recurly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from six.moves.urllib.parse import urljoin
from xml.etree import ElementTree

import recurly
import recurly.js as js
from recurly.errors import *
from recurly.resource import Resource, Money, PageError
Expand Down Expand Up @@ -514,6 +515,12 @@ class Subscription(Resource):
)
sensitive_attributes = ('number', 'verification_value',)

def preview(self):
if hasattr(self, '_url'):
raise Exception('Cannot preview an existing subscription')
url = urljoin(recurly.base_uri(), self.collection_path) + '/preview'
return self.post(url)

def _update(self):
if not hasattr(self, 'timeframe'):
self.timeframe = 'now'
Expand Down
4 changes: 2 additions & 2 deletions recurly/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,12 +632,12 @@ def post(self, url):
"""Sends this `Resource` instance to the service with a
``POST`` request to the given URL."""
response = self.http_request(url, 'POST', self, {'Content-Type': 'application/xml; charset=utf-8'})
if response.status not in (201, 204):
if response.status not in (200, 201, 204):
self.raise_http_error(response)

self._url = response.getheader('Location')

if response.status == 201:
if response.status in (200, 201):
response_xml = response.read()
logging.getLogger('recurly.http.response').debug(response_xml)
self.update_from_element(ElementTree.fromstring(response_xml))
Expand Down
37 changes: 0 additions & 37 deletions tests/fixtures/subscription/show-taxed.xml

This file was deleted.

7 changes: 5 additions & 2 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,12 +790,15 @@ def test_subscribe(self):
with self.mock_request('subscription/plan-deleted.xml'):
plan.delete()

"""Test taxed subscription"""
with self.mock_request('subscription/show-taxed.xml'):
with self.mock_request('subscription/show.xml'):
sub = account.subscriptions()[0]
self.assertEqual(sub.tax_in_cents, 0)
self.assertEqual(sub.tax_type, 'usst')

with self.mock_request('subscription/show.xml'):
sub = account.subscriptions()[0]
self.assertRaises(Exception, sub.preview)

def test_subscribe_add_on(self):
plan = Plan(
plan_code='basicplan',
Expand Down

0 comments on commit 2516818

Please sign in to comment.