Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add missing tests
Anna Siwikade329b676a9
diff --git a/saleor/checkout/core.py b/saleor/checkout/core.pyindex 36a6d07893..2dc1aab532 100644--- a/saleor/checkout/core.py+++ b/saleor/checkout/core.py@@ -14,7 +14,6 @@ from ..account.utils import store_user_addressfrom ..cart.models import Cartfrom ..cart.utils import get_or_empty_db_cartfrom ..core import analytics-from ..core.utils import ZERO_TAXED_MONEYfrom ..discount.models import NotApplicable, Voucherfrom ..discount.utils import increase_voucher_usagefrom ..order.models import Orderdiff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex 6c18eafaba..5ddc78d7ef 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -72,16 +72,20 @@ class CreateOrderFromDraftForm(forms.ModelForm):raise forms.ValidationError(errors)return self.cleaned_data- def save(self, commit=True):+ def save(self):self.instance.status = OrderStatus.UNFULFILLEDif self.instance.user:self.instance.user_email = self.instance.user.email+ remove_shipping_address = Falseif not self.instance.is_shipping_required():- if self.instance.shipping_address:- self.instance.shipping_address.delete()self.instance.shipping_method_name = Noneself.instance.shipping_price = ZERO_TAXED_MONEY- return super().save(commit)+ if self.instance.shipping_address:+ remove_shipping_address = True+ super().save()+ if remove_shipping_address:+ self.instance.shipping_address.delete()+ return self.instanceclass OrderCustomerForm(forms.ModelForm):@@ -108,9 +112,9 @@ class OrderCustomerForm(forms.ModelForm):def __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)- if self.instance.user:- self.fields['user'].set_initial(- self.instance.user, label=self.instance.user.ajax_label)+ user = self.instance.user+ if user:+ self.fields['user'].set_initial(user, label=user.ajax_label)def clean(self):cleaned_data = super().clean()diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex b7ad3d23ef..3621255c8e 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -254,7 +254,6 @@ def orderline_change_quantity(request, order_pk, line_pk):'product': line.product, 'old_quantity': old_quantity,'new_quantity': line.quantity}with transaction.atomic():- order.history.create(content=msg, user=request.user)form.save()messages.success(request, msg)return redirect('dashboard:order-details', order_pk=order.pk)@@ -277,7 +276,6 @@ def orderline_cancel(request, order_pk, line_pk):'Dashboard message related to an order line','Cancelled item %s') % linewith transaction.atomic():- order.history.create(content=msg, user=request.user)form.cancel_line()messages.success(request, msg)return redirect('dashboard:order-details', order_pk=order.pk)@@ -341,7 +339,8 @@ def address_view(request, order_pk, address_type):updated_address = form.save()if not address:save_address_in_order(order, updated_address, address_type)- order.history.create(content=success_msg, user=request.user)+ if not order.is_draft():+ order.history.create(content=success_msg, user=request.user)messages.success(request, success_msg)return redirect('dashboard:order-details', order_pk=order_pk)ctx = {'order': order, 'address_type': address_type, 'form': form}@@ -503,8 +502,7 @@ def order_voucher_remove(request, order_pk):msg = pgettext_lazy('Dashboard message', 'Removed voucher from order')with transaction.atomic():form.remove_voucher()- order.history.create(content=msg, user=request.user)- messages.success(request, msg)+ messages.success(request, msg)return redirect('dashboard:order-details', order_pk=order.pk)return redirect('dashboard:order-voucher-edit', order_pk=order.pk)diff --git a/saleor/discount/utils.py b/saleor/discount/utils.pyindex b90d6c27a6..97fc096b6b 100644--- a/saleor/discount/utils.py+++ b/saleor/discount/utils.py@@ -66,8 +66,7 @@ def get_value_voucher_discount(voucher, total_price):return voucher.get_discount_amount_for(total_price)-def get_shipping_voucher_discount(- voucher, total_price, shipping_price):+def get_shipping_voucher_discount(voucher, total_price, shipping_price):"""Calculate discount value for a voucher of shipping type."""voucher.validate_limit(total_price)return voucher.get_discount_amount_for(shipping_price)diff --git a/tests/dashboard/test_order.py b/tests/dashboard/test_order.pyindex 8bdeb19c01..063ca767d5 100644--- a/tests/dashboard/test_order.py+++ b/tests/dashboard/test_order.py@@ -425,9 +425,6 @@ def test_view_cancel_order_line(admin_client, draft_order):# check stock deallocationassert Stock.objects.first().quantity_allocated == (quantity_allocated_before - line_quantity)- # check note in the order's history- assert OrderHistoryEntry.objects.get(order=draft_order).content == (- 'Cancelled item %s' % product)url = reverse('dashboard:orderline-cancel', kwargs={'order_pk': draft_order.pk,@@ -470,13 +467,6 @@ def test_view_change_order_line_quantity(admin_client, draft_order):line.refresh_from_db()# source line quantity should be decreased to 2assert line.quantity == 2- # a note in the order's history should be created- assert OrderHistoryEntry.objects.get(order=draft_order).content == (- 'Changed quantity for product %(product)s from'- ' %(old_quantity)s to %(new_quantity)s') % {- 'product': line.product,- 'old_quantity': line_quantity_before_quantity_change,- 'new_quantity': 2}@pytest.mark.integrationdiff --git a/tests/test_account.py b/tests/test_account.pyindex 69ccd0f8c1..0ec1891ca9 100644--- a/tests/test_account.py+++ b/tests/test_account.py@@ -1,3 +1,4 @@+import jsonfrom urllib.parse import urlencodeimport i18naddress@@ -193,3 +194,27 @@ def test_compare_addresses_different_country(address):copied_address.country = Country('FR')copied_address.save()assert address != copied_address+++def test_user_ajax_label(customer_user):+ address = customer_user.default_billing_address+ label = '%s %s (%s)' % (+ address.first_name, address.last_name, customer_user.email)+ assert customer_user.ajax_label == label+++def test_user_ajax_label_without_address(admin_user):+ assert admin_user.ajax_label == admin_user.email+++def test_ajax_users_list(admin_client, admin_user, customer_user):+ users_list = [+ {'id': admin_user.pk, 'text': admin_user.ajax_label},+ {'id': customer_user.pk, 'text': customer_user.ajax_label}]+ url = reverse('dashboard:ajax-users-list')++ response = admin_client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')+ resp_decoded = json.loads(response.content.decode('utf-8'))++ assert response.status_code == 200+ assert resp_decoded == {'results': users_list}diff --git a/tests/test_checkout.py b/tests/test_checkout.pyindex dc6f2ae080..38ea0dfd20 100644--- a/tests/test_checkout.py+++ b/tests/test_checkout.py@@ -1,7 +1,6 @@-from unittest.mock import MagicMock, Mock+from unittest.mock import Mockimport pytest-from django.conf import settingsfrom django.contrib.auth.models import AnonymousUserfrom django.urls import reversefrom prices import Money, TaxedMoney@@ -10,7 +9,10 @@ from saleor.account.models import Addressfrom saleor.checkout import viewsfrom saleor.checkout.core import STORAGE_SESSION_KEY, Checkoutfrom saleor.checkout.forms import NoteForm+from saleor.checkout.utils import get_voucher_discount_for_checkoutfrom saleor.core.exceptions import InsufficientStock+from saleor.discount import DiscountValueType, VoucherType+from saleor.discount.models import Voucher, NotApplicablefrom saleor.shipping.models import ShippingMethodCountry@@ -214,3 +216,126 @@ def test_note_in_created_order(checkout_with_items):checkout_with_items.note = 'test_note'order = checkout_with_items.create_order()assert order.notes.filter(content='test_note').exists()+++ 'total, discount_value, discount_type, limit, expected_value', [+ ('100', 10, DiscountValueType.FIXED, None, 10),+ ('100.05', 10, DiscountValueType.PERCENTAGE, 100, 10)])+def test_value_voucher_checkout_discount(+ settings, total, discount_value, discount_type, limit, expected_value):+ voucher = Voucher(+ code='unique', type=VoucherType.VALUE,+ discount_value_type=discount_type,+ discount_value=discount_value,+ limit=Money(limit, 'USD') if limit is not None else None)+ subtotal = TaxedMoney(net=Money(total, 'USD'), gross=Money(total, 'USD'))+ checkout = Mock(get_subtotal=Mock(return_value=subtotal))+ discount = get_voucher_discount_for_checkout(voucher, checkout)+ assert discount == Money(expected_value, 'USD')+++def test_value_voucher_checkout_discount_not_applicable(settings):+ voucher = Voucher(+ code='unique', type=VoucherType.VALUE,+ discount_value_type=DiscountValueType.FIXED,+ discount_value=10,+ limit=Money(100, 'USD'))+ subtotal = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))+ checkout = Mock(get_subtotal=Mock(return_value=subtotal))+ with pytest.raises(NotApplicable) as e:+ get_voucher_discount_for_checkout(voucher, checkout)+ assert e.value.limit == Money(100, 'USD')+++ 'shipping_cost, shipping_country_code, discount_value, discount_type, apply_to, expected_value', [ # noqa+ (10, None, 50, DiscountValueType.PERCENTAGE, None, 5),+ (10, None, 20, DiscountValueType.FIXED, None, 10),+ (10, 'PL', 20, DiscountValueType.FIXED, '', 10),+ (5, 'PL', 5, DiscountValueType.FIXED, 'PL', 5)])+def test_shipping_voucher_checkout_discount(+ settings, shipping_cost, shipping_country_code, discount_value,+ discount_type, apply_to, expected_value):+ subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))+ shipping_total = TaxedMoney(+ net=Money(shipping_cost, 'USD'), gross=Money(shipping_cost, 'USD'))+ checkout = Mock(+ get_subtotal=Mock(return_value=subtotal),+ is_shipping_required=True, shipping_method=Mock(+ price=Money(shipping_cost, 'USD'),+ country_code=shipping_country_code,+ get_total_price=Mock(return_value=shipping_total)))+ voucher = Voucher(+ code='unique', type=VoucherType.SHIPPING,+ discount_value_type=discount_type,+ discount_value=discount_value,+ apply_to=apply_to,+ limit=None)+ discount = get_voucher_discount_for_checkout(voucher, checkout)+ assert discount == Money(expected_value, 'USD')+++ 'is_shipping_required, shipping_method, discount_value, discount_type, '+ 'apply_to, limit, subtotal, error_msg', [+ (True, Mock(country_code='PL'), 10, DiscountValueType.FIXED,+ 'US', None, Money(10, 'USD'),+ 'This offer is only valid in United States of America.'),+ (True, None, 10, DiscountValueType.FIXED,+ None, None, Money(10, 'USD'),+ 'Please select a shipping method first.'),+ (False, None, 10, DiscountValueType.FIXED,+ None, None, Money(10, 'USD'),+ 'Your order does not require shipping.'),+ (True, Mock(price=Money(10, 'USD')), 10,+ DiscountValueType.FIXED, None, 5, Money(2, 'USD'),+ 'This offer is only valid for orders over $5.00.')])+def test_shipping_voucher_checkout_discount_not_applicable(+ settings, is_shipping_required, shipping_method, discount_value,+ discount_type, apply_to, limit, subtotal, error_msg):+ subtotal_price = TaxedMoney(net=subtotal, gross=subtotal)+ checkout = Mock(+ is_shipping_required=is_shipping_required,+ shipping_method=shipping_method,+ get_subtotal=Mock(return_value=subtotal_price))+ voucher = Voucher(+ code='unique', type=VoucherType.SHIPPING,+ discount_value_type=discount_type,+ discount_value=discount_value,+ limit=Money(limit, 'USD') if limit is not None else None,+ apply_to=apply_to)+ with pytest.raises(NotApplicable) as e:+ get_voucher_discount_for_checkout(voucher, checkout)+ assert str(e.value) == error_msg+++def test_product_voucher_checkout_discount_not_applicable(+ settings, monkeypatch):+ monkeypatch.setattr(+ 'saleor.checkout.utils.get_product_variants_and_prices',+ lambda cart, product: [])+ voucher = Voucher(+ code='unique', type=VoucherType.PRODUCT,+ discount_value_type=DiscountValueType.FIXED,+ discount_value=10)+ checkout = Mock(cart=Mock())++ with pytest.raises(NotApplicable) as e:+ get_voucher_discount_for_checkout(voucher, checkout)+ assert str(e.value) == 'This offer is only valid for selected items.'+++def test_category_voucher_checkout_discount_not_applicable(+ settings, monkeypatch):+ monkeypatch.setattr(+ 'saleor.checkout.utils.get_category_variants_and_prices',+ lambda cart, product: [])+ voucher = Voucher(+ code='unique', type=VoucherType.CATEGORY,+ discount_value_type=DiscountValueType.FIXED,+ discount_value=10)+ checkout = Mock(cart=Mock())+ with pytest.raises(NotApplicable) as e:+ get_voucher_discount_for_checkout(voucher, checkout)+ assert str(e.value) == 'This offer is only valid for selected items.'diff --git a/tests/test_discounts.py b/tests/test_discounts.pyindex 62c757be42..4517950b7f 100644--- a/tests/test_discounts.py+++ b/tests/test_discounts.py@@ -1,7 +1,9 @@+import jsonfrom datetime import date, timedeltafrom unittest.mock import Mockimport pytest+from django.urls import reversefrom freezegun import freeze_timefrom prices import Money, TaxedMoney@@ -12,7 +14,8 @@ from saleor.discount.forms import CheckoutDiscountFormfrom saleor.discount.models import NotApplicable, Sale, Voucherfrom saleor.discount.utils import (decrease_voucher_usage, get_product_discount_on_sale,- increase_voucher_usage)+ get_product_or_category_voucher_discount, get_shipping_voucher_discount,+ get_value_voucher_discount, increase_voucher_usage)from saleor.product.models import Product, ProductVariant@@ -59,127 +62,12 @@ def test_percentage_discounts(product_in_stock):assert final_price.gross == Money(5, 'USD')- 'total, discount_value, discount_type, limit, expected_value', [- ('100', 10, DiscountValueType.FIXED, None, 10),- ('100.05', 10, DiscountValueType.PERCENTAGE, 100, 10)])-def test_value_voucher_checkout_discount(- settings, total, discount_value, discount_type, limit, expected_value):- voucher = Voucher(- code='unique', type=VoucherType.VALUE,- discount_value_type=discount_type,- discount_value=discount_value,- limit=Money(limit, 'USD') if limit is not None else None)- subtotal = TaxedMoney(net=Money(total, 'USD'), gross=Money(total, 'USD'))- checkout = Mock(get_subtotal=Mock(return_value=subtotal))- discount = get_voucher_discount_for_checkout(voucher, checkout)- assert discount == Money(expected_value, 'USD')---def test_value_voucher_checkout_discount_not_applicable(settings):- voucher = Voucher(- code='unique', type=VoucherType.VALUE,- discount_value_type=DiscountValueType.FIXED,- discount_value=10,- limit=Money(100, 'USD'))- subtotal = TaxedMoney(net=Money(10, 'USD'), gross=Money(10, 'USD'))- checkout = Mock(get_subtotal=Mock(return_value=subtotal))- with pytest.raises(NotApplicable) as e:- get_voucher_discount_for_checkout(voucher, checkout)- assert e.value.limit == Money(100, 'USD')--- 'shipping_cost, shipping_country_code, discount_value, discount_type, apply_to, expected_value', [ # noqa- (10, None, 50, DiscountValueType.PERCENTAGE, None, 5),- (10, None, 20, DiscountValueType.FIXED, None, 10),- (10, 'PL', 20, DiscountValueType.FIXED, '', 10),- (5, 'PL', 5, DiscountValueType.FIXED, 'PL', 5)])-def test_shipping_voucher_checkout_discount(- settings, shipping_cost, shipping_country_code, discount_value,- discount_type, apply_to, expected_value):- subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))- shipping_total = TaxedMoney(- net=Money(shipping_cost, 'USD'), gross=Money(shipping_cost, 'USD'))- checkout = Mock(- get_subtotal=Mock(return_value=subtotal),- is_shipping_required=True, shipping_method=Mock(- price=Money(shipping_cost, 'USD'),- country_code=shipping_country_code,- get_total_price=Mock(return_value=shipping_total)))- voucher = Voucher(- code='unique', type=VoucherType.SHIPPING,- discount_value_type=discount_type,- discount_value=discount_value,- apply_to=apply_to,- limit=None)- discount = get_voucher_discount_for_checkout(voucher, checkout)- assert discount == Money(expected_value, 'USD')--- 'is_shipping_required, shipping_method, discount_value, discount_type, '- 'apply_to, limit, subtotal, error_msg', [- (True, Mock(country_code='PL'), 10, DiscountValueType.FIXED,- 'US', None, Money(10, 'USD'),- 'This offer is only valid in United States of America.'),- (True, None, 10, DiscountValueType.FIXED,- None, None, Money(10, 'USD'),- 'Please select a shipping method first.'),- (False, None, 10, DiscountValueType.FIXED,- None, None, Money(10, 'USD'),- 'Your order does not require shipping.'),- (True, Mock(price=Money(10, 'USD')), 10,- DiscountValueType.FIXED, None, 5, Money(2, 'USD'),- 'This offer is only valid for orders over $5.00.')])-def test_shipping_voucher_checkout_discount_not_applicable(- settings, is_shipping_required, shipping_method, discount_value,- discount_type, apply_to, limit, subtotal, error_msg):- subtotal_price = TaxedMoney(net=subtotal, gross=subtotal)- checkout = Mock(- is_shipping_required=is_shipping_required,- shipping_method=shipping_method,- get_subtotal=Mock(return_value=subtotal_price))- voucher = Voucher(- code='unique', type=VoucherType.SHIPPING,- discount_value_type=discount_type,- discount_value=discount_value,- limit=Money(limit, 'USD') if limit is not None else None,- apply_to=apply_to)- with pytest.raises(NotApplicable) as e:- get_voucher_discount_for_checkout(voucher, checkout)- assert str(e.value) == error_msg---def test_product_voucher_checkout_discount_not_applicable(- settings, monkeypatch):- monkeypatch.setattr(- 'saleor.checkout.utils.get_product_variants_and_prices',- lambda cart, product: [])- voucher = Voucher(- code='unique', type=VoucherType.PRODUCT,- discount_value_type=DiscountValueType.FIXED,- discount_value=10)- checkout = Mock(cart=Mock())-- with pytest.raises(NotApplicable) as e:- get_voucher_discount_for_checkout(voucher, checkout)- assert str(e.value) == 'This offer is only valid for selected items.'---def test_category_voucher_checkout_discount_not_applicable(- settings, monkeypatch):- monkeypatch.setattr(- 'saleor.checkout.utils.get_category_variants_and_prices',- lambda cart, product: [])- voucher = Voucher(- code='unique', type=VoucherType.CATEGORY,- discount_value_type=DiscountValueType.FIXED,- discount_value=10)- checkout = Mock(cart=Mock())- with pytest.raises(NotApplicable) as e:- get_voucher_discount_for_checkout(voucher, checkout)- assert str(e.value) == 'This offer is only valid for selected items.'+def test_voucher_queryset_active(voucher):+ vouchers = Voucher.objects.all()+ assert len(vouchers) == 1+ active_vouchers = Voucher.objects.active(+ date=date.today() - timedelta(days=1))+ assert len(active_vouchers) == 0def test_checkout_discount_form_invalid_voucher_code(monkeypatch):@@ -199,14 +87,6 @@ def test_checkout_discount_form_not_applicable_voucher(monkeypatch, voucher):assert 'voucher' in form.errors-def test_voucher_queryset_active(voucher):- vouchers = Voucher.objects.all()- assert len(vouchers) == 1- active_vouchers = Voucher.objects.active(- date=date.today() - timedelta(days=1))- assert len(active_vouchers) == 0--def test_checkout_discount_form_active_queryset_voucher_not_active(voucher):assert len(Voucher.objects.all()) == 1checkout = Mock(cart=Mock())@@ -336,3 +216,82 @@ def test_decrease_voucher_usage():decrease_voucher_usage(voucher)voucher.refresh_from_db()assert voucher.used == 9+++ 'total, limit, discount_value, discount_value_type, expected_value', [+ (20, 15, 50, DiscountValueType.PERCENTAGE, 10),+ (20, None, 50, DiscountValueType.PERCENTAGE, 10),+ (20, 15, 5, DiscountValueType.FIXED, 5),+ (20, None, 5, DiscountValueType.FIXED, 5)])+def test_get_value_voucher_discount(+ total, limit, discount_value, discount_value_type, expected_value):+ voucher = Voucher(+ code='unique', type=VoucherType.VALUE,+ discount_value_type=discount_value_type,+ discount_value=discount_value,+ limit=Money(limit, 'USD') if limit is not None else None)+ total_price = TaxedMoney(+ net=Money(total, 'USD'), gross=Money(total, 'USD'))+ discount = get_value_voucher_discount(voucher, total_price)+ assert discount == Money(expected_value, 'USD')+++ 'total, limit, shipping_price, discount_value, discount_value_type, expected_value', [ # noqa+ (20, 15, 10, 50, DiscountValueType.PERCENTAGE, 5),+ (20, None, 10, 50, DiscountValueType.PERCENTAGE, 5),+ (20, 15, 10, 5, DiscountValueType.FIXED, 5),+ (20, None, 10, 5, DiscountValueType.FIXED, 5)])+def test_get_shipping_voucher_discount(+ total, limit, shipping_price, discount_value, discount_value_type,+ expected_value):+ voucher = Voucher(+ code='unique', type=VoucherType.VALUE,+ discount_value_type=discount_value_type,+ discount_value=discount_value,+ limit=Money(limit, 'USD') if limit is not None else None)+ total = TaxedMoney(+ net=Money(total, 'USD'), gross=Money(total, 'USD'))+ shipping_price = TaxedMoney(+ net=Money(shipping_price, 'USD'), gross=Money(shipping_price, 'USD'))+ discount = get_shipping_voucher_discount(voucher, total, shipping_price)+ assert discount == Money(expected_value, 'USD')+++ 'prices, discount_value_type, discount_value, voucher_type, apply_to, expected_value', [ # noqa+ ([5, 10, 15], DiscountValueType.PERCENTAGE, 10, VoucherType.PRODUCT,+ VoucherApplyToProduct.ALL_PRODUCTS, 3),+ ([5, 10, 15], DiscountValueType.FIXED, 2, VoucherType.PRODUCT,+ VoucherApplyToProduct.ALL_PRODUCTS, 6),+ ([5, 10, 15], DiscountValueType.FIXED, 2, VoucherType.PRODUCT,+ VoucherApplyToProduct.ONE_PRODUCT, 2),+ ([5, 10, 15], DiscountValueType.FIXED, 2, VoucherType.CATEGORY,+ None, 2)])+def test_get_product_or_category_voucher_discount_all_products(+ prices, discount_value_type, discount_value, voucher_type, apply_to,+ expected_value):+ prices = [+ TaxedMoney(net=Money(price, 'USD'), gross=Money(price, 'USD'))+ for price in prices]+ voucher = Voucher(+ code='unique', type=voucher_type, apply_to=apply_to,+ discount_value_type=discount_value_type,+ discount_value=discount_value)++ discount = get_product_or_category_voucher_discount(voucher, prices)+ assert discount == Money(expected_value, 'USD')+++def test_ajax_voucher_list(admin_client, voucher):+ voucher.name = 'Summer sale'+ voucher.save()+ vouchers_list = [{'id': voucher.pk, 'text': str(voucher)}]+ url = reverse('dashboard:ajax-vouchers')++ response = admin_client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')+ resp_decoded = json.loads(response.content.decode('utf-8'))++ assert response.status_code == 200+ assert resp_decoded == {'results': vouchers_list}diff --git a/tests/test_order.py b/tests/test_order.pyindex 60c45bae2e..8bb7b99396 100644--- a/tests/test_order.py+++ b/tests/test_order.py@@ -1,11 +1,13 @@from decimal import Decimalfrom django.urls import reverse+from payments import PaymentStatusfrom prices import Money, TaxedMoneyfrom tests.utils import get_redirect_location-from saleor.order import FulfillmentStatus, models, OrderStatus+from saleor.order import FulfillmentStatus, OrderStatus, modelsfrom saleor.order.forms import OrderNoteForm+from saleor.order.models import Orderfrom saleor.order.utils import (add_variant_to_order, cancel_fulfillment, cancel_order, recalculate_order,restock_fulfillment_lines, restock_order_lines, update_order_status)@@ -250,3 +252,59 @@ def test_update_order_status(fulfilled_order):update_order_status(fulfilled_order)assert fulfilled_order.status == OrderStatus.UNFULFILLED+++def test_order_queryset_confirmed(draft_order):+ other_orders = [+ Order.objects.create(status=OrderStatus.UNFULFILLED),+ Order.objects.create(status=OrderStatus.PARTIALLY_FULFILLED),+ Order.objects.create(status=OrderStatus.FULFILLED),+ Order.objects.create(status=OrderStatus.CANCELED)+ ]++ confirmed_orders = Order.objects.confirmed()++ assert draft_order not in confirmed_orders+ assert all([order in confirmed_orders for order in other_orders])+++def test_order_queryset_drafts(draft_order):+ other_orders = [+ Order.objects.create(status=OrderStatus.UNFULFILLED),+ Order.objects.create(status=OrderStatus.PARTIALLY_FULFILLED),+ Order.objects.create(status=OrderStatus.FULFILLED),+ Order.objects.create(status=OrderStatus.CANCELED)+ ]++ draft_orders = Order.objects.drafts()++ assert draft_order in draft_orders+ assert all([order not in draft_orders for order in other_orders])+++def test_order_queryset_to_ship():+ total = TaxedMoney(net=Money(10, 'USD'), gross=Money(15, 'USD'))+ orders_to_ship = [+ Order.objects.create(status=OrderStatus.UNFULFILLED, total=total),+ Order.objects.create(+ status=OrderStatus.PARTIALLY_FULFILLED, total=total)+ ]+ for order in orders_to_ship:+ order.payments.create(+ variant='default', status=PaymentStatus.CONFIRMED, currency='USD',+ total=order.total_gross.amount,+ captured_amount=order.total_gross.amount)++ orders_not_to_ship = [+ Order.objects.create(status=OrderStatus.DRAFT, total=total),+ Order.objects.create(status=OrderStatus.UNFULFILLED, total=total),+ Order.objects.create(+ status=OrderStatus.PARTIALLY_FULFILLED, total=total),+ Order.objects.create(status=OrderStatus.FULFILLED, total=total),+ Order.objects.create(status=OrderStatus.CANCELED, total=total)+ ]++ orders = Order.objects.to_ship()++ assert all([order in orders for order in orders_to_ship])+ assert all([order not in orders for order in orders_not_to_ship])diff --git a/tests/test_product.py b/tests/test_product.pyindex 301eddbece..cb2fca7cdf 100644--- a/tests/test_product.py+++ b/tests/test_product.py@@ -1,17 +1,12 @@import datetime-import ioimport json-from contextlib import redirect_stdoutfrom unittest.mock import Mock, patchimport pytest-from django.conf import settingsfrom django.urls import reverse-from django.utils.encoding import smart_textfrom saleor.cart import CartStatus, utilsfrom saleor.cart.models import Cart-from saleor.core.utils import create_thumbnailsfrom saleor.product import (ProductAvailabilityStatus, VariantAvailabilityStatus, models)from saleor.product.models import Category, ProductImage