Permalink
Browse files

emit "processing" signal at the end of ``OrderManager.create_from_cart``

  • Loading branch information...
1 parent 7b69277 commit 6279e30c2028327532b79d433710f7ec144c1c54 @piquadrat piquadrat committed Jan 3, 2012
Showing with 19 additions and 0 deletions.
  1. +6 −0 shop/models/defaults/managers.py
  2. +13 −0 shop/tests/views_checkout.py
@@ -4,6 +4,8 @@
from django.db.models.aggregates import Count
from polymorphic.manager import PolymorphicManager
+from shop.order_signals import processing
+
#==============================================================================
# Product
@@ -76,6 +78,8 @@ def create_from_cart(self, cart):
This will only actually commit the transaction once the function exits
to minimize useless database access.
+
+ Emits the ``processing`` signal.
"""
# must be imported here!
from shop.models.ordermodel import (
@@ -124,4 +128,6 @@ def create_from_cart(self, cart):
eoi.label = unicode(label)
eoi.value = value
eoi.save()
+
+ processing.send(self.model, order=order)
return order
@@ -8,6 +8,7 @@
from shop.addressmodel.models import Country, Address
from shop.models.cartmodel import Cart
from shop.models.ordermodel import Order
+from shop.order_signals import processing
from shop.tests.util import Mock
from shop.tests.utils.context_managers import SettingsOverride
from shop.views.checkout import CheckoutSelectionView, ThankYouView
@@ -214,6 +215,18 @@ def test_order_created(self):
res = view.create_order_object_from_cart()
self.assertEqual(res.order_total, Decimal('0'))
+ def test_processing_signal(self):
+ view = CheckoutSelectionView(request=self.request)
+
+ order_from_signal = []
+ def receiver(sender, order=None, **kwargs):
+ order_from_signal.append(order)
+
+ processing.connect(receiver)
+ res = view.create_order_object_from_cart()
+
+ self.assertIs(res, order_from_signal[0])
+
class ThankYouViewTestCase(TestCase):
def setUp(self):

0 comments on commit 6279e30

Please sign in to comment.