def test_order_modifier(rf, admin_user): order, source = get_order_and_source(admin_user) # 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_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) 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_order_modifier(rf, admin_user): order, source = get_order_and_source(admin_user) # 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_order_cannot_be_created(): modifier = OrderModifier() with pytest.raises(AttributeError): modifier.create_order(None)