Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add cart tests
Michal Ociepkacfe3298aa239
diff --git a/cart/__init__.py b/cart/__init__.pyindex 7f6e1cdfca..5bea775014 100755--- a/cart/__init__.py+++ b/cart/__init__.py@@ -69,15 +69,19 @@ class CartPartitioner(Partitioner):'''Change this method to provide custom delivery groups.'''- for product_class, items in groupby(- self.subject,- lambda cart_item: cart_item.product.__class__):- delivery_class = ShippedGroup- if issubclass(product_class, DigitalShip):- delivery_class = DigitalGroup+ for classifier, items in groupby(self.subject, self.classify):+ delivery_class = self.get_delivery_class(classifier)delivery = delivery_class(items)yield delivery+ def classify(self, item):+ return item.product.__class__++ def get_delivery_class(self, classifier):+ if issubclass(classifier, DigitalShip):+ return DigitalGroup+ return ShippedGroup+def get_delivery_subtotal(self, partion, **kwargs):return partion.get_delivery_total(**kwargs)diff --git a/cart/models.py b/cart/models.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/cart/tests.py b/cart/tests.pyindex 501deb776c..9d61185fed 100755--- a/cart/tests.py+++ b/cart/tests.py@@ -1,16 +1,54 @@-"""-This file demonstrates writing tests using the unittest module. These will pass-when you run "manage.py test".+from cart import Cart, InsufficientStockException, BaseGroup+from delivery import BaseDelivery+from django.test import TestCase+from prices import Price+from product.models import Ship+from satchless.cart import CartLine-Replace this with more appropriate tests for your application.-"""+__all__ = ['CartTest', 'ShippedGroupTest']+++product = Ship.objects.create(stock=10, price=Price(10, currency='USD'),+ category_id=1, weight=123)+++class CartTest(TestCase):++ def test_check_quantity(self):+ 'Stock limit works'+ cart = Cart()++ def illegal():+ cart.add(product, 100)++ self.assertRaises(InsufficientStockException, illegal)+ self.assertFalse(cart)+++class Shipping(BaseDelivery):++ def __unicode__(self):+ return u'Dummy shipping'++ def get_price_per_item(self, **kwargs):+ weight = sum(line.product.weight for line in self.group)+ qty = sum(line.quantity for line in self.group)+ return Price(qty*weight, currency='USD')+++class Group(BaseGroup):++ def get_delivery_methods(self):+ yield Shipping(self)-from django.test import TestCase+class GroupTest(TestCase):-class SimpleTest(TestCase):- def test_basic_addition(self):- """- Tests that 1 + 1 always equals 2.- """- self.assertEqual(1 + 1, 2)+ def test_get_delivery_total(self):+ 'Shipped group works'+ group = Group([])+ self.assertEqual(group.get_delivery_total(),+ Price(0,currency='USD'), 0)+ group.append(CartLine(product, 2))+ self.assertEqual(group.get_delivery_total(),+ Price(246, currency='USD'), 246)diff --git a/checkout/tests.py b/checkout/tests.pydeleted file mode 100644index 501deb776c..0000000000--- a/checkout/tests.py+++ /dev/null@@ -1,16 +0,0 @@-"""-This file demonstrates writing tests using the unittest module. These will pass-when you run "manage.py test".--Replace this with more appropriate tests for your application.-"""--from django.test import TestCase---class SimpleTest(TestCase):- def test_basic_addition(self):- """- Tests that 1 + 1 always equals 2.- """- self.assertEqual(1 + 1, 2)