def test_translations_of_method_and_component(): sm = get_shipping_method(name="Unique shipping") sm.set_current_language('en') sm.name = "Shipping" sm.set_current_language('fi') sm.name = "Toimitus" sm.save() cost = FixedCostBehaviorComponent.objects.language('fi').create( price_value=10, description="kymppi") cost.set_current_language('en') cost.description = "ten bucks" cost.save() sm.behavior_components.add(cost) source = BasketishOrderSource(get_default_shop()) source.shipping_method = sm translation.activate('fi') shipping_lines = [ line for line in source.get_final_lines() if line.type == OrderLineType.SHIPPING ] assert len(shipping_lines) == 1 assert shipping_lines[0].text == 'Toimitus: kymppi' translation.activate('en') source.uncache() shipping_lines = [ line for line in source.get_final_lines() if line.type == OrderLineType.SHIPPING ] assert len(shipping_lines) == 1 assert shipping_lines[0].text == 'Shipping: ten bucks'
def test_translations_of_method_and_component(): sm = get_shipping_method(name="Unique shipping") sm.set_current_language('en') sm.name = "Shipping" sm.set_current_language('fi') sm.name = "Toimitus" sm.save() cost = FixedCostBehaviorComponent.objects.language('fi').create( price_value=10, description="kymppi") cost.set_current_language('en') cost.description = "ten bucks" cost.save() sm.behavior_components.add(cost) source = BasketishOrderSource(get_default_shop()) source.shipping_method = sm translation.activate('fi') shipping_lines = [ line for line in source.get_final_lines() if line.type == OrderLineType.SHIPPING] assert len(shipping_lines) == 1 assert shipping_lines[0].text == 'Toimitus: kymppi' translation.activate('en') source.uncache() shipping_lines = [ line for line in source.get_final_lines() if line.type == OrderLineType.SHIPPING] assert len(shipping_lines) == 1 assert shipping_lines[0].text == 'Shipping: ten bucks'
def test_methods_possible_no_shipping_address(admin_user): with patch.object(CorreiosWS, 'get_preco_prazo', return_value=MOCKED_SUCCESS_RESULT): contact = get_person_contact(admin_user) source = BasketishOrderSource(get_default_shop()) default_product = get_default_product() default_product.width = 500 default_product.depth = 400 default_product.heith = 130 default_product.save() source.add_line( type=OrderLineType.PRODUCT, product=default_product, supplier=get_default_supplier(), quantity=1, base_unit_price=source.create_price(10), weight=Decimal("0.2")) billing_address = get_address(name="My House", country='BR') billing_address.postal_code = "89070210" source.billing_address = billing_address source.shipping_address = None source.customer = contact source.shipping_method = get_correios_carrier_1() source.payment_method = get_payment_method(name="neat", price=4) assert source.shipping_method_id assert source.payment_method_id errors = list(source.get_validation_errors()) # no errors assert len(errors) == 0 final_lines = list(source.get_final_lines()) assert any(line.type == OrderLineType.SHIPPING for line in final_lines) for line in final_lines: if line.type == OrderLineType.SHIPPING: assert line.text == "Correios - PAC #1" # no billing addres also - no shipping source.billing_address = None list(source.get_final_lines())
def test_methods(admin_user, country): contact = get_person_contact(admin_user) source = BasketishOrderSource(get_default_shop()) source.add_line( type=OrderLineType.PRODUCT, product=get_default_product(), supplier=get_default_supplier(), quantity=1, base_unit_price=source.create_price(10), weight=Decimal("0.2") ) billing_address = get_address() shipping_address = get_address(name="Shippy Doge", country=country) source.billing_address = billing_address source.shipping_address = shipping_address source.customer = contact source.shipping_method = get_expensive_sweden_shipping_method() source.payment_method = get_payment_method(name="neat", price=4) assert source.shipping_method_id assert source.payment_method_id errors = list(source.get_validation_errors()) if country == "FI": # "Expenseefe-a Svedee Sheepping" will not allow shipping to # Finland, let's see if that holds true assert any([ve.code == "we_no_speak_finnish" for ve in errors]) assert [x.code for x in errors] == ["we_no_speak_finnish"] return # Shouldn't try the rest if we got an error here else: assert not errors final_lines = list(source.get_final_lines()) assert any(line.type == OrderLineType.SHIPPING for line in final_lines) for line in final_lines: if line.type == OrderLineType.SHIPPING: if country == "SE": # We _are_ using Expenseefe-a Svedee Sheepping after all. assert line.price == source.create_price("5.00") else: assert line.price == source.create_price("4.00") assert line.text == u"Expenseefe-a Svedee Sheepping" if line.type == OrderLineType.PAYMENT: assert line.price == source.create_price(4)
def test_methods(admin_user, country): contact = get_person_contact(admin_user) source = BasketishOrderSource(get_default_shop()) source.add_line( type=OrderLineType.PRODUCT, product=get_default_product(), supplier=get_default_supplier(), quantity=1, base_unit_price=source.create_price(10), weight=Decimal("0.2") ) billing_address = get_address() shipping_address = get_address(name="Shippy Doge", country=country) source.billing_address = billing_address source.shipping_address = shipping_address source.customer = contact source.shipping_method = get_expensive_sweden_shipping_method() source.payment_method = get_payment_method(name="neat", price=4) assert source.shipping_method_id assert source.payment_method_id errors = list(source.get_validation_errors()) if country == "FI": # "Expenseefe-a Svedee Sheepping" will not allow shipping to # Finland, let's see if that holds true assert any([ve.code == "we_no_speak_finnish" for ve in errors]) assert [x.code for x in errors] == ["we_no_speak_finnish"] return # Shouldn't try the rest if we got an error here else: assert not errors final_lines = list(source.get_final_lines()) assert any(line.type == OrderLineType.SHIPPING for line in final_lines) for line in final_lines: if line.type == OrderLineType.SHIPPING: if country == "SE": # We _are_ using Expenseefe-a Svedee Sheepping after all. assert line.price == source.create_price("5.00") else: assert line.price == source.create_price("4.00") assert line.text == u"Expenseefe-a Svedee Sheepping" if line.type == OrderLineType.PAYMENT: assert line.price == source.create_price(4)