コード例 #1
0
def test_pricer_calculates_sub_total_for_multi_quantity():
    catalogue_provider = CatalogueProvider({"APPLE": Decimal("5")})
    offer_provider = OfferProvider({})
    basket = {"APPLE": 3}
    pricer = BasketPricer(catalogue_provider, offer_provider)
    prices = pricer.calculate_basket_prices(basket)
    assert prices["sub_total"] == Decimal("15")
コード例 #2
0
def test_pricer_calculated_total_cant_be_negative():
    catalogue_provider = CatalogueProvider({"APPLE": Decimal("-5")})
    offer_provider = OfferProvider({})
    basket = {"APPLE": 1}
    pricer = BasketPricer(catalogue_provider, offer_provider)
    with pytest.raises(NegativeBasketPriceException):
        pricer.calculate_basket_prices(basket)
コード例 #3
0
def test_pricer_calculates_sub_total_using_product_price():
    catalogue_provider = CatalogueProvider({"APPLE": Decimal("5")})
    offer_provider = OfferProvider({})
    basket = {"APPLE": 1}
    pricer = BasketPricer(catalogue_provider, offer_provider)
    prices = pricer.calculate_basket_prices(basket)
    assert prices["sub_total"] == Decimal("5")
コード例 #4
0
def test_pricer_calculates_percentage_discount_for_product():
    catalogue_provider = CatalogueProvider({"APPLE": Decimal("5")})
    offer_provider = OfferProvider({"APPLE": [PercentageOffer(Decimal("10"))]})
    basket = {"APPLE": 1}
    pricer = BasketPricer(catalogue_provider, offer_provider)
    prices = pricer.calculate_basket_prices(basket)
    assert prices["discount"] == Decimal("0.5")
コード例 #5
0
def test_pricer_calculates_sub_total_from_basket_products():
    catalogue_provider = CatalogueProvider({"APPLE": Decimal("5")})
    offer_provider = OfferProvider({})
    basket = {"APPLE": 1}
    pricer = BasketPricer(catalogue_provider, offer_provider)
    assert pricer.calculate_basket_prices(basket) == {
        "sub_total": Decimal("5"),
        "discount": Decimal("0"),
        "total": Decimal("5"),
    }
コード例 #6
0
def test_pricer_returns_prices():
    catalogue_provider = CatalogueProvider({})
    offer_provider = OfferProvider({})
    basket = {}
    pricer = BasketPricer(catalogue_provider, offer_provider)
    assert pricer.calculate_basket_prices(basket) == {
        "sub_total": Decimal("0"),
        "discount": Decimal("0"),
        "total": Decimal("0"),
    }
    def test_baskets(self, first_basket, second_basket, catalogue, offers):
        second_pricer = BasketPricer(first_basket, catalogue, offers)
        assert second_pricer.sub_total == Decimal("5.16")
        assert second_pricer.discount == Decimal("1.98")
        assert second_pricer.total == Decimal("3.18")

        second_pricer = BasketPricer(second_basket, catalogue, offers)
        assert second_pricer.sub_total == Decimal("6.96")
        assert second_pricer.discount == Decimal("1.94")
        assert second_pricer.total == Decimal("5.02")
コード例 #8
0
def test_pricer_calculates_sub_total_for_multiple_products_in_basket():
    catalogue_provider = CatalogueProvider({
        "APPLE": Decimal("5"),
        "CHEESE": Decimal("3")
    })
    offer_provider = OfferProvider({})
    basket = {"APPLE": 2, "CHEESE": 1}
    pricer = BasketPricer(catalogue_provider, offer_provider)
    prices = pricer.calculate_basket_prices(basket)
    assert prices["sub_total"] == Decimal("13")
コード例 #9
0
def test_pricer_calculates_chooses_highest_discount():
    catalogue_provider = CatalogueProvider({"APPLE": Decimal("5")})
    offer_provider = OfferProvider({
        "APPLE":
        [PercentageOffer(Decimal("10")),
         PercentageOffer(Decimal("15"))],
    })
    basket = {"APPLE": 1}
    pricer = BasketPricer(catalogue_provider, offer_provider)
    prices = pricer.calculate_basket_prices(basket)
    assert prices["discount"] == Decimal("0.75")
コード例 #10
0
def test_pricer_calculates_correctly_total_value():
    catalogue_provider = CatalogueProvider({
        "APPLE": Decimal("5"),
        "POTATO": Decimal("2")
    })
    offer_provider = OfferProvider({"APPLE": [PercentageOffer(Decimal("20"))]})
    basket = {"APPLE": 4, "POTATO": 2, "NOT_IN_CATALOGUE_PRODUCT": 3}
    pricer = BasketPricer(catalogue_provider, offer_provider)
    assert pricer.calculate_basket_prices(basket) == {
        "sub_total": Decimal("24"),
        "discount": Decimal("4"),
        "total": Decimal("20"),
    }
コード例 #11
0
def test_pricer_returns_zero_prices_when_basket_is_empty():
    catalogue_provider = CatalogueProvider({
        "APPLE": Decimal("5"),
        "CHEESE": Decimal("3")
    })
    offer_provider = OfferProvider({})
    basket = {}
    pricer = BasketPricer(catalogue_provider, offer_provider)
    assert pricer.calculate_basket_prices(basket) == {
        "sub_total": Decimal("0"),
        "discount": Decimal("0"),
        "total": Decimal("0"),
    }
def test_garbage_basket():
    BasketPricer({1: 1.3}, {"abc": 1.22})
def test_garbage_offers():
    BasketPricer({"test": 1}, {"test": 1.12}, {"test": (123, )})
def test_garbage_catalogue():
    BasketPricer({"test": 1}, {"test": "dasda"})
コード例 #15
0
 def pricer_with_multiple_offers(self, basket, catalogue, multiple_offers):
     return BasketPricer(basket, catalogue, multiple_offers)
コード例 #16
0
 def pricer_with_basket_catalogue_and_offers(self, basket, catalogue,
                                             offers):
     return BasketPricer(basket, catalogue, offers)
コード例 #17
0
 def pricer_with_basket_and_catalogue(self, basket, catalogue):
     return BasketPricer(basket, catalogue)
コード例 #18
0
 def empty_pricer(self):
     return BasketPricer({}, {})