Permalink
Browse files

fix ProductType natural key serialization

  • Loading branch information...
1 parent 0875349 commit a82e3c278917dfa29186b7a4688f70cd411cc81b @gabrielgrant committed Jan 22, 2012
Showing with 13 additions and 9 deletions.
  1. +1 −1 billing/models.py
  2. +12 −8 billing/tests/__init__.py
View
@@ -110,7 +110,7 @@ def __unicode__(self):
def __repr__(self):
return 'ProductType(name=%s)' % self.name
def natural_key(self):
- return self.name
+ return (self.name,)
class SubscriptionManager(models.Manager):
def filter_by_current_statuses(self, statuses):
View
@@ -3,6 +3,9 @@
from django.utils import unittest
from django.test import TestCase
from django.core.management import call_command
+from django.core import serializers
+
+JSONSerializer = serializers.get_serializer("json")
from ordereddict import OrderedDict
@@ -94,13 +97,7 @@ def test_get_visible_products(self):
self.a.subscribe_to_product(billing_defs.SecretPlan)
self.assertListEqual(self.a.get_visible_products(), all_products)
-class ProductTypeTests(TestCase):
- def setUp(self):
- pass
-
- def tearDown(self):
- pass
-
+class ProductTypeTests(UserTestCase):
def test_autodiscover(self):
self.assertEqual(ProductType.objects.count(), 6)
def test_get_product_class(self):
@@ -109,7 +106,14 @@ def test_get_product_class(self):
def test_get_by_nautral_key(self):
self.assertEqual(ProductType.objects.get_by_natural_key('GoldPlan').name, 'GoldPlan')
def test_natural_key(self):
- self.assertEqual(ProductType.objects.get(name='GoldPlan').natural_key(), 'GoldPlan')
+ self.assertEqual(ProductType.objects.get(name='GoldPlan').natural_key(), ('GoldPlan',))
+ def test_serialization_deserialization_natural(self):
+ serializer = JSONSerializer()
+ Subscription.objects.create_from_product(
+ billing_defs.GoldPlan, self.u.billing_account)
+ s = serializer.serialize(Subscription.objects.all(), use_natural_keys=True)
+ deserialized = list(serializers.deserialize('json', s))[0]
+ self.assertEqual(deserialized.object, Subscription.objects.get())
class SubscriptionManagerTests(UserTestCase):
def setUp(self):

0 comments on commit a82e3c2

Please sign in to comment.