示例#1
0
def test_limited_methods():
    """
    Test that products can declare that they limit available shipping methods.
    """
    unique_shipping_method = ShippingMethod(tax_class=get_default_tax_class(), module_data={"price": 0})
    unique_shipping_method.save()
    shop = get_default_shop()
    common_product = create_product(sku="SH_COMMON", shop=shop)  # A product that does not limit shipping methods
    unique_product = create_product(sku="SH_UNIQUE", shop=shop)  # A product that only supports unique_shipping_method
    unique_shop_product = unique_product.get_shop_instance(shop)
    unique_shop_product.limit_shipping_methods = True
    unique_shop_product.shipping_methods.add(unique_shipping_method)
    unique_shop_product.save()
    impossible_product = create_product(sku="SH_IMP", shop=shop)  # A product that can't be shipped at all
    imp_shop_product = impossible_product.get_shop_instance(shop)
    imp_shop_product.limit_shipping_methods = True
    imp_shop_product.save()
    for product_ids, method_ids in [
        ((common_product.pk, unique_product.pk), (unique_shipping_method.pk,)),
        ((common_product.pk,), ShippingMethod.objects.values_list("pk", flat=True)),
        ((unique_product.pk,), (unique_shipping_method.pk,)),
        ((unique_product.pk, impossible_product.pk,), ()),
        ((common_product.pk, impossible_product.pk,), ()),
    ]:
        product_ids = set(product_ids)
        assert ShippingMethod.objects.available_ids(shop=shop, products=product_ids) == set(method_ids)
示例#2
0
def test_weight_limits():
    sm = ShippingMethod(tax_class=get_default_tax_class())
    sm.module_data = {"min_weight": "100", "max_weight": "500"}
    source = BasketishOrderSource(get_default_shop())
    assert any(ve.code == "min_weight" for ve in sm.get_validation_errors(source))
    source.add_line(type=OrderLineType.PRODUCT, weight=600)
    assert any(ve.code == "max_weight" for ve in sm.get_validation_errors(source))
示例#3
0
def get_expensive_sweden_shipping_method():
    sm = ShippingMethod(
        identifier=ExpensiveSwedenShippingModule.identifier,
        module_identifier=ExpensiveSwedenShippingModule.identifier,
        tax_class=get_default_tax_class(),
    )
    sm.module_data = {"min_weight": "0.11000000", "max_weight": "3.00000000", "price_waiver_product_minimum": "370"}
    sm.save()
    return sm
示例#4
0
def test_weight_limits():
    sm = ShippingMethod(tax_class=get_default_tax_class())
    sm.module_data = {"min_weight": "100", "max_weight": "500"}
    source = BasketishOrderSource(get_default_shop())
    assert any(ve.code == "min_weight"
               for ve in sm.get_validation_errors(source))
    source.add_line(type=OrderLineType.PRODUCT, weight=600)
    assert any(ve.code == "max_weight"
               for ve in sm.get_validation_errors(source))
示例#5
0
def test_tax():
    sm = ShippingMethod(tax_class=None, module_data={"price": 50})
    source = BasketishOrderSource(get_default_shop())
    # Since `tax_class` is None, the highest tax percentage in the order should be used:
    source.add_line(type=OrderLineType.PRODUCT, tax_rate=Decimal("0.8"))
    source.add_line(type=OrderLineType.PRODUCT, tax_rate=Decimal("0.3"))
    line = list(sm.get_source_lines(source))[0]
    assert line.tax_rate == Decimal("0.8")

    sm.tax_class = get_default_tax_group()
    line = list(sm.get_source_lines(source))[0]
    assert line.tax_rate == sm.tax_class.tax_rate
示例#6
0
def get_expensive_sweden_shipping_method():
    sm = ShippingMethod(
        identifier=ExpensiveSwedenShippingModule.identifier,
        module_identifier=ExpensiveSwedenShippingModule.identifier,
        tax_class=get_default_tax_class())
    sm.module_data = {
        "min_weight": "0.11000000",
        "max_weight": "3.00000000",
        "price_waiver_product_minimum": "370"
    }
    sm.save()
    return sm
示例#7
0
def test_tax():
    sm = ShippingMethod(tax_class=None, module_data={"price": 50})
    source = BasketishOrderSource(get_default_shop())
    # Since `tax_class` is None, the highest tax percentage in the order should be used:
    source.add_line(type=OrderLineType.PRODUCT, tax_rate=Decimal("0.8"))
    source.add_line(type=OrderLineType.PRODUCT, tax_rate=Decimal("0.3"))
    line = list(sm.get_source_lines(source))[0]
    assert line.tax_rate == Decimal("0.8")

    sm.tax_class = get_default_tax_group()
    line = list(sm.get_source_lines(source))[0]
    assert line.tax_rate == sm.tax_class.tax_rate
