Skip to content

Commit

Permalink
Merge branch 'feature/deflake' of https://github.com/funkybob/saleor
Browse files Browse the repository at this point in the history
…into funkybob-feature/deflake
  • Loading branch information
patrys committed Feb 17, 2016
2 parents 28d8eb0 + e71407f commit baf35dd
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 31 deletions.
1 change: 0 additions & 1 deletion saleor/checkout/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def _save_address(self, address, is_billing=False, is_shipping=False):
address.save()
return address


@transaction.atomic
def create_order(self):
if self.is_shipping_required:
Expand Down
2 changes: 0 additions & 2 deletions saleor/checkout/forms.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from django import forms
from django.template.loader import get_template
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django_prices.templatetags.prices_i18n import format_price

from ..shipping.models import ShippingMethodCountry
from ..userprofile.models import Address


class CheckoutAddressField(forms.ChoiceField):
Expand Down
14 changes: 7 additions & 7 deletions saleor/checkout/test_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def test_checkout_clear_storage():
checkout.storage['new'] = 1
checkout.clear_storage()
assert checkout.storage is None
assert checkout.modified == True
assert checkout.modified is True


def test_checkout_is_shipping_required():
cart = Mock(is_shipping_required=Mock(return_value=True))
checkout = Checkout(cart, AnonymousUser(), 'tracking_code')
assert checkout.is_shipping_required == True
assert checkout.is_shipping_required is True


def test_checkout_deliveries():
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_checkout_shipping_address_with_anonymous_user(user, shipping):

@pytest.mark.parametrize('address_objects, shipping', [
(Mock(get=Mock(return_value='shipping')), 'shipping'),
(Mock(get=Mock(side_effect = Address.DoesNotExist)), None),
(Mock(get=Mock(side_effect=Address.DoesNotExist)), None),
])
def test_checkout_shipping_address_with_storage(address_objects, shipping, monkeypatch):
monkeypatch.setattr('saleor.checkout.core.Address.objects', address_objects)
Expand All @@ -97,7 +97,7 @@ def test_checkout_shipping_address_setter():
assert checkout.storage['shipping_address'] == {
'city': u'', 'city_area': u'', 'company_name': u'', 'country': '', 'phone': u'',
'country_area': u'', 'first_name': 'Jan', 'id': None, 'last_name': 'Kowalski',
'postal_code': u'', 'street_address_1': u'','street_address_2': u''}
'postal_code': u'', 'street_address_1': u'', 'street_address_2': u''}


