Exemplo n.º 1
0
def test_price_infos(rf):
    request, shop, group = initialize_test(rf, True)

    product_one = create_product("Product_1", shop, default_price=150)
    product_two = create_product("Product_2", shop, default_price=250)

    spp = SimpleProductPrice(product=product_one,
                             shop=shop,
                             group=group,
                             price=100)
    spp.save()

    spp = SimpleProductPrice(product=product_two,
                             shop=shop,
                             group=group,
                             price=200)
    spp.save()

    product_ids = [product_one.pk, product_two.pk]

    spm = SimplePricingModule()
    pricing_context = spm.get_context_from_request(request)
    price_infos = spm.get_price_infos(pricing_context, product_ids)

    assert len(price_infos) == 2
    assert product_one.pk in price_infos
    assert product_two.pk in price_infos

    assert price_infos[product_one.pk].price == TaxfulPrice(100)
    assert price_infos[product_two.pk].price == TaxfulPrice(200)

    assert price_infos[product_one.pk].base_price == TaxfulPrice(100)
    assert price_infos[product_two.pk].base_price == TaxfulPrice(200)
Exemplo n.º 2
0
def test_set_taxful_price_works_with_product_id(rf):
    request, shop, group = initialize_test(rf, True)

    product = create_product("Anuva-Product", shop, default_price=300)

    # create ssp with higher price
    spp = SimpleProductPrice(product=product,
                             shop=shop,
                             group=group,
                             price=250)
    spp.save()

    spm = SimplePricingModule()
    pricing_context = spm.get_context_from_request(request)
    price_info = spm.get_price_info(pricing_context,
                                    product=product.pk,
                                    quantity=1)

    assert price_info.price == TaxfulPrice(250)
    assert price_info.includes_tax

    pp = product.get_price(pricing_context, quantity=1)

    assert pp.includes_tax
    assert pp == TaxfulPrice("250")
Exemplo n.º 3
0
def test_set_taxful_price_works():
    product = create_product("Anuva-Product")
    spp = SimpleProductPrice(product=product, shop=None)
    spp.price = 250
    spp.includes_tax = True
    spp.save()
    assert spp.price == 250
    assert spp.includes_tax == True
    spm = SimplePricingModule()
    pp = spm.get_price(spm.get_context_from_data(), product.pk, quantity=1)
    assert pp.includes_tax
    assert pp == TaxfulPrice("250")
Exemplo n.º 4
0
def test_shop_specific_cheapest_price_2(rf):
    shop = get_default_shop()
    request = rf.get("/")
    request.shop = shop
    product = create_product("Just-A-Product-Too")
    SimpleProductPrice.objects.create(product=product, shop=None, price=250)
    SimpleProductPrice.objects.create(product=product, shop=shop, price=199)
    spm = SimplePricingModule()
    assert spm.get_price(
        spm.get_context_from_request(request), product.pk,
        quantity=1) == TaxfulPrice(
            199)  # Cheaper price is valid even if the other way around applies
Exemplo n.º 5
0
def test_shop_specific_cheapest_price_1(rf):
    shop = get_default_shop()
    request = rf.get("/")
    request.shop = shop
    product = create_product("Just-A-Product")
    SimpleProductPrice.objects.create(
        product=product,
        shop=None,
        price=200,
    )
    SimpleProductPrice.objects.create(product=product, shop=shop, price=250)
    spm = SimplePricingModule()
    assert spm.get_price(
        spm.get_context_from_request(request), product.pk,
        quantity=1) == TaxfulPrice(
            200)  # Cheaper price is valid even if shop-specific price exists
Exemplo n.º 6
0
def test_zero_default_price(rf):
    request, shop, group = initialize_test(rf, True)

    # create a product with zero price
    product = create_product("random-1", shop=shop, default_price=0)

    SimpleProductPrice.objects.create(product=product,
                                      group=group,
                                      shop=shop,
                                      price=50)

    spm = SimplePricingModule()
    pricing_context = spm.get_context_from_request(request)
    price_info = spm.get_price_info(pricing_context, product)

    assert price_info.price == TaxfulPrice(50)
Exemplo n.º 7
0
def test_no_customer(rf):
    shop = get_default_shop()
    group = get_default_customer_group()

    product = create_product("random-1", shop=shop, default_price=100)

    SimpleProductPrice.objects.create(product=product,
                                      group=group,
                                      shop=shop,
                                      price=50)

    request = rf.get("/")
    request.shop = shop

    spm = SimplePricingModule()
    pricing_context = spm.get_context_from_request(request)

    price_info = spm.get_price_info(pricing_context, product)

    assert price_info.price == TaxfulPrice(100)