Beispiel #1
0
 def add_two_items_in_catalogue(self):
     first_item, price1, quantity1 = Item("I1"), 2.0, 10
     second_item, price2, quantity2 = Item("I2"), 3.0, 20
     self.catalogue.add_item(first_item, price1, quantity1)
     self.catalogue.add_item(second_item, price2, quantity2)
     assert first_item in self.catalogue.show_items()
     assert second_item in self.catalogue.show_items()
Beispiel #2
0
 def test_discount_calculation(self):
     item1 = Item("item1")
     item2 = Item("item2")
     Catalogue().add_item(item1, 100.0, 10)
     Offers().clear_offers()
     an_offer = PercentOffer(offer_name="p1", percent=10, item=item1)
     Offers().add_offer(an_offer)
     items = {item1: 1, item2: 1}
     expected_discount = 10.0
     actual_discount, _ = an_offer.get_discount_and_remaining_items(items)
     assert expected_discount == actual_discount
Beispiel #3
0
 def test_discount_calculation(self):
     item1 = Item("item1")
     item2 = Item("item2")
     Catalogue().add_item(item1, 100.0, 10)
     Catalogue().add_item(item2, 100.0, 10)
     Offers().clear_offers()
     an_offer = BuynGetmOffer(offer_name="b1", n=2, m=1, item=item1)
     Offers().add_offer(an_offer)
     items = {item1: 4, item2: 4}
     expected_discount = 100.0
     actual_discount, _ = an_offer.get_discount_and_remaining_items(items)
     assert expected_discount == actual_discount
Beispiel #4
0
 def add_more_quantity_without_adding_price(self):
     item, price, quantity = Item("Item"), 2.0, 10
     self.catalogue.add_item(item, price, quantity)
     additional_quantity = 10
     self.catalogue.add_existing_item(
         item, additional_quantity=additional_quantity)
     assert self.catalogue.show_items()[item][1] == 20
    def test_discount_calculation_applied_to_more_items_in_set(self):
        item1 = Item("item1")
        item2 = Item("item2")
        item3 = Item("item3")
        Catalogue().add_item(item1, 100.0, 10)
        Catalogue().add_item(item2, 100.0, 10)
        Catalogue().add_item(item3, 1000.0, 10)
        Offers().clear_offers()

        x = {item2, item3}
        an_offer = BuynOfXOffer(offer_name="b1", n=3, x=x)
        Offers().add_offer(an_offer)
        items = {item1: 4, item2: 4, item3: 2}
        expected_discount = 100.0
        actual_discount, _ = an_offer.get_discount_and_remaining_items(items)
        assert expected_discount == actual_discount
Beispiel #6
0
    def test_calculate_sub_total(self):
        item_1, price_1, quantity_1 = Item("an_item_1"), 100.0, 20
        item_2, price_2, quantity_2 = Item("an_item_2"), 200.0, 20
        quantity_to_add_to_cart_1 = 2
        quantity_to_add_to_cart_2 = 2
        Catalogue().clear_catalogue()
        Catalogue().add_item(item_1, price_1, quantity_1)
        Catalogue().add_item(item_2, price_2, quantity_2)

        expected_sub_total = 600.0

        cart = Cart()
        cart.add_item(item_1, quantity_to_add_to_cart_1)
        cart.add_item(item_2, quantity_to_add_to_cart_2)

        actual_sub_total = cart.calculate_sub_total()
        assert actual_sub_total == expected_sub_total
Beispiel #7
0
 def test_add_item_to_cart(self):
     item_1, price_1, quantity_1 = Item("Item_1"), 2.0, 20
     quantity_to_add_to_cart = 15
     Catalogue().add_item(item_1, price_1, quantity_1)
     cart = Cart()
     cart.add_item(item_1, quantity_to_add_to_cart)
     assert item_1 in cart.show_items()
     assert quantity_to_add_to_cart == cart.show_items()[item_1]
     assert Catalogue().show_items(
     )[item_1][1] == quantity_1 - quantity_to_add_to_cart