@pytest.mark.parametrize('shipping_address, shipping_method, value', [
Expand All @@ -117,7 +117,7 @@ def test_checkout_shipping_method(shipping_address, shipping_method, value, monk


def test_checkout_shipping_does_not_exists(monkeypatch):
queryset = Mock(get=Mock(side_effect = ShippingMethodCountry.DoesNotExist))
queryset = Mock(get=Mock(side_effect=ShippingMethodCountry.DoesNotExist))
monkeypatch.setattr('saleor.checkout.core.ShippingMethodCountry.objects', queryset)
checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
checkout.storage['shipping_method_country_id'] = 1
Expand All @@ -127,9 +127,9 @@ def test_checkout_shipping_does_not_exists(monkeypatch):
def test_checkout_shipping_method_setter():
shipping_method = Mock(id=1)
checkout = Checkout(Mock(), AnonymousUser(), 'tracking_code')
assert checkout.modified == False
assert checkout.modified is False
checkout.shipping_method = shipping_method
assert checkout.modified == True
assert checkout.modified is True
assert checkout.storage['shipping_method_country_id'] == 1


Expand Down
2 changes: 1 addition & 1 deletion saleor/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def test_get_country_by_ip(reader, expected_country, monkeypatch):
def test_get_currency_for_country(settings, country, expected_currency, monkeypatch):
monkeypatch.setattr('saleor.core.settings', settings)
currency = get_currency_for_country(country)
assert currency == expected_currency
assert currency == expected_currency
1 change: 1 addition & 0 deletions saleor/dashboard/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest


@pytest.fixture()
def admin_user(db, django_user_model, django_username_field):
"""A Django admin user.
Expand Down
1 change: 0 additions & 1 deletion saleor/dashboard/discount/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

6 changes: 2 additions & 4 deletions saleor/dashboard/discount/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ def save(self, commit=True):
# On which product we should apply it? On first, last or cheapest?
# Percentage case is limited to the all value and the apply_to field
# is not used in this case so we set it to None.
if (self.instance.discount_value_type
== Voucher.DISCOUNT_VALUE_PERCENTAGE):
if self.instance.discount_value_type == Voucher.DISCOUNT_VALUE_PERCENTAGE:
self.instance.apply_to = None
return super(ProductVoucherForm, self).save(commit)

Expand All @@ -141,7 +140,6 @@ def save(self, commit=True):
# On which product we should apply it? On first, last or cheapest?
# Percentage case is limited to the all value and the apply_to field
# is not used in this case so we set it to None.
if (self.instance.discount_value_type
== Voucher.DISCOUNT_VALUE_PERCENTAGE):
if self.instance.discount_value_type == Voucher.DISCOUNT_VALUE_PERCENTAGE:
self.instance.apply_to = None
return super(CategoryVoucherForm, self).save(commit)
2 changes: 1 addition & 1 deletion saleor/dashboard/product/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.core.urlresolvers import reverse
import pytest

from ...product.test_product import product_in_stock
from ...product.test_product import product_in_stock # NOQA


@pytest.mark.integration
Expand Down
1 change: 0 additions & 1 deletion saleor/dashboard/shipping/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@
url(r'^(?P<pk>\d+)/delete/$',
views.shipping_method_delete, name='shipping-method-delete'),
]

10 changes: 4 additions & 6 deletions saleor/discount/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ class VoucherQueryset(models.QuerySet):
def active(self):
today = date.today()
queryset = self.filter(
models.Q(usage_limit__isnull=True)
| models.Q(used__lt=models.F('usage_limit')))
models.Q(usage_limit__isnull=True) | models.Q(used__lt=models.F('usage_limit')))
queryset = queryset.filter(
models.Q(end_date__isnull=True)
| models.Q(end_date__gte=today))
models.Q(end_date__isnull=True) | models.Q(end_date__gte=today))
queryset = queryset.filter(start_date__lte=today)
return queryset

Expand Down Expand Up @@ -272,8 +270,8 @@ def modifier_for_variant(self, variant):
if discounted_products and variant.pk not in discounted_products:
raise NotApplicable('Discount not applicable for this product')
if (discounted_categories and not
self._product_has_category_discount(
variant.product, discounted_categories)):
self._product_has_category_discount(
variant.product, discounted_categories)):
raise NotApplicable('Discount too high for this product')
return self.get_discount()

Expand Down
6 changes: 3 additions & 3 deletions saleor/discount/test_discounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ def test_percentage_discounts(product_variant):

@pytest.mark.parametrize(
'total, discount_value, discount_type, limit, expected_value', [
('100', 10, Voucher.DISCOUNT_VALUE_FIXED, None, 10),
('100.05', 10, Voucher.DISCOUNT_VALUE_PERCENTAGE, 100, 10)])
('100', 10, Voucher.DISCOUNT_VALUE_FIXED, None, 10),
('100.05', 10, Voucher.DISCOUNT_VALUE_PERCENTAGE, 100, 10)
])
def test_value_voucher_checkout_discount(settings, total, discount_value,
discount_type, limit, expected_value):
settings.DEFAULT_CURRENCY = 'USD'
Expand Down Expand Up @@ -182,7 +183,6 @@ def test_category_voucher_checkout_discount_not_applicable(settings,
assert str(e.value) == 'This offer is only valid for selected items.'



@pytest.mark.parametrize(
'prices, discount_value, discount_type, apply_to, expected_value', [
([10], 10, Voucher.DISCOUNT_VALUE_FIXED, Voucher.APPLY_TO_ONE_PRODUCT, 10), # noqa
Expand Down
5 changes: 2 additions & 3 deletions saleor/order/test_order.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from prices import Price

from ..cart import Cart, SessionCart
from ..product.models import Stock
from ..product.test_product import product_in_stock
from ..userprofile.test_userprofile import billing_address
from ..product.test_product import product_in_stock # NOQA
from ..userprofile.test_userprofile import billing_address # NOQA
from . import models


Expand Down
2 changes: 1 addition & 1 deletion saleor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'

VERSATILEIMAGEFIELD_RENDITION_KEY_SETS = {
'defaults': [
'defaults': [
('list_view', 'crop__100x100'),
('dashboard', 'crop__400x400'),
('product_page_mobile', 'crop__680x680'),
Expand Down

0 comments on commit baf35dd

Please sign in to comment.