Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Removed CartPartitioner and ShippedGroup

Artur Smętdee7d4462985
diff --git a/saleor/cart/__init__.py b/saleor/cart/__init__.py
index b2e8a43737..825e39558e 100755
--- a/saleor/cart/__init__.py
+++ b/saleor/cart/__init__.py
@@ -2,14 +2,7 @@ from __future__ import unicode_literals
from django.utils.translation import pgettext
from satchless import cart
-from satchless.item import ItemList, ClassifyingPartitioner
-
-
-class ShippedGroup(ItemList):
- '''
- Group for shippable products.
- '''
- pass
+from satchless.item import ItemList, partition
class DigitalGroup(ItemList):
@@ -19,17 +12,6 @@ class DigitalGroup(ItemList):
pass
-class CartPartitioner(ClassifyingPartitioner):
- '''
- Dividing cart into groups.
- '''
- def classify(self, item):
- return 'shippable'
-
- def get_partition(self, classifier, items):
- return ShippedGroup(items)
-
-
class Cart(cart.Cart):
'''
Contains cart items. Serialized instance of cart is saved into django
@@ -42,3 +24,7 @@ class Cart(cart.Cart):
return pgettext(
'Shopping cart',
'Your cart (%(cart_count)s)') % {'cart_count': self.count()}
+
+
+def partitioner(subject):
+ return partition(subject, lambda product: 'shippable')
\ No newline at end of file
diff --git a/saleor/cart/tests.py b/saleor/cart/tests.py
index 80c36f2d79..c57f94fb89 100755
--- a/saleor/cart/tests.py
+++ b/saleor/cart/tests.py
@@ -6,7 +6,7 @@ from mock import patch
from prices import Price
from satchless.item import InsufficientStock
-from . import Cart, CartPartitioner
+from . import Cart
from .forms import AddToCartForm, ReplaceCartLineForm, ReplaceCartLineFormSet
from ..product.models import (ProductVariant, StockedProduct, PhysicalProduct,
FixedProductDiscount)
@@ -39,7 +39,9 @@ digital_product.product = digital_product
class CartTest(TestCase):
def test_check_quantity(self):
- 'Stock limit works'
+ """
+ Stock limit works
+ """
cart = Cart()
def illegal():
@@ -49,19 +51,6 @@ class CartTest(TestCase):
self.assertFalse(cart)
-class CartPartitionerTest(TestCase):
-
- def setUp(self):
- self.cart = Cart()
-
- @patch.object(FixedProductDiscount, 'objects')
- def test_total_price_including_custom_delivery_method(self, mock_manager):
- self.cart.add(stock_product, 1)
- items = CartPartitioner(self.cart)
- self.assertEqual(items.get_total(),
- Price(10, currency='USD'))
-
-
class BigShipCartFormTest(TestCase):
def setUp(self):
@@ -69,7 +58,9 @@ class BigShipCartFormTest(TestCase):
self.post = {'quantity': 5}
def test_quantity(self):
- 'Is BigShipCartForm works with correct quantity value on empty cart'
+ """
+ BigShipCartForm works with correct quantity value on empty cart
+ """
form = BigShipCartForm(
self.post, cart=self.cart, product=stock_product)
self.assertTrue(form.is_valid())
@@ -79,7 +70,9 @@ class BigShipCartFormTest(TestCase):
self.assertEqual(product_quantity, 5, 'Bad quantity')
def test_max_quantity(self):
- 'Is BigShipCartForm works with correct product stock value'
+ """
+ BigShipCartForm works with correct product stock value
+ """
form = BigShipCartForm(
self.post, cart=self.cart, product=stock_product)
self.assertTrue(form.is_valid())
@@ -93,14 +86,18 @@ class BigShipCartFormTest(TestCase):
'%s is the bad quantity value' % (product_quantity,))
def test_too_big_quantity(self):
- 'Is BigShipCartForm works with not correct quantity value'
+ """
+ BigShipCartForm works with not correct quantity value'
+ """
form = BigShipCartForm({'quantity': 15}, cart=self.cart,
product=stock_product)
self.assertFalse(form.is_valid())
self.assertFalse(self.cart)
def test_clean_quantity_product(self):
- 'Is BigShipCartForm works with not stocked product'
+ """
+ Is BigShipCartForm works with not stocked product
+ """
cart = Cart()
self.post['quantity'] = 10000
form = BigShipCartForm(self.post, cart=cart, product=digital_product)
@@ -116,7 +113,9 @@ class ReplaceCartLineFormTest(TestCase):
self.cart = Cart()
def test_quantity(self):
- 'Is ReplaceCartLineForm works with correct quantity value'
+ """
+ ReplaceCartLineForm works with correct quantity value
+ """
form = ReplaceCartLineForm({'quantity': 5}, cart=self.cart,
product=stock_product)
self.assertTrue(form.is_valid())
@@ -130,7 +129,9 @@ class ReplaceCartLineFormTest(TestCase):
'%s is the bad quantity value' % (product_quantity,))
def test_too_big_quantity(self):
- 'Is ReplaceCartLineForm works with to big quantity value'
+ """
+ Is ReplaceCartLineForm works with to big quantity value
+ """
form = ReplaceCartLineForm({'quantity': 15}, cart=self.cart,
product=stock_product)
self.assertFalse(form.is_valid())
diff --git a/saleor/cart/views.py b/saleor/cart/views.py
index 10273df157..579b927f31 100755
--- a/saleor/cart/views.py
+++ b/saleor/cart/views.py
@@ -5,12 +5,12 @@ from django.shortcuts import redirect
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
-from . import CartPartitioner
from .forms import ReplaceCartLineFormSet
+from . import partitioner
def index(request):
- partitioner = CartPartitioner(request.cart)
+ cart_partitioner = partitioner(request.cart)
formset = ReplaceCartLineFormSet(request.POST or None, cart=request.cart)
if formset.is_valid():
msg = _('Successfully updated product quantities.')
@@ -19,5 +19,5 @@ def index(request):
return redirect('cart:index')
return TemplateResponse(
request, 'cart/index.html', {
- 'cart': partitioner,
+ 'cart': cart_partitioner,
'formset': formset})
diff --git a/saleor/checkout/__init__.py b/saleor/checkout/__init__.py
index 89350dfe06..05b7ee0439 100644
--- a/saleor/checkout/__init__.py
+++ b/saleor/checkout/__init__.py
@@ -6,7 +6,7 @@ from satchless.process import ProcessManager
from .steps import (BillingAddressStep, ShippingStep, DigitalDeliveryStep,
SummaryStep)
-from ..cart import CartPartitioner, DigitalGroup
+from ..cart import DigitalGroup, partitioner
from ..core import analytics
from ..order.models import Order
@@ -41,7 +41,7 @@ class Checkout(ProcessManager):
self.generate_steps(request.cart)
def generate_steps(self, cart):
- self.items = CartPartitioner(cart)
+ self.items = partitioner(cart)
self.billing = BillingAddressStep(
self.request, self.get_storage('billing'))
self.steps.append(self.billing)