Skip to content

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

Get existing tests to run

Patryk Zawadzki974ec7e9020e
diff --git a/saleor/cart/__init__.py b/saleor/cart/__init__.py
index e0a6d3ef14..097bf23ba3 100755
--- a/saleor/cart/__init__.py
+++ b/saleor/cart/__init__.py
@@ -2,19 +2,19 @@ from __future__ import unicode_literals
from django.utils.translation import pgettext
from satchless import cart
-from satchless.item import ItemSet, ClassifyingPartitioner
+from satchless.item import ItemList, ClassifyingPartitioner
from ..product.models import DigitalShip
-class ShippedGroup(list, ItemSet):
+class ShippedGroup(ItemList):
'''
Group for shippable products.
'''
pass
-class DigitalGroup(list, ItemSet):
+class DigitalGroup(ItemList):
'''
Group for digital products.
'''
@@ -45,5 +45,6 @@ class Cart(cart.Cart):
billing_address = None
def __unicode__(self):
- return pgettext('Shopping cart', 'Your cart (%(cart_count)s)') % {
- 'cart_count': self.count()}
+ return pgettext(
+ 'Shopping cart',
+ 'Your cart (%(cart_count)s)') % {'cart_count': self.count()}
diff --git a/saleor/cart/tests.py b/saleor/cart/tests.py
index 46b1a875c3..37e5250a76 100755
--- a/saleor/cart/tests.py
+++ b/saleor/cart/tests.py
@@ -1,19 +1,17 @@
from __future__ import unicode_literals
from django.test import TestCase
-from mock import MagicMock, patch
+from mock import patch
from prices import Price
from satchless.item import InsufficientStock
-from satchless.cart import CartLine
-from . import Cart, BaseGroup, CartPartitioner
+from . import Cart, CartPartitioner
from .forms import AddToCartForm, ReplaceCartLineForm, \
ReplaceCartLineFormSet
-from ..delivery import BaseDelivery
from ..product.models import (Product, StockedProduct, PhysicalProduct,
FixedProductDiscount)
-__all__ = ['CartTest', 'GroupTest', 'AddToCartFormTest']
+__all__ = ['CartTest', 'AddToCartFormTest']
class BigShip(Product, StockedProduct, PhysicalProduct):
@@ -37,44 +35,6 @@ class CartTest(TestCase):
self.assertFalse(cart)
-class Shipping(BaseDelivery):
-
- def __unicode__(self):
- return '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 ExpressShipping(BaseDelivery):
-
- def __unicode__(self):
- return 'Dummy express shipping'
-
- def get_price_per_item(self, **_kwargs):
- return Price(500, currency='USD')
-
-
-class Group(BaseGroup):
-
- def get_delivery_methods(self):
- yield Shipping(self)
-
-
-class GroupTest(TestCase):
-
- 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(stock_product, 2))
- self.assertEqual(group.get_delivery_total(),
- Price(246, currency='USD'), 246)
-
-
class CartPartitionerTest(TestCase):
def setUp(self):
@@ -84,10 +44,8 @@ class CartPartitionerTest(TestCase):
def test_total_price_including_custom_delivery_method(self, mock_manager):
self.cart.add(stock_product, 1)
items = CartPartitioner(self.cart)
- for group in items:
- group.delivery_method = ExpressShipping(group)
self.assertEqual(items.get_total(),
- Price(510, currency='USD'), 510)
+ Price(10, currency='USD'))
class AddToCartFormTest(TestCase):
diff --git a/saleor/checkout/steps.py b/saleor/checkout/steps.py
index d689f81d01..bb91f30326 100644
--- a/saleor/checkout/steps.py
+++ b/saleor/checkout/steps.py
@@ -156,7 +156,7 @@ class ShippingStep(BaseAddressStep):
delivery_group_data = None
delivery_group = None
- def __init__(self, checkout, request, items_group, _id=None):
+ def __init__(self, checkout, request, purchased_items, _id=None):
self.id = _id
self.delivery_group_data = checkout.get_group(str(self))
if 'address' in self.delivery_group_data:
@@ -165,7 +165,7 @@ class ShippingStep(BaseAddressStep):
address = checkout.billing_address
super(ShippingStep, self).__init__(checkout, request, address)
delivery_methods = list(
- get_delivery_methods_for_group(items_group, address=address))
+ get_delivery_methods_for_group(purchased_items, address=address))
delivery_name = self.delivery_group_data.get('delivery_method')
# TODO: find cheapest not first
selected_delivery_group = delivery_methods[0]
diff --git a/saleor/checkout/tests.py b/saleor/checkout/tests.py
index 0e5cc5e1ac..75c5fc2e79 100644
--- a/saleor/checkout/tests.py
+++ b/saleor/checkout/tests.py
@@ -4,7 +4,6 @@ from mock import MagicMock, patch
from . import BillingAddressStep, ShippingStep
from ..checkout import Checkout
from ..checkout.steps import BaseAddressStep
-from ..delivery import DummyShipping
from ..userprofile.models import Address
NEW_ADDRESS = {
@@ -72,26 +71,24 @@ class TestShippingStep(TestCase):
@patch.object(Address, 'save')
def test_address_save_without_address(self, mock_save):
self.request.POST = NEW_ADDRESS
- self.request.POST['method'] = 0
+ self.request.POST['method'] = 'dummy_shipping'
group = MagicMock()
group.address = None
checkout = Checkout(self.request)
- group.get_delivery_methods.return_value = [DummyShipping(group)]
step = ShippingStep(checkout, self.request, group)
self.assertTrue(step.forms_are_valid(), 'Forms don\'t validate.')
step.save()
self.assertEqual(mock_save.call_count, 0)
- grup_storage = checkout.get_group(str(step))
- self.assertEqual(type(grup_storage['address']), Address,
+ group_storage = checkout.get_group(str(step))
+ self.assertEqual(type(group_storage['address']), Address,
'Address instance expected')
@patch.object(Address, 'save')
def test_address_save_with_address_in_group(self, mock_save):
self.request.POST = NEW_ADDRESS
- self.request.POST['method'] = 0
+ self.request.POST['method'] = 'dummy_shipping'
group = MagicMock()
group.address = Address()
- group.get_delivery_methods.return_value = [DummyShipping(group)]
step = ShippingStep(self.checkout, self.request, group)
self.assertTrue(step.forms_are_valid(), 'Forms don\'t validate.')
step.save()
@@ -100,7 +97,7 @@ class TestShippingStep(TestCase):
@patch.object(Address, 'save')
def test_address_save_with_address_in_checkout(self, mock_save):
self.request.POST = NEW_ADDRESS
- self.request.POST['method'] = 0
+ self.request.POST['method'] = 'dummy_shipping'
original_billing_address_data = {'first_name': 'Change',
'last_name': 'Me',
'id': 10}
@@ -108,11 +105,10 @@ class TestShippingStep(TestCase):
self.checkout.billing_address = original_billing_address
group = MagicMock()
group.address = None
- group.get_delivery_methods.return_value = [DummyShipping(group)]
step = ShippingStep(self.checkout, self.request, group)
self.assertTrue(step.forms_are_valid(), 'Forms don\'t validate.')
step.save()
self.assertEqual(mock_save.call_count, 0)
self.assertEqual(self.checkout.billing_address,
Address(**original_billing_address_data))
- self.assertEqual(step.group['address'].id, None)
+ self.assertEqual(step.delivery_group_data['address'].id, None)
diff --git a/saleor/core/context_processors.py b/saleor/core/context_processors.py
index 104e30bc22..09f125c738 100644
--- a/saleor/core/context_processors.py
+++ b/saleor/core/context_processors.py
@@ -14,5 +14,4 @@ def canonical_hostname(request):
def default_currency(request):
- return get_setting_as_dict('SATCHLESS_DEFAULT_CURRENCY',
- 'DEFAULT_CURRENCY')
+ return get_setting_as_dict('DEFAULT_CURRENCY')
diff --git a/saleor/delivery/__init__.py b/saleor/delivery/__init__.py
index 0633115c3e..4ada95b253 100644
--- a/saleor/delivery/__init__.py
+++ b/saleor/delivery/__init__.py
@@ -19,7 +19,7 @@ class BaseDelivery(ItemSet):
return iter(self.group)
def get_delivery_total(self, **kwargs):
- return Price(0, currency=settings.SATCHLESS_DEFAULT_CURRENCY)
+ return Price(0, currency=settings.DEFAULT_CURRENCY)
def get_total_with_delivery(self):
return self.group.get_total() + self.get_delivery_total()
@@ -36,8 +36,6 @@ class BaseDelivery(ItemSet):
class DummyShipping(BaseDelivery):
- address = None
-
def __init__(self, delivery_group, address):
self.address = address
super(DummyShipping, self).__init__(delivery_group)
@@ -49,13 +47,11 @@ class DummyShipping(BaseDelivery):
weight = sum(line.product.weight for line in self.group)
qty = sum(line.quantity for line in self.group)
return Price(qty * weight,
- currency=settings.SATCHLESS_DEFAULT_CURRENCY)
+ currency=settings.DEFAULT_CURRENCY)
class DigitalDelivery(BaseDelivery):
- email = None
-
def __init__(self, delivery_group, email):
self.email = email
super(DigitalDelivery, self).__init__(delivery_group)
@@ -65,7 +61,9 @@ class DigitalDelivery(BaseDelivery):
def get_delivery_methods_for_group(group, **kwargs):
- if isinstance(group, ShippedGroup):
+ if 'address' in kwargs:
yield DummyShipping(group, kwargs['address'])
- else:
+ elif 'email' in kwargs:
yield DigitalDelivery(group, kwargs['email'])
+ else:
+ raise ValueError('Unknown delivery type')
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 2501fe742a..26caabfee7 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -103,7 +103,7 @@ class Order(models.Model, ItemSet):
def get_delivery_total(self):
return sum([group.price for group in self.groups.all()],
- Price(0, currency=settings.SATCHLESS_DEFAULT_CURRENCY))
+ Price(0, currency=settings.DEFAULT_CURRENCY))
def send_confirmation_email(self):
email = self.get_user_email()
@@ -130,7 +130,7 @@ class DeliveryGroup(Subtyped, ItemSet):
order = models.ForeignKey(Order, related_name='groups', editable=False)
price = PriceField(
pgettext_lazy('Delivery group field', 'unit price'),
- currency=settings.SATCHLESS_DEFAULT_CURRENCY, max_digits=12,
+ currency=settings.DEFAULT_CURRENCY, max_digits=12,
decimal_places=4,
default=0,
editable=False)
@@ -203,7 +203,7 @@ class OrderedItem(models.Model, ItemLine):
def get_price_per_item(self, **kwargs):
return Price(net=self.unit_price_net, gross=self.unit_price_gross,
- currency=settings.SATCHLESS_DEFAULT_CURRENCY)
+ currency=settings.DEFAULT_CURRENCY)
def __unicode__(self):
return self.product_name
@@ -235,6 +235,6 @@ class Payment(BasePayment):
items = [PurchasedItem(name=item.product_name, quantity=item.quantity,
price=item.unit_price_gross,
sku=item.product.sku,
- currency=settings.SATCHLESS_DEFAULT_CURRENCY)
+ currency=settings.DEFAULT_CURRENCY)
for item in self.order.get_items()]
return items
diff --git a/saleor/product/models.py b/saleor/product/models.py
index eff14f0191..ab5e2e3550 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -46,7 +46,7 @@ class Product(Subtyped, Item):
name = models.CharField(pgettext_lazy('Product field', 'name'),
max_length=128)
price = PriceField(pgettext_lazy('Product field', 'price'),
- currency=settings.SATCHLESS_DEFAULT_CURRENCY,
+ currency=settings.DEFAULT_CURRENCY,
max_digits=12, decimal_places=4)
sku = models.CharField(pgettext_lazy('Product field', 'sku'),
max_length=32, unique=True)
@@ -110,7 +110,7 @@ class FixedProductDiscount(models.Model):
name = models.CharField(max_length=255)
products = models.ManyToManyField(Product, blank=True)
discount = PriceField(pgettext_lazy('Discount field', 'discount value'),
- currency=settings.SATCHLESS_DEFAULT_CURRENCY,
+ currency=settings.DEFAULT_CURRENCY,
max_digits=12, decimal_places=4)
objects = ProductDiscountManager()
diff --git a/saleor/settings.py b/saleor/settings.py
index aa87f3a03b..548d86dca6 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -181,7 +181,7 @@ LOGIN_URL = '/account/login'
WARN_ABOUT_INVALID_HTML5_OUTPUT = False
-SATCHLESS_DEFAULT_CURRENCY = 'USD'
+DEFAULT_CURRENCY = 'USD'
ACCOUNT_ACTIVATION_DAYS = 3