def test_order_modifier(rf, admin_user): order, source = get_order_and_source(admin_user, get_default_product()) # get original values taxful_total_price = order.taxful_total_price_value taxless_total_price = order.taxless_total_price_value original_line_count = order.lines.count() # modify source source.billing_address = MutableAddress.objects.create(name="New Billing") source.shipping_address = MutableAddress.objects.create(name="New Shipping") modifier = OrderModifier() modifier.update_order_from_source(source, order) # new param to edit order from source assert Order.objects.count() == 1 order = Order.objects.first() assert order.billing_address.name == "New Billing" assert order.shipping_address.name == "New Shipping" assert order.taxful_total_price_value == taxful_total_price assert order.taxless_total_price_value == taxless_total_price # add new line to order source source.add_line( type=OrderLineType.OTHER, quantity=1, base_unit_price=source.create_price(10), require_verification=True, ) modifier.update_order_from_source(source, order) assert order.lines.count() == original_line_count + 1
def test_modify_order_with_package_product(admin_user): package_children = 4 package = create_package_product("parent", get_default_shop(), get_default_supplier(), 100, package_children) order, source = get_order_and_source(admin_user, package) source.add_line( type=OrderLineType.OTHER, quantity=1, base_unit_price=source.create_price(10), require_verification=True, ) modifier = OrderModifier() modifier.update_order_from_source(source, order) assert order.lines.products().count() == 1 + package_children # parent + children assert order.lines.other().count() == 2 # one added here + one from original order
def test_shop_change(rf, admin_user): order, source = get_order_and_source(admin_user) shop = Shop.objects.create(name="Another shop", identifier="another-shop", status=ShopStatus.ENABLED, public_name="Another shop") source.shop = shop modifier = OrderModifier() assert order.shop != source.shop # Changing shop should be blocked. Source shop is just ignored. edited_order = modifier.update_order_from_source(source, order) assert edited_order.shop == order.shop
def test_shop_change(rf, admin_user): order, source = get_order_and_source(admin_user, get_default_product()) shop = Shop.objects.create( name="Another shop", identifier="another-shop", status=ShopStatus.ENABLED, public_name="Another shop" ) source.shop = shop modifier = OrderModifier() assert order.shop != source.shop # Changing shop should be blocked. Source shop is just ignored. edited_order = modifier.update_order_from_source(source, order) assert edited_order.shop == order.shop
def test_shop_change(rf, admin_user): order, source = get_order_and_source(admin_user, get_default_product()) shop = Shop.objects.create(name="Another shop", identifier="another-shop", status=ShopStatus.ENABLED, public_name="Another shop") source.shop = shop modifier = OrderModifier() assert order.shop != source.shop order_count = Order.objects.count() with pytest.raises(ValidationError): # Changing shop should be blocked. Source shop is just ignored. modifier.update_order_from_source(source, order) assert order_count == Order.objects.count(), "no new orders created"
def test_shop_change(rf, admin_user): order, source = get_order_and_source(admin_user, get_default_product()) shop = Shop.objects.create( name="Another shop", identifier="another-shop", status=ShopStatus.ENABLED, public_name="Another shop" ) source.shop = shop modifier = OrderModifier() assert order.shop != source.shop order_count = Order.objects.count() with pytest.raises(ValidationError): # Changing shop should be blocked. Source shop is just ignored. modifier.update_order_from_source(source, order) assert order_count == Order.objects.count(), "no new orders created"
def test_order_cannot_be_created(): modifier = OrderModifier() with pytest.raises(AttributeError): modifier.create_order(None)