Beispiel #8
0
    def test_calculate_totals_for_BuynGetm(self):
        item_1, price_1, quantity_1 = Item("an_item_1"), 100.0, 20
        item_2, price_2, quantity_2 = Item("an_item_2"), 100.0, 20
        quantity_to_add_to_cart_1 = 4
        quantity_to_add_to_cart_2 = 4
        Catalogue().clear_catalogue()
        Catalogue().add_item(item_1, price_1, quantity_1)
        Catalogue().add_item(item_2, price_2, quantity_2)
        Offers().clear_offers()
        an_offer = BuynGetmOffer("b1", 3, 1, item_1)
        Offers().add_offer(an_offer)

        expected_totals = 700.0

        cart = Cart()
        cart.add_item(item_1, quantity_to_add_to_cart_1)
        cart.add_item(item_2, quantity_to_add_to_cart_2)

        actual_total = cart.calculate_totals()
        assert actual_total == expected_totals
Beispiel #9
0
    def test_calculate_percent_discount_on_two_items(self):
        item_1, price_1, quantity_1 = Item("an_item_1"), 100.0, 20
        item_2, price_2, quantity_2 = Item("an_item_2"), 100.0, 20
        quantity_to_add_to_cart_1 = 2
        quantity_to_add_to_cart_2 = 2
        Catalogue().clear_catalogue()
        Catalogue().add_item(item_1, price_1, quantity_1)
        Catalogue().add_item(item_2, price_2, quantity_2)
        Offers().clear_offers()
        an_offer = PercentOffer("p1", 10, item_1)
        another_offer = PercentOffer("p2", 20, item_2)
        Offers().add_offer(an_offer)
        Offers().add_offer(another_offer)

        expected_discount = 60.0

        cart = Cart()
        cart.add_item(item_1, quantity_to_add_to_cart_1)
        cart.add_item(item_2, quantity_to_add_to_cart_2)
        actual_discount = cart.calculate_discount()
        assert actual_discount == expected_discount
Beispiel #10
0
    def setup(self):
        Catalogue().clear_catalogue()
        Offers().clear_offers()
        self.baked_bean = Item("BakedBean")
        self.sardines = Item("Sardines")
        self.biscuits = Item("Biscuits")
        self.shampoo_small = Item("Shampoo(Small)")
        self.shampoo_medium = Item("Shampoo (Medium)")
        self.shampoo_large = Item("Shampoo (Large)")

        catalogue = Catalogue()
        catalogue.add_item(self.baked_bean, 0.99, 100)
        catalogue.add_item(self.sardines, 1.89, 100)
        catalogue.add_item(self.biscuits, 1.20, 100)
        catalogue.add_item(self.shampoo_small, 2.00, 100)
        catalogue.add_item(self.shampoo_medium, 2.50, 100)
        catalogue.add_item(self.shampoo_large, 3.50, 100)

        baked_bean_offer = BuynGetmOffer("bakedBean2For1", 2, 1,
                                         self.baked_bean)
        sardines_offer = PercentOffer("Sardines25", 25, self.sardines)
        shampoo_offer = BuynOfXOffer(
            "ShampooSet3", 3,
            {self.shampoo_small, self.shampoo_medium, self.shampoo_large})
        Offers().add_offer(baked_bean_offer)
        Offers().add_offer(sardines_offer)
        Offers().add_offer(shampoo_offer)
