def test_get_price(self): date_str = '04-20-2020' dt = timedelta(days=10) date_object = datetime.strptime(date_str, '%m-%d-%Y') self.product = Product("apple", 2, "food", None, 1) self.product.discount.append(VisibleProductDiscount(date_object, date_object + dt, 50)) self.assertEqual(1, self.product.get_price_after_discount())
def setUp(self): self.inv = Inventory() self.inv.products["orange"] = Product("orange", 2, "food", None, 6) self.inv.products["Banana"] = Product("Banana", 2, "food", None, 2) self.inv.products["Tako"] = Product("Tako", 2, "food", None, 2) self.inv.products["Bamba"] = Product("Bamba", 2, "food", None, 2) self.inv.products["Potato"] = Product("Potato", 2, "food", None, 2) self.products_list = ["orange", "Banana", "Tako", "Bamba", "Potato"]
def search(self, search_term: str = "", categories: [str] = None, key_words: [str] = None) -> [Product]: if self.store_id == 4 and search_term == "": return [] return [Product("Banana", 2, ["fruit"], ["fruits"], 2)]
def add_product(self, user_name: str, product_name: str, product_price: int, product_categories, key_words: [str], amount): """ Args: user_name:the user who wants to add product, should be a owner or a manager with permission product_name:product name product_price:product price product_categories: key_words: Returns: """ if self.is_owner(user_name) or self.check_permission( user_name, 'update_products'): self.inventory.add_product( product_name, Product(product_name, product_price, product_categories, key_words, amount, self.store_id)) return {'error': False, 'data': "Product has been added"} else: logger.error("%s Don't have this permission", user_name) return {'error': True, 'error_msg': "User don't have permission"}
def test_product_to_json(self): date_str = '04-10-2020' dt = timedelta(days=10) date_object = datetime.strptime(date_str, '%m-%d-%Y') p = Product("Apple", 20, "Food", "Fruits", 10) p.discount.append(Discount(date_object, date_object + dt, 50)) print(Json2obj.product_to_json(p))
def setUp(self) -> None: self.users_manager = UsersManager() date_str = '04-10-2020' dt = timedelta(days=10) date_object = datetime.strptime(date_str, '%m-%d-%Y') self.product_orange = Product("orange", 2, "food", None, 100) self.product_orange.discount.append( VisibleProductDiscount(date_object, date_object + dt, 50)) self.product_apple = Product("apple", 2, "food", None, 100) self.product_apple.discount.append( VisibleProductDiscount(date_object, date_object + dt, 50)) self.product_petunia = Product("petunia", 5, "food", None, 100) self.product_petunia.discount.append( VisibleProductDiscount(date_object, date_object + dt, 50)) self.product_begonia = Product("begonia", 15, "food", None, 100) self.product_begonia.discount.append( VisibleProductDiscount(date_object, date_object + dt, 50))
def test_add_product_two(self): p = Product("Macbook", 25, "Food", "Fruits", 20) # Just checking that the product is not exist self.assertNotIn("Macbook", self.store.inventory.products) # Amitush, you have the permission to add product, use it! self.assertTrue(self.store.add_product("Amit", p.name, p.price, p.categories, p.key_words, p.amount)) # Let's see if you did it well self.assertIn("Macbook", self.store.inventory.products)
def test_buy(self): self.test_add_product_to_store() cart = Cart() cart.baskets = {self.idx - 1: Basket(self.idx - 1)} cart.get_basket(self.idx - 1).add_product(Product(*self.products[-1]), 2) self.assertTrue(self.store_manager.buy(jsonpickle.encode(cart))) cart = Cart() cart.baskets = {self.idx + 1: Basket(self.idx + 1)} cart.get_basket(self.idx + 1).add_product(Product(*self.products[-1]), 2) self.assertFalse(self.store_manager.buy(jsonpickle.encode(cart))) cart = Cart() cart.baskets = {self.idx - 1: Basket(self.idx - 1)} cart.get_basket(self.idx - 1).add_product(Product(*self.products[-1]), 30) self.assertFalse(self.store_manager.buy(jsonpickle.encode(cart)))
def setUp(self) -> None: # baskets = {store_id, basket} self.cart = Cart() date_str = '04-10-2020' dt = timedelta(days=100000) date_object = datetime.strptime(date_str, '%m-%d-%Y') self.product_orange = Product("orange", 2, "food", None, 100) self.product_orange.visible_discount.append( VisibleProductDiscount(date_object, date_object + dt, 50)) self.product_apple = Product("apple", 2, "food", None, 100) self.product_apple.visible_discount.append( VisibleProductDiscount(date_object, date_object + dt, 50)) self.product_petunia = Product("petunia", 5, "food", None, 100) self.product_petunia.visible_discount.append( VisibleProductDiscount(date_object, date_object + dt, 50)) self.product_begonia = Product("begonia", 15, "food", None, 100) self.product_begonia.visible_discount.append( VisibleProductDiscount(date_object, date_object + dt, 50))
def setUp(self) -> None: # 1234 for store id self.basket = Basket(1234) date_str = '04-10-2020' dt = timedelta(days=100000) date_object = datetime.strptime(date_str, '%m-%d-%Y') self.product_orange = Product("orange", 2, "food", None, 100) self.product_orange.discount.append( VisibleProductDiscount(date_object, date_object + dt, 50)) self.product_apple = Product("apple", 2, "food", None, 100) self.product_apple.discount.append( VisibleProductDiscount(date_object, date_object + dt, 50)) self.product_petunia = Product("petunia", 5, "food", None, 100) self.product_petunia.discount.append( VisibleProductDiscount(date_object, date_object + dt, 50)) self.product_begonia = Product("begonia", 15, "food", None, 100) self.product_begonia.discount.append( VisibleProductDiscount(date_object, date_object + dt, 50))
def test_add_purchase_to_store(self): self.test_add_product_to_store() purchase = Purchase( {self.products[-1][0]: (Product(*self.products[-1]), 2)}, "moshe", self.idx - 1, 0) self.assertTrue( self.store_manager.add_purchase_to_store( self.idx - 1, jsonpickle.encode(purchase))) self.assertFalse( self.store_manager.add_purchase_to_store( self.idx + 1, jsonpickle.encode(purchase)))
def commit_discount(self, product_price_dict: dict): total_basket_price = self.basket_total_price(product_price_dict) if self.start < datetime.today( ) < self.end and total_basket_price >= self.min_price: to_add_discount = "Store Discount" + str(self.id) price = self.calculate_conditional_discount(total_basket_price) discount_as_product = Product(to_add_discount, (-price), "none", "none", 1) new_product_tup = (discount_as_product, 1, price, price) product_price_dict[to_add_discount] = new_product_tup x = 5
def init_product(self): return { "Apple": Product("Apple", 20, ["Food"], ["Fruits"], 30), "Banana": Product("Banana", 20, ["Food"], ["Fruits"], 10), "Orange": Product("Orange", 20, ["Food"], ["Fruits"], 10), "Tomato": Product("Tomato", 20, ["Food"], ["Vegetables"], 10), "Cucumber": Product("Cucumber", 20, ["Food"], ["Vegetables"], 10), "Carrot": Product("Carrot", 20, ["Food"], ["Vegetables"], 10), "Iphone": Product("Iphone", 20, ["Electronics"], ["Computers"], 10), "Hard Disk": Product("Hard Disk", 20, ["Electronics"], ["Computers"], 10), "Keyboard": Product("Keyboard", 20, ["Electronics"], ["Computers"], 10) }
def test_view_purchases_admin(self): reg_lielle = RegisteredUser("lielle") self.users_mng.reg_user_list["lielle"] = reg_lielle product_orange = Product("orange", 2, "food", None, 100) purchase = Purchase([product_orange], "lielle", 1234, 1) reg_lielle.purchase_history.append(purchase) purch = [purchase] x = jsonpickle.decode( self.users_mng.view_purchases_admin("lielle", "admin")) self.assertEqual(x[0].purchase_id, purch[0].purchase_id) y = self.users_mng.view_purchases_admin("lielle", "not_admin") self.assertFalse(y) self.users_mng.reg_user_list.pop("lielle")
def setUp(self): self.store = Store(0, "test store", "test owner") self.store.store_managers = {"Moshe": [], "Amit": [Store.add_product], "Hadar": [], "Lielle": [Store.remove_product], "Noa": [Store.add_discount_to_product], "Evgeny": [Store.update_product]} self.standard_users = ["Avishay", "Alex", "Ron"] self.store.inventory.products = {"Apple": Product("Apple", 20, ["Food"], ["Fruits"], 10), "Banana": Product("Banana", 20, ["Food"], ["Fruits"], 10), "Orange": Product("Orange", 20, ["Food"], ["Fruits"], 10), "Tomato": Product("Tomato", 20, ["Food"], ["Vegetables"], 10), "Cucumber": Product("Cucumber", 20, ["Food"], ["Vegetables"], 10), "Carrot": Product("Carrot", 20, ["Food"], ["Vegetables"], 10), "Iphone": Product("Iphone", 20, ["Electronics"], ["Computers"], 10), "Hard Disk": Product("Hard Disk", 20, ["Electronics"], ["Computers"], 10), "Keyboard": Product("Keyboard", 20, ["Electronics"], ["Computers"], 10)} self.discount = VisibleProductDiscount(datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), 10) self.new_discount = ConditionalProductDiscount(datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), 10, [])
def test_view_purchases(self): # #24 reg_lielle = RegisteredUser("lielle") self.users_mng.reg_user_list["lielle"] = reg_lielle product_orange = Product("orange", 2, "food", None, 100) purchase = Purchase([product_orange], "lielle", 1234, 1) reg_lielle.purchase_history.append(purchase) purch = [purchase] x = jsonpickle.decode(self.users_mng.view_purchases("lielle")) self.assertEqual(x[0].purchase_id, purch[0].purchase_id) user = User("guestUser1212") self.users_mng.guest_user_list[user.username] = user user.purchase_history.append(purchase) self.assertEqual( jsonpickle.decode( self.users_mng.view_purchases("guestUser1212"))[0].purchase_id, purch[0].purchase_id) self.users_mng.reg_user_list.pop("lielle")
def add_product(self, user_name: str, product_name: str, product_price: int, product_categories, key_words: [str], amount) -> bool: """ Args: user_name:the user who wants to add product, should be a owner or a manager with permission product_name:product name product_price:product price product_categories: key_words: Returns: """ if self.check_permission(user_name, getattr(Store, "add_product")): self.inventory.add_product(product_name, Product(product_name, product_price, product_categories, key_words, amount)) return True else: logger.error("%s Don't have this permission", user_name) return False
def test_update_product(self): self.test_add_product_to_store() # check regular update for attribute, value in Product(self.products[-1][0], 20, ["not so expensive now"], ["electronics"], 1).__dict__.items(): if attribute != "discount": self.assertTrue( self.store_manager.update_product( self.idx - 1, "moshe" + str(self.idx - 1), self.products[-1][0], attribute, value)) self.assertEqual( self.store_manager.stores.get( self.idx - 1).inventory.products.get( self.products[-1][0]).__getattribute__(attribute), value) # update without permissions self.assertFalse( self.store_manager.update_product(self.idx - 1, "not moshe", self.products[-1][0], "price", 73))
def setUp(self) -> None: self.users_manager = UsersManager() date_str = '04-10-2020' dt = timedelta(days=10) date_object = datetime.datetime(2020, 4, 10) self.product_orange = Product("orange", 2, "food", None, 100) self.product_orange.visible_discount.append( VisibleProductDiscount(date_object, date_object + dt, 50)) self.product_apple = Product("apple", 2, "food", None, 100) self.product_apple.visible_discount.append( VisibleProductDiscount(date_object, date_object + dt, 50)) self.product_petunia = Product("petunia", 5, "food", None, 100) self.product_petunia.visible_discount.append( VisibleProductDiscount(date_object, date_object + dt, 50)) self.product_begonia = Product("begonia", 15, "food", None, 100) self.product_begonia.visible_discount.append( VisibleProductDiscount(date_object, date_object + dt, 50)) ############################################### self.store_manager = StoresManager() self.guest_user = self.users_manager.add_guest_user() self.idx = 0 self.store_id1 = self.users_manager.store_manager.open_store( "test store1", "test owner1") self.store_id2 = self.users_manager.store_manager.open_store( "test store2", "test owner2") self.store_id3 = self.users_manager.store_manager.open_store( "test store3", "test owner3") self.store_id4 = self.users_manager.store_manager.open_store( "test store4", "test owner4") self.products = { "Apple": Product("Apple", 20, ["Food"], ["Fruits"], 10), "Banana": Product("Banana", 20, ["Food"], ["Fruits"], 10), "Orange": Product("Orange", 20, ["Food"], ["Fruits"], 10), "Tomato": Product("Tomato", 20, ["Food"], ["Vegetables"], 10), "Cucumber": Product("Cucumber", 20, ["Food"], ["Vegetables"], 10), "Carrot": Product("Carrot", 20, ["Food"], ["Vegetables"], 10), "Iphone": Product("Iphone", 20, ["Electronics"], ["Computers"], 10), "Hard Disk": Product("Hard Disk", 20, ["Electronics"], ["Computers"], 10), "Keyboard": Product("Keyboard", 20, ["Electronics"], ["Computers"], 10) } self.users_manager.store_manager.get_store( self.store_id1).inventory.products = self.products self.users_manager.store_manager.get_store( self.store_id2).inventory.products = self.products self.users_manager.store_manager.get_store( self.store_id3).inventory.products = self.products self.users_manager.store_manager.get_store( self.store_id4).inventory.products = self.products self.discount = VisibleProductDiscount(datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), 10) self.discount1 = VisibleProductDiscount(datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), 30) self.users_manager.store_manager.get_store( self.store_id1).discounts[self.discount.id] = self.discount self.users_manager.store_manager.get_store( self.store_id1).discounts[self.discount1.id] = self.discount1 self.users_manager.store_manager.get_store( self.store_id2).discounts[self.discount.id] = self.discount self.users_manager.store_manager.get_store( self.store_id3).discounts[self.discount1.id] = self.discount1 self.discount.products_in_discount[ "Apple"] = self.users_manager.store_manager.get_store( self.store_id1).inventory.products["Apple"] self.discount.products_in_discount[ "Tomato"] = self.users_manager.store_manager.get_store( self.store_id1).inventory.products["Tomato"] self.discount1.products_in_discount[ "Apple"] = self.users_manager.store_manager.get_store( self.store_id1).inventory.products["Apple"] self.discount.products_in_discount[ "Carrot"] = self.users_manager.store_manager.get_store( self.store_id1).inventory.products["Carrot"] self.discount.products_in_discount[ "Keyboard"] = self.users_manager.store_manager.get_store( self.store_id1).inventory.products["Keyboard"] self.discount.products_in_discount[ "Apple"] = self.users_manager.store_manager.get_store( self.store_id2).inventory.products["Apple"] self.discount.products_in_discount[ "Tomato"] = self.users_manager.store_manager.get_store( self.store_id2).inventory.products["Tomato"] self.discount.products_in_discount[ "Carrot"] = self.users_manager.store_manager.get_store( self.store_id2).inventory.products["Carrot"] self.discount.products_in_discount[ "Keyboard"] = self.users_manager.store_manager.get_store( self.store_id2).inventory.products["Keyboard"] self.discount.products_in_discount[ "Apple"] = self.users_manager.store_manager.get_store( self.store_id3).inventory.products["Apple"] self.discount.products_in_discount[ "Tomato"] = self.users_manager.store_manager.get_store( self.store_id3).inventory.products["Tomato"] self.discount1.products_in_discount[ "Apple"] = self.users_manager.store_manager.get_store( self.store_id3).inventory.products["Apple"] self.discount.products_in_discount[ "Carrot"] = self.users_manager.store_manager.get_store( self.store_id3).inventory.products["Carrot"] self.discount.products_in_discount[ "Keyboard"] = self.users_manager.store_manager.get_store( self.store_id3).inventory.products["Keyboard"] self.basket1 = Basket( self.users_manager.store_manager.get_store( self.store_id1).store_id) self.basket2 = Basket( self.users_manager.store_manager.get_store( self.store_id2).store_id) self.basket3 = Basket( self.users_manager.store_manager.get_store( self.store_id3).store_id) self.basket1.products["Apple"] = ( self.users_manager.store_manager.get_store( self.store_id1).inventory.products["Apple"], 10) self.basket1.products["Keyboard"] = ( self.users_manager.store_manager.get_store( self.store_id1).inventory.products["Keyboard"], 5) self.basket1.products["Carrot"] = ( self.users_manager.store_manager.get_store( self.store_id1).inventory.products["Carrot"], 1) self.basket2.products["Apple"] = ( self.users_manager.store_manager.get_store( self.store_id2).inventory.products["Apple"], 3) self.basket2.products["Keyboard"] = ( self.users_manager.store_manager.get_store( self.store_id2).inventory.products["Keyboard"], 7) self.basket2.products["Carrot"] = ( self.users_manager.store_manager.get_store( self.store_id2).inventory.products["Carrot"], 5) self.basket3.products["Apple"] = ( self.users_manager.store_manager.get_store( self.store_id3).inventory.products["Apple"], 5) self.basket3.products["Keyboard"] = ( self.users_manager.store_manager.get_store( self.store_id3).inventory.products["Keyboard"], 5) self.basket3.products["Carrot"] = ( self.users_manager.store_manager.get_store( self.store_id3).inventory.products["Carrot"], 2) self.cart = self.users_manager.get_cart(self.guest_user) self.cart.baskets[self.store_id1] = self.basket1 self.cart.baskets[self.store_id2] = self.basket2 self.cart.baskets[self.store_id3] = self.basket3
def setUp(self): self.store = Store(0, "test store", "test owner") self.store.store_managers = { "Moshe": [], "Amit": [Store.add_product], "Hadar": [], "Lielle": [Store.remove_product], "Noa": [Store.add_visible_product_discount], "Evgeny": [Store.update_product] } self.standard_users = ["Avishay", "Alex", "Ron"] self.store.inventory.products = { "Apple": Product("Apple", 20, ["Food"], ["Fruits"], 30), "Banana": Product("Banana", 20, ["Food"], ["Fruits"], 10), "Orange": Product("Orange", 20, ["Food"], ["Fruits"], 10), "Tomato": Product("Tomato", 20, ["Food"], ["Vegetables"], 10), "Cucumber": Product("Cucumber", 20, ["Food"], ["Vegetables"], 10), "Carrot": Product("Carrot", 20, ["Food"], ["Vegetables"], 10), "Iphone": Product("Iphone", 20, ["Electronics"], ["Computers"], 10), "Hard Disk": Product("Hard Disk", 20, ["Electronics"], ["Computers"], 10), "Keyboard": Product("Keyboard", 20, ["Electronics"], ["Computers"], 10) } self.discount = VisibleProductDiscount(datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), 5) self.discount1 = VisibleProductDiscount(datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), 5) self.discount2 = ConditionalProductDiscount( datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), 5, 2, 2) self.discount3 = ConditionalProductDiscount( datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), 5, 7, 1) self.discount4 = ConditionalProductDiscount( datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), 5, 6, 3) self.discount5 = ConditionalProductDiscount( datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), 100, 3, 1) self.tup_disc_prod_name_list = [] self.tup_disc_prod_name_list.append( (self.discount3, ["Apple", "Carrot", "Keyboard"])) self.tup_disc_prod_name_list.append( (self.discount4, ["Apple", "Tomato"])) self.discount9 = VisibleProductDiscount(datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), 30) self.discount6 = CompositeDiscount(datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), LogicOperator.AND, self.tup_disc_prod_name_list, [self.discount, self.discount9]) self.discount7 = CompositeDiscount(datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), LogicOperator.OR, self.tup_disc_prod_name_list, [self.discount, self.discount9]) self.discount8 = CompositeDiscount(datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), LogicOperator.XOR, self.tup_disc_prod_name_list, [self.discount, self.discount9]) # self.store.discounts[0] = self.discount # self.store.discounts[1] = self.discount1 # self.store.discounts[2] = self.discount2 # self.store.discounts[3] = self.discount3 # self.store.discounts[4] = self.discount4 # self.store.discounts[5] = self.discount5 # self.store.discounts[6] = self.discount6 # self.store.discounts[7] = self.discount7 # self.store.discounts[8] = self.discount8 self.discount.products_in_discount[ "Apple"] = self.store.inventory.products["Apple"] self.discount.products_in_discount[ "Tomato"] = self.store.inventory.products["Tomato"] self.discount.products_in_discount[ "Carrot"] = self.store.inventory.products["Carrot"] self.discount.products_in_discount[ "Keyboard"] = self.store.inventory.products["Keyboard"] self.discount.products_in_discount[ "Hard Disk"] = self.store.inventory.products["Hard Disk"] self.discount1.products_in_discount[ "Apple"] = self.store.inventory.products["Apple"] self.discount2.products_in_discount[ "Orange"] = self.store.inventory.products["Orange"] self.discount3.products_in_discount[ "Apple"] = self.store.inventory.products["Apple"] self.discount3.products_in_discount[ "Carrot"] = self.store.inventory.products["Carrot"] self.discount3.products_in_discount[ "Keyboard"] = self.store.inventory.products["Keyboard"] self.discount4.products_in_discount[ "Apple"] = self.store.inventory.products["Apple"] self.discount5.products_in_discount[ "Tomato"] = self.store.inventory.products["Tomato"] self.discount5.products_in_discount[ "Hard Disk"] = self.store.inventory.products["Hard Disk"] self.discount6.products_in_discount[ "Iphone"] = self.store.inventory.products["Iphone"] self.discount6.products_in_discount[ "Hard Disk"] = self.store.inventory.products["Hard Disk"] self.discount7.products_in_discount[ "Iphone"] = self.store.inventory.products["Iphone"] self.discount7.products_in_discount[ "Hard Disk"] = self.store.inventory.products["Hard Disk"] self.discount8.products_in_discount[ "Iphone"] = self.store.inventory.products["Iphone"] self.discount8.products_in_discount[ "Hard Disk"] = self.store.inventory.products["Hard Disk"] self.discount9.products_in_discount[ "Hard Disk"] = self.store.inventory.products["Hard Disk"] self.basket = Basket(self.store.store_id) self.basket.products["Apple"] = ( self.store.inventory.products["Apple"], 10) self.basket.products["Keyboard"] = ( self.store.inventory.products["Keyboard"], 5) self.basket.products["Carrot"] = ( self.store.inventory.products["Carrot"], 1) self.basket.products["Orange"] = ( self.store.inventory.products["Orange"], 3) self.basket.products["Tomato"] = ( self.store.inventory.products["Tomato"], 4) self.basket1 = Basket(self.store.store_id) self.basket1.products["Apple"] = ( self.store.inventory.products["Apple"], 10) self.basket1.products["Keyboard"] = ( self.store.inventory.products["Keyboard"], 10) self.basket1.products["Carrot"] = ( self.store.inventory.products["Carrot"], 10) self.basket1.products["Banana"] = ( self.store.inventory.products["Banana"], 10) self.basket1.products["Orange"] = ( self.store.inventory.products["Orange"], 10) self.basket1.products["Cucumber"] = ( self.store.inventory.products["Cucumber"], 10) self.basket1.products["Iphone"] = ( self.store.inventory.products["Iphone"], 10) self.basket1.products["Hard Disk"] = ( self.store.inventory.products["Hard Disk"], 10) self.basket1.products["Tomato"] = ( self.store.inventory.products["Tomato"], 10)
def test_add_product(self): apple = Product("apple", 1, "food", None, 2) self.inv.add_product(apple.name, Product("apple", 1, "food", None, 2)) inv_apple = self.inv.products.get(apple.name) self.assertTrue(apple == inv_apple)
def setUp(self) -> None: self.user = User("Shem") self.product_orange = Product("orange", 2, "food", None, 100) self.purchase = Purchase([self.product_orange], "Shem", 1234, 1)
def createObject(self): return Product(self.name, self.price, self.categorties, self.key_words, self.amount, self)
def setUp(self): self.inv = Inventory() self.inv.products = {"orange": Product("orange", 2, "food", None, 2)}
def setUp(self) -> None: self.store_manager = StoresManager() self.idx = 0 self.store_id = self.store_manager.open_store("test store", "test owner") self.products = [("t-shirt", 20, ["cloth"], ["green"], 7), ("apple", 1, ["food", "green"], ["vegetable"], 10), ("orange", 1, ["food", "orange"], ["fruits"], 10), ("iphone", 5000, ["electronics", "bad and expensive phone "], ["fruits"], 10)] self.store_manager.get_store(self.store_id).inventory.products = { "Apple": Product("Apple", 20, ["Food"], ["Fruits"], 10), "Banana": Product("Banana", 20, ["Food"], ["Fruits"], 10), "Orange": Product("Orange", 20, ["Food"], ["Fruits"], 10), "Tomato": Product("Tomato", 20, ["Food"], ["Vegetables"], 10), "Cucumber": Product("Cucumber", 20, ["Food"], ["Vegetables"], 10), "Carrot": Product("Carrot", 20, ["Food"], ["Vegetables"], 10), "Iphone": Product("Iphone", 20, ["Electronics"], ["Computers"], 10), "Hard Disk": Product("Hard Disk", 20, ["Electronics"], ["Computers"], 10), "Keyboard": Product("Keyboard", 20, ["Electronics"], ["Computers"], 10) } self.discount = VisibleProductDiscount(datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), 10) self.discount1 = VisibleProductDiscount(datetime.datetime(2018, 6, 1), datetime.datetime(2020, 5, 17), 30) self.purchase_store = PurchaseStorePolicy(0, 10, 2) self.purchase_store1 = PurchaseStorePolicy(9, 10, 3) self.purchase = PurchaseProductPolicy(0, 5, 0) self.purchase1 = PurchaseProductPolicy(3, 6, 1) self.store_manager.get_store(self.store_id).purchase_policies[ self.purchase_store.id] = self.purchase_store self.store_manager.get_store(self.store_id).purchase_policies[ self.purchase_store1.id] = self.purchase_store1 self.store_manager.get_store( self.store_id).purchase_policies[self.purchase.id] = self.purchase self.store_manager.get_store(self.store_id).purchase_policies[ self.purchase1.id] = self.purchase1 self.store_manager.get_store( self.store_id).discounts[self.discount.id] = self.discount self.store_manager.get_store( self.store_id).discounts[self.discount1.id] = self.discount1 self.purchase.products_in_policy[ "Apple"] = self.store_manager.get_store( self.store_id).inventory.products["Apple"] self.purchase1.products_in_policy[ "Iphone"] = self.store_manager.get_store( self.store_id).inventory.products["Iphone"] self.discount.products_in_discount[ "Apple"] = self.store_manager.get_store( self.store_id).inventory.products["Apple"] self.discount.products_in_discount[ "Tomato"] = self.store_manager.get_store( self.store_id).inventory.products["Tomato"] self.discount1.products_in_discount[ "Apple"] = self.store_manager.get_store( self.store_id).inventory.products["Apple"] self.discount.products_in_discount[ "Carrot"] = self.store_manager.get_store( self.store_id).inventory.products["Carrot"] self.discount.products_in_discount[ "Keyboard"] = self.store_manager.get_store( self.store_id).inventory.products["Keyboard"] self.basket_legal_pruchace = Basket( self.store_manager.get_store(self.store_id).store_id) self.basket_ilegal_pruchace = Basket( self.store_manager.get_store(self.store_id).store_id) self.basket_some_legal_pruchace = Basket( self.store_manager.get_store(self.store_id).store_id) self.basket_legal_pruchace.products["Apple"] = ( self.store_manager.get_store( self.store_id).inventory.products["Apple"], 5) self.basket_legal_pruchace.products["Iphone"] = ( self.store_manager.get_store( self.store_id).inventory.products["Iphone"], 5) self.basket_ilegal_pruchace.products["Apple"] = ( self.store_manager.get_store( self.store_id).inventory.products["Apple"], 6) self.basket_ilegal_pruchace.products["Iphone"] = ( self.store_manager.get_store( self.store_id).inventory.products["Iphone"], 2) self.basket_some_legal_pruchace.products["Apple"] = ( self.store_manager.get_store( self.store_id).inventory.products["Apple"], 4) self.basket_some_legal_pruchace.products["Iphone"] = ( self.store_manager.get_store( self.store_id).inventory.products["Iphone"], 2) self.basket = Basket( self.store_manager.get_store(self.store_id).store_id) self.basket.products["Apple"] = (self.store_manager.get_store( self.store_id).inventory.products["Apple"], 10) self.basket.products["Keyboard"] = (self.store_manager.get_store( self.store_id).inventory.products["Keyboard"], 5) self.basket.products["Carrot"] = (self.store_manager.get_store( self.store_id).inventory.products["Carrot"], 1)