示例#8
0
def test_waiver():
    sm = ShippingMethod(
        name="Waivey",
        tax_class=get_default_tax_class(),
        module_data={"price_waiver_product_minimum": "370", "price": "100"},
    )
    source = BasketishOrderSource()
    assert not source.prices_include_tax()
    assert sm.get_effective_name(source) == u"Waivey"
    assert sm.get_effective_price(source) == TaxlessPrice(100)
    source.lines = [
        SourceLine(type=OrderLineType.PRODUCT, product=get_default_product(), unit_price=TaxlessPrice(400), quantity=1)
    ]
    assert sm.get_effective_price(source) == TaxlessPrice(0)
示例#9
0
def test_waiver():
    sm = ShippingMethod(name="Waivey", tax_class=get_default_tax_class(),
                        module_data={
                            "price_waiver_product_minimum": "370",
                            "price": "100"
                        })
    source = BasketishOrderSource(get_default_shop())
    assert sm.get_effective_name(source) == u"Waivey"
    assert sm.get_effective_price_info(source).price == source.shop.create_price(100)
    source.add_line(
        type=OrderLineType.PRODUCT,
        product=get_default_product(),
        base_unit_price=source.shop.create_price(400),
        quantity=1
    )
    assert sm.get_effective_price_info(source).price == source.shop.create_price(0)
示例#10
0
def test_waiver():
    sm = ShippingMethod(name="Waivey",
                        tax_class=get_default_tax_class(),
                        module_data={
                            "price_waiver_product_minimum": "370",
                            "price": "100"
                        })
    source = BasketishOrderSource(get_default_shop())
    assert sm.get_effective_name(source) == u"Waivey"
    assert sm.get_effective_price_info(
        source).price == source.shop.create_price(100)
    source.add_line(type=OrderLineType.PRODUCT,
                    product=get_default_product(),
                    base_unit_price=source.shop.create_price(400),
                    quantity=1)
    assert sm.get_effective_price_info(
        source).price == source.shop.create_price(0)
示例#11
0
def test_waiver():
    sm = ShippingMethod(name="Waivey",
                        tax_class=get_default_tax_class(),
                        module_data={
                            "price_waiver_product_minimum": "370",
                            "price": "100"
                        })
    source = BasketishOrderSource()
    assert not source.prices_include_tax()
    assert sm.get_effective_name(source) == u"Waivey"
    assert sm.get_effective_price(source) == TaxlessPrice(100)
    source.lines = [
        SourceLine(type=OrderLineType.PRODUCT,
                   product=get_default_product(),
                   unit_price=TaxlessPrice(400),
                   quantity=1)
    ]
    assert sm.get_effective_price(source) == TaxlessPrice(0)
示例#12
0
def test_limited_methods():
    """
    Test that products can declare that they limit available shipping methods.
    """
    unique_shipping_method = ShippingMethod(tax_class=get_default_tax_class(),
                                            module_data={"price": 0})
    unique_shipping_method.save()
    shop = get_default_shop()
    common_product = create_product(
        sku="SH_COMMON",
        shop=shop)  # A product that does not limit shipping methods
    unique_product = create_product(
        sku="SH_UNIQUE",
        shop=shop)  # A product that only supports unique_shipping_method
    unique_shop_product = unique_product.get_shop_instance(shop)
    unique_shop_product.limit_shipping_methods = True
    unique_shop_product.shipping_methods.add(unique_shipping_method)
    unique_shop_product.save()
    impossible_product = create_product(
        sku="SH_IMP", shop=shop)  # A product that can't be shipped at all
    imp_shop_product = impossible_product.get_shop_instance(shop)
    imp_shop_product.limit_shipping_methods = True
    imp_shop_product.save()
    for product_ids, method_ids in [
        ((common_product.pk, unique_product.pk),
         (unique_shipping_method.pk, )),
        ((common_product.pk, ),
         ShippingMethod.objects.values_list("pk", flat=True)),
        ((unique_product.pk, ), (unique_shipping_method.pk, )),
        ((
            unique_product.pk,
            impossible_product.pk,
        ), ()),
        ((
            common_product.pk,
            impossible_product.pk,
        ), ()),
    ]:
        product_ids = set(product_ids)
        assert ShippingMethod.objects.available_ids(
            shop=shop, products=product_ids) == set(method_ids)
示例#13
0
def test_method_list(admin_user):
    with override_provides_for_expensive_sweden_shipping_method():
        assert any(name == "Expensive Sweden Shipping" for (spec, name) in ShippingMethod.get_module_choices())
示例#14
0
def test_method_list(admin_user):
    with override_provides_for_expensive_sweden_shipping_method():
        assert any(name == "Expensive Sweden Shipping"
                   for (spec, name) in ShippingMethod.get_module_choices())