Beispiel #11
0
 def getItemsMap(self):
     ItemsMap = {}
     item = Item(
         1, 'First', 11,
         self._getItemIcon(self._getItemImgPath('img//Items//1.jpg')))
     ItemsMap[1] = item
     item = Item(
         2, 'Second', 20,
         self._getItemIcon(self._getItemImgPath('img/Items//2.jpg')))
     ItemsMap[2] = item
     item = Item(
         3, 'Third', 21,
         self._getItemIcon(self._getItemImgPath('img//Items//3.jpg')))
     ItemsMap[3] = item
     item = Item(
         4, 'Fourth', 51,
         self._getItemIcon(self._getItemImgPath('img//Items//4.jpg')))
     ItemsMap[4] = item
     item = Item(
         5, '', 0,
         self._getItemIcon(self._getItemImgPath('img//Items//NoItem.jpg')))
     ItemsMap[5] = item
     item = Item(
         6, '', 0,
         self._getItemIcon(self._getItemImgPath('img//Items//NoItem.jpg')))
     ItemsMap[6] = item
     return ItemsMap
Beispiel #12
0
    def test_remove_item_from_cart(self):
        item_1, price_1, quantity_1 = Item("Item_2"), 2.0, 20
        quantity_to_add_to_cart = 15
        Catalogue().add_item(item_1, price_1, quantity_1)
        cart = Cart()
        cart.add_item(item_1, quantity_to_add_to_cart)

        quantity_to_remove_from_cart = 5
        cart.remove_item(item_1, quantity_to_remove_from_cart)
        assert cart.show_items(
        )[item_1] == quantity_to_add_to_cart - quantity_to_remove_from_cart
        assert Catalogue().show_items()[item_1][
            1] == quantity_1 - quantity_to_add_to_cart + quantity_to_remove_from_cart
Beispiel #13
0
    def test_calculate_percent_discount(self):
        item_1, price_1, quantity_1 = Item("an_item"), 100.0, 20
        quantity_to_add_to_cart = 2
        Catalogue().clear_catalogue()
        Catalogue().add_item(item_1, price_1, quantity_1)
        Offers().clear_offers()
        an_offer = PercentOffer("p1", 10, item_1)
        Offers().add_offer(an_offer)
        expected_discount = 20.0

        cart = Cart()
        cart.add_item(item_1, quantity_to_add_to_cart)
        actual_discount = cart.calculate_discount()
        assert actual_discount == expected_discount
Beispiel #14
0
 def __init__(self, btnId, itemsForSale, button, label):
     QObject.__init__(self)
     self.button=button
     self.label=label
     if btnId<=len(itemsForSale):
         buttonContext=itemsForSale[btnId-1]
         self.btnId=btnId
         itemId=buttonContext[0]
         itemName=buttonContext[1]
         itemPrice=buttonContext[2]/100.
         itemIcon=buttonContext[3]
         self.item=Item(itemId, itemName, itemPrice, itemIcon)
         self.label.setText(str(int(itemPrice)))
     else:
         itemId=0
         self.item=None
         self.label.setText('')
Beispiel #15
0
 def remove_some_quantity_of_an_item_from_catalogue(self):
     item, price, quantity = Item("Item"), 2.0, 10
     self.catalogue.add_item(item, price, quantity)
     if item in self.catalogue.show_items():
         self.catalogue.remove_item(item, 4)
     assert self.catalogue.show_items()[item][1] == 6
Beispiel #16
0
 def remove_all_quantity_of_an_item_from_catalogue(self):
     an_item, price, quantity = Item("AnItem"), 2.0, 10
     self.catalogue.add_item(an_item, price, quantity)
     if an_item in self.catalogue.show_items():
         self.catalogue.remove_item(an_item, 10)
     assert self.catalogue.show_items()[an_item][1] == 0
Beispiel #17
0
 def test_add_an_item_to_catalogue(self):
     first_item, price, quantity = Item("FirstItem"), 2.0, 10
     self.catalogue.add_item(first_item, price, quantity)
     assert first_item in self.catalogue.show_items()
     assert price == self.catalogue.show_items()[first_item][0]
     assert quantity == self.catalogue.show_items()[first_item][1]
Beispiel #18
0
 def test_there_is_only_one_catalogue(self):
     an_item, price, quantity = Item("Item1"), 2.0, 10
     catalogue1 = Catalogue()
     catalogue1.add_item(an_item, price, quantity)
     catalogue2 = Catalogue()
     assert an_item in catalogue2.show_items()