Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add tests for get_valid_shipping_methods_for_order method
IKarbowiakf90a582e33d9
diff --git a/saleor/order/tests/test_order_utils.py b/saleor/order/tests/test_order_utils.pyindex ae2e0f48d1..c9d7784c01 100644--- a/saleor/order/tests/test_order_utils.py+++ b/saleor/order/tests/test_order_utils.py@@ -3,7 +3,11 @@ import pytestfrom .. import OrderStatusfrom ..events import OrderEventsfrom ..models import Order, OrderEvent-from ..utils import change_order_line_quantity, match_orders_with_new_user+from ..utils import (+ change_order_line_quantity,+ get_valid_shipping_methods_for_order,+ match_orders_with_new_user,+)@pytest.mark.parametrize(@@ -74,3 +78,76 @@ def test_match_draft_order_with_new_user(customer_user, channel_USD):order.refresh_from_db()assert order.user is None+++def test_get_valid_shipping_methods_for_order(order_line_with_one_allocation, address):+ # given+ order = order_line_with_one_allocation.order+ order_line_with_one_allocation.is_shipping_required = True+ order_line_with_one_allocation.save(update_fields=["is_shipping_required"])++ order.currency = "USD"+ order.shipping_address = address+ order.save(update_fields=["shipping_address"])++ # when+ valid_shipping_methods = get_valid_shipping_methods_for_order(order)++ # then+ assert len(valid_shipping_methods) == 1+++def test_get_valid_shipping_methods_for_order_no_channel_shipping_zones(+ order_line_with_one_allocation, address+):+ # given+ order = order_line_with_one_allocation.order+ order.channel.shipping_zones.clear()+ order_line_with_one_allocation.is_shipping_required = True+ order_line_with_one_allocation.save(update_fields=["is_shipping_required"])++ order.currency = "USD"+ order.shipping_address = address+ order.save(update_fields=["shipping_address"])++ # when+ valid_shipping_methods = get_valid_shipping_methods_for_order(order)++ # then+ assert len(valid_shipping_methods) == 0+++def test_get_valid_shipping_methods_for_order_no_shipping_address(+ order_line_with_one_allocation, address+):+ # given+ order = order_line_with_one_allocation.order+ order_line_with_one_allocation.is_shipping_required = True+ order_line_with_one_allocation.save(update_fields=["is_shipping_required"])++ order.currency = "USD"++ # when+ valid_shipping_methods = get_valid_shipping_methods_for_order(order)++ # then+ assert valid_shipping_methods is None+++def test_get_valid_shipping_methods_for_order_shipping_not_required(+ order_line_with_one_allocation, address+):+ # given+ order = order_line_with_one_allocation.order+ order_line_with_one_allocation.is_shipping_required = False+ order_line_with_one_allocation.save(update_fields=["is_shipping_required"])++ order.currency = "USD"+ order.shipping_address = address+ order.save(update_fields=["shipping_address"])++ # when+ valid_shipping_methods = get_valid_shipping_methods_for_order(order)++ # then+ assert valid_shipping_methods is None