This repository has been archived by the owner on Jan 25, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from andymckay/812511
pull in price tiers, partial, add in api (bug 812511)
- Loading branch information
Showing
6 changed files
with
75 additions
and
26 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.conf import settings | ||
|
||
from ..utils import SlumberWrapper | ||
|
||
|
||
class MarketplaceAPI(SlumberWrapper): | ||
errors = {} | ||
|
||
def get_price(self, tier): | ||
return self.slumber.api.webpay.prices(id=tier).get() | ||
|
||
|
||
client = MarketplaceAPI(settings.MARKETPLACE_URL or 'http://example.com') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.test import TestCase | ||
|
||
import mock | ||
from nose.tools import eq_ | ||
|
||
from lib.marketplace.api import client | ||
|
||
|
||
sample_price = { | ||
u'name': u'Tier 0', | ||
u'prices': [{u'amount': u'1.00', u'currency': u'USD'}, | ||
{u'amount': u'3.00', u'currency': u'JPY'}], | ||
u'resource_uri': u'/api/webpay/prices/1/' | ||
} | ||
|
||
@mock.patch('lib.marketplace.api.client.slumber') | ||
class SolitudeAPITest(TestCase): | ||
|
||
def test_get_prices(self, slumber): | ||
sample = mock.Mock() | ||
sample.get.return_value = sample_price | ||
slumber.api.webpay.prices.return_value = sample | ||
prices = client.get_price(1) | ||
eq_(prices['name'], sample_price['name']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import json | ||
|
||
from slumber import API | ||
from slumber.exceptions import HttpClientError | ||
|
||
|
||
class SlumberWrapper(object): | ||
""" | ||
A wrapper around the Slumber API. | ||
""" | ||
|
||
def __init__(self, url): | ||
self.slumber = API(url) | ||
|
||
def parse_res(self, res): | ||
if res == '': | ||
return {} | ||
if isinstance(res, (str, unicode)): | ||
return json.loads(res) | ||
return res | ||
|
||
def safe_run(self, command, *args, **kwargs): | ||
try: | ||
res = command(*args, **kwargs) | ||
except HttpClientError as e: | ||
res = self.parse_res(e.response.content) | ||
for key, value in res.iteritems(): | ||
res[key] = [self.errors[v] for v in value] | ||
return {'errors': res} | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters