Example #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)
Example #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")
Example #3
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)
Example #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
Example #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
Example #6
0
def test_shop_specific_cheapest_price_2(rf):
    request, shop, group = initialize_test(rf, False)

    product = create_product("Just-A-Product-Too", shop, default_price=199)

    price_cls = (TaxfulPrice if shop.prices_include_tax else TaxlessPrice)

    SimpleProductPrice.objects.create(product=product, shop=shop, group=group, price=250)
    spm = SimplePricingModule()
    assert product.get_price(spm.get_context_from_request(request), quantity=1) == price_cls(
        199)  # Cheaper price is valid even if the other way around applies
Example #7
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
Example #8
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")
Example #9
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")
Example #10
0
def test_shop_specific_cheapest_price_1(rf):
    request, shop, group = initialize_test(rf, False)

    product = create_product("Just-A-Product", shop, default_price=200)

    # determine which is the taxfulness
    price_cls = TaxfulPrice if shop.prices_include_tax else TaxlessPrice

    # SimpleProductPrice.objects.create(product=product, shop=None, price=200)
    SimpleProductPrice.objects.create(product=product, shop=shop, group=group, price=250)
    spm = SimplePricingModule()
    assert product.get_price(spm.get_context_from_request(request), quantity=1) == price_cls(
        200)  # Cheaper price is valid even if shop-specific price exists
Example #11
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)
Example #12
0
def test_zero_default_price(rf):
    request, shop, group = initialize_test(rf, True)
    price = shop.create_price

    # 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_value=50)

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

    assert price_info.price == price(50)
Example #13
0
def test_shop_specific_cheapest_price_2(rf):
    request, shop, group = initialize_test(rf, False)

    product = create_product("Just-A-Product-Too", shop, default_price=199)

    price_cls = (TaxfulPrice if shop.prices_include_tax else TaxlessPrice)

    SimpleProductPrice.objects.create(product=product,
                                      shop=shop,
                                      group=group,
                                      price=250)
    spm = SimplePricingModule()
    assert product.get_price(
        spm.get_context_from_request(request), quantity=1) == price_cls(
            199)  # Cheaper price is valid even if the other way around applies
Example #14
0
def test_set_taxful_price_works(rf):
    request, shop, group = initialize_test(rf, True)
    price = shop.create_price

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

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

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

    assert price_info.price == price(250)
    assert product.get_price(pricing_context, quantity=1) == price(250)
Example #15
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
Example #16
0
def test_shop_specific_cheapest_price_1(rf):
    request, shop, group = initialize_test(rf, False)

    product = create_product("Just-A-Product", shop, default_price=200)

    # determine which is the taxfulness
    price_cls = TaxfulPrice if shop.prices_include_tax else TaxlessPrice

    # SimpleProductPrice.objects.create(product=product, shop=None, price=200)
    SimpleProductPrice.objects.create(product=product,
                                      shop=shop,
                                      group=group,
                                      price=250)
    spm = SimplePricingModule()
    assert product.get_price(
        spm.get_context_from_request(request), quantity=1) == price_cls(
            200)  # Cheaper price is valid even if shop-specific price exists
Example #17
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)
Example #18
0
def test_no_customer(rf):
    shop = get_default_shop()
    group = get_default_customer_group()
    price = shop.create_price

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

    SimpleProductPrice.objects.create(product=product, group=group, shop=shop, price_value=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 == price(100)
Example #19
0
def test_shop_specific_cheapest_price_2(rf):
    request, shop, group = initialize_test(rf, False)
    price = shop.create_price

    product = create_product("Just-A-Product-Too", shop, default_price=199)

    SimpleProductPrice.objects.create(product=product, shop=shop, group=group, price_value=250)
    spm = SimplePricingModule()

    # Cheaper price is valid even if the other way around applies
    assert product.get_price(request, quantity=1) == price(199)
Example #20
0
def test_shop_specific_cheapest_price_1(rf):
    request, shop, group = initialize_test(rf, False)
    price = shop.create_price

    product = create_product("Just-A-Product", shop, default_price=200)

    # SimpleProductPrice.objects.create(product=product, shop=None, price=200)
    SimpleProductPrice.objects.create(product=product, shop=shop, group=group, price_value=250)
    spm = SimplePricingModule()

    # Cheaper price is valid even if shop-specific price exists
    assert product.get_price(request, quantity=1) == price(200)