Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

create product on the fly (bug 820870)

  • Loading branch information...
commit 93a116ebd3326d219f8986c9770ed2f6b609a5ef 1 parent a61b950
@andymckay andymckay authored
Showing with 58 additions and 8 deletions.
  1. +35 −8 lib/solitude/api.py
  2. +23 −0 lib/solitude/tests.py
View
43 lib/solitude/api.py
@@ -126,14 +126,8 @@ def configure_product_for_billing(self, webpay_trans_id,
seller_product__external_id=product_id
)
if res['meta']['total_count'] == 0:
- # TODO(Kumar) create products on the fly. bug 820164
- raise NotImplementedError(
- 'this product does not exist and must be created')
-
- # Create the product on the fly.
- # This case exists for in-app purchases where the
- # seller is selling a new item for the first time.
-
+ bango_product_uri = self.create_product(product_id,
+ product_name, currency, amount, res['objects'][0])
else:
bango_product_uri = res['objects'][0]['resource_uri']
log.info('transaction %s: bango product: %s'
@@ -150,6 +144,39 @@ def configure_product_for_billing(self, webpay_trans_id,
% (webpay_trans_id, bill_id))
return bill_id
+ def create_product(self, external_id, product_name, currency, amount, seller):
+ """
+ Creates a product and a Bango ID on the fly in solitude.
+ """
+ if not seller['bango']:
+ raise ValueError('No bango account set up for %s' %
+ seller['resource_pk'])
+
+ product = self.slumber.generic.product.post({
+ 'external_id': external_id,
+ 'seller': seller['bango']['seller']
+ })
+ bango = self.slumber.bango.product.post({
+ 'seller_bango': seller['bango']['resource_uri'],
+ 'seller_product': product['resource_uri'],
+ 'name': product_name,
+ 'categoryId': 1,
+ 'secret': 'n' # This is likely going to be removed.
+ })
+ self.slumber.bango.premium.post({
+ 'price': amount,
+ 'currencyIso': currency,
+ 'seller_product_bango': bango['resource_uri']
+ })
+
+ self.slumber.bango.rating.post({
+ 'rating': 'UNIVERSAL',
+ 'ratingScheme': 'GLOBAL',
+ 'seller_product_bango': bango['resource_uri']
+ })
+ return bango['resource_uri']
+
+
if getattr(settings, 'SOLITUDE_URL', False):
client = SolitudeAPI(settings.SOLITUDE_URL)
View
23 lib/solitude/tests.py
@@ -1,12 +1,14 @@
from django.conf import settings
from django.test import TestCase
+import mock
from nose.exc import SkipTest
from nose.tools import eq_
from lib.solitude.api import client
from lib.solitude.errors import ERROR_STRINGS
+
class SolitudeAPITest(TestCase):
def setUp(self):
@@ -79,3 +81,24 @@ def test_verify_good_pin(self):
def test_verify_alpha_pin(self):
assert not client.verify_pin(self.uuid, 'lame')
+
+
+class CreateBangoTest(TestCase):
+ uuid = 'some:pin'
+
+ def test_create_no_bango(self):
+ with self.assertRaises(ValueError):
+ client.create_product('ext:id', None, None, None,
+ {'bango': None, 'resource_pk': 'foo'})
+
+ @mock.patch('lib.solitude.api.client.slumber')
+ def test_create_bango(self, slumber):
+ # Temporary mocking. Remove when this is mocked properly.
+ slumber.bango.generic.post.return_value = {'product': 'some:uri'}
+ slumber.bango.product.post.return_value = {'resource_uri': 'some:uri'}
+ assert client.create_product('ext:id', 'product:name', 'CAD', 1,
+ {'bango': {'seller': 's', 'resource_uri': 'r'},
+ 'resource_pk': 'foo'})
+ assert slumber.generic.product.post.called
+ assert slumber.bango.rating.post.called
+ assert slumber.bango.premium.post.called
Please sign in to comment.
Something went wrong with that request. Please try again.