This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merge pull request #80 from kumar303/prod-access

Declare access types for product keys (bug 837169)
  • Loading branch information...
kumar303 committed Mar 4, 2013
2 parents 570c8fc + edf739b commit f6c20a5ff47416ddc915a958fd38c42a3def56fa
View
@@ -1 +1,16 @@
+from solitude.base import invert
+
+
EXTERNAL_PRODUCT_ID_IS_NOT_UNIQUE = 'EXTERNAL_PRODUCT_ID_IS_NOT_UNIQUE'
+
+ACCESS_PURCHASE = 1
+ACCESS_SIMULATE = 2
+
+ACCESS_TYPES = {
+ # The product can be purchased.
+ 'purchase': ACCESS_PURCHASE,
+ # The product can only go through a simulated purchase.
+ 'simulate': ACCESS_SIMULATE,
+}
+
+ACCESS_CHOICES = invert(ACCESS_TYPES)
View
@@ -1,7 +1,9 @@
from django import forms
-from .models import Seller, SellerPaypal, SellerProduct
+
from solitude.fields import URLField
+from .models import Seller, SellerPaypal, SellerProduct
+
class SellerValidation(forms.ModelForm):
View
@@ -3,7 +3,8 @@
from aesfield.field import AESField
from solitude.base import Model
-from .constants import EXTERNAL_PRODUCT_ID_IS_NOT_UNIQUE
+from .constants import (ACCESS_CHOICES, ACCESS_PURCHASE,
+ EXTERNAL_PRODUCT_ID_IS_NOT_UNIQUE)
class Seller(Model):
@@ -47,6 +48,9 @@ def token_exists(self):
class SellerProduct(Model):
+ """
+ The key to a seller's generic product.
+ """
# An identifier for this product that corresponds to the
# seller's catalog.
external_id = models.CharField(max_length=255, db_index=True)
@@ -58,6 +62,9 @@ class SellerProduct(Model):
# of backend.
secret = AESField(blank=True, null=True,
aes_key='sellerproduct:secret')
+ # The type of access this product key has.
+ access = models.PositiveIntegerField(choices=ACCESS_CHOICES,
+ default=ACCESS_PURCHASE)
unique_error_message = lambda *args: EXTERNAL_PRODUCT_ID_IS_NOT_UNIQUE
@@ -2,7 +2,8 @@
from nose.tools import eq_
-from lib.sellers.constants import EXTERNAL_PRODUCT_ID_IS_NOT_UNIQUE
+from lib.sellers.constants import (ACCESS_PURCHASE, ACCESS_SIMULATE,
+ EXTERNAL_PRODUCT_ID_IS_NOT_UNIQUE)
from lib.sellers.models import Seller, SellerProduct, SellerPaypal
from solitude.base import APITest
@@ -165,6 +166,7 @@ def data(self, **kw):
params = {'seller': self.seller_uri(),
'external_id': 'pre-generated-product-id',
'secret': 'hush',
+ 'access': ACCESS_PURCHASE,
'public_id': 'public-id'}
params.update(**kw)
return params
@@ -262,6 +264,14 @@ def test_patch_get_secret(self):
data = json.loads(res.content)
eq_(data['secret'], 'hush')
+ def test_patch_get_access(self):
+ obj, url = self.create_url()
+ res = self.client.patch(url, json.dumps({'access': ACCESS_SIMULATE}))
+ eq_(res.status_code, 202, res.content)
+ res = self.client.get(url)
+ data = json.loads(res.content)
+ eq_(data['access'], ACCESS_SIMULATE)
+
def test_patch_get_ext_id(self):
obj, url = self.create_url()
res = self.client.patch(url, json.dumps({'seller': self.seller_url,
@@ -274,6 +284,7 @@ def test_put_get(self):
obj, url = self.create_url()
res = self.client.put(url, json.dumps({'seller': self.seller_url,
'secret': 'hush',
+ 'access': ACCESS_PURCHASE,
'external_id': 'abc',
'public_id': 'blah'}))
eq_(res.status_code, 202)
@@ -1,3 +1,5 @@
+from solitude.base import invert
+
STATUS_PENDING = 0 # When the payment has been started.
STATUS_COMPLETED = 1 # When the IPN says its ok.
STATUS_CHECKED = 2 # When someone calls pay-check on the transaction.
@@ -40,10 +42,6 @@
'bango': SOURCE_BANGO
}
-
-def invert(data):
- return [(v, k) for k, v in data.items()]
-
STATUSES_CHOICES = invert(STATUSES)
-TYPES_CHOICES= invert(TYPES)
+TYPES_CHOICES = invert(TYPES)
SOURCES_CHOICES = invert(SOURCES)
@@ -0,0 +1,2 @@
+ALTER TABLE seller_product ADD COLUMN access int(11) UNSIGNED NOT NULL DEFAULT 1;
+ALTER TABLE seller_product ALTER COLUMN access DROP DEFAULT;
View
@@ -489,3 +489,10 @@ class Meta:
def reget(self):
return self.__class__.objects.get(pk=self.pk)
+
+
+def invert(data):
+ """
+ Helper to turn a dict of constants into a choices tuple.
+ """
+ return [(v, k) for k, v in data.items()]

0 comments on commit f6c20a5

Please sign in to comment.