def test_2(self): """ """ # arrange print(hex(id(self.clientele))) clients = self.clientele.client_list print(hex(id(clients))) store1 = Store() store2 = Store() store1.google_placeid = '99fb064f2e56c0acd9cbecca555518d638c7dbb2' # act clients.append(store1) clients.append(store2) original_length = len(self.clientele.client_list) self.clientele.eliminate_duplicates() updated_length = len(self.clientele.client_list) # assert self.assertLess(updated_length, original_length, 'empty placeid removal failed')
def test_1(self): """ """ # arrange print(hex(id(self.clientele))) clients = self.clientele.client_list print(hex(id(clients))) store1 = Store() store2 = Store() store3 = Store() store2.google_placeid = store1.google_placeid = 'ChIJawlhKwWbm1QR6vt0assdQKw' store3.google_placeid = '99fb064f2e56c0acd9cbecca555518d638c7dbb2' # act clients.append(store1) clients.append(store2) clients.append(store3) original_length = len(self.clientele.client_list) self.clientele.eliminate_duplicates() updated_length = len(self.clientele.client_list) # assert self.assertLess(updated_length, original_length, 'duplicate removal failed')
def test_add_new_product(self): s1 = Store("my store", 0, 123213, None, None) s1.store_number = 0 Ecommerce.get_instance().stores = [s1] Ecommerce.get_instance().add_new_product(0, 'france schnitzel', 35, 'schnitzel', ['hot', 'crispy']) self.assertEqual(len(s1.products), 1) Ecommerce.get_instance().add_new_product(0, 'italian schnitzel', 35, 'hotSchnitzel', []) self.assertEqual(len(s1.products), 2)
def test_search_product(self): #ok store1 = Store("ramiLevi", 0, "123123", None, None) store1.store_number = 0 product1 = Product('Apple', 'Fruits', ['Food', 'Fruit', 'Apple'], 5) product1.catalog_number = 0 store1.add_new_product(product1) Ecommerce.get_instance().stores = [store1] self.assertEqual(len(User.search_product("name", "Apple").val), 1, 'bad')
def setUp(self): self.store = Store('schnitzale', 23444, 4, None, None) self.store.store_number = 0 self.productA = Product('france schnitzel', 'schnitzel', ['hot', 'crispy'], 35) self.productB = Product('italian schnitzel', 'hotSchnitzel', ['hot', 'sweet'], 35) self.productA.catalog_number = 0 self.productB.catalog_number = 1
def test_add_new_product(self): #ok user1 = User("amir", 2) user1.identifier = 0 store1 = Store("ramiLevi", 0, "123123", None, None) store1.supervisor = 1 Ecommerce.get_instance().stores = [store1] user1.state = State.STORE_OWNER self.assertTrue( user1.add_new_product(0, "chocholate", 5, "Food", ['Food', 'Sweet']), "need return True")
def test_inc_product_amount(self): s1 = Store("my store", 1, 123213, None, None) s1.store_number = 0 Ecommerce.get_instance().stores = [s1] Ecommerce.get_instance().add_new_product(0, 'france schnitzel', 35, 'schnitzel', ['hot', 'crispy']) Ecommerce.get_instance().inc_product_amount(0, 0, 70) for p in s1.products: if p['product'].catalog_number == 0: self.assertEqual(p['amount'], 70)
def test_remove_product(self): #ok user1 = User("amir", 12) user1.identifier = 0 store1 = Store("mega", 0, "456456", None, None) store1.store_number = 1 product1 = Product('chocholate', 'Food', ['Food', 'Sweet'], 10) product1.catalog_number = 1 store1.add_new_product(product1) Ecommerce.get_instance().stores = [store1] user1.state = State.GUEST self.assertFalse(user1.remove_product(1, 1).val, "need return False") user1.state = State.STORE_OWNER self.assertTrue(user1.remove_product(1, 1), "need return True") self.assertFalse(user1.remove_product(1, 10).val, "need return False")
def add_client(self, client_dict): try: client = Store(client_dict) self.client_list.append(client) except Exception as e: print(str(e)) logging.error(e)
def __init__(self, controller): self.__controller = controller self.store = Store() self.student = Student(model=self, controller=self.__controller) self.activity = Activity(controller=self.__controller, store=self.store)
def uniq(lst): last = Store() for item in lst: if item == last: continue yield item last = item
def test_remove_cart(self): basket = ShoppingBasket() discount_service = DiscountService() buying_policy = BuyingPolicyService() store = Store('effect', 123, 123, discount_service, buying_policy) cart = ShoppingCart(store) basket.shopping_carts.append(cart) basket.remove_cart(cart) self.assertEqual(basket.shopping_carts, [])
def test_contains_cart(self): basket = ShoppingBasket() discount_service = DiscountService() buying_policy = BuyingPolicyService() store = Store('effect', 123, 123, discount_service, buying_policy) cart = ShoppingCart(store) self.assertFalse(basket.contains_cart(cart)) basket.shopping_carts.append(cart) self.assertTrue(basket.contains_cart(cart))
def segundo_init(self): self.store = Store() self.aluno = Aluno(model=self) self.grupo = Grupo(model=self) self.atividade = Atividade(model=self) self.sobre = Sobre(model=self) self.apresentacao = Apresentacao(model=self)
def __init__(self): self.store = Store() self.aluno = Aluno() self.grupo = Grupo() self.atividade = Atividade() self.evento = Evento() self.tarefa = Tarefa() self.apresentacao = Apresentacao()
def test_inc_product_amount(self): #ok user1 = User("amir", 13) user1.identifier = 0 store1 = Store("ramiLevi", 0, "123123", None, None) store1.store_number = 0 product1 = Product('Banana', 'Fruits', ['Food', 'Fruit', 'Apple'], 5) product1.catalog_number = 0 store1.add_new_product(product1) Ecommerce.get_instance().stores = [store1] user1.state = State.GUEST self.assertFalse( user1.inc_product_amount(0, 0, 3).val, "need return False") user1.state = State.STORE_OWNER self.assertTrue( user1.inc_product_amount(0, 0, 3).val, "need return True") self.assertFalse( user1.inc_product_amount(100, 0, 3).val, "need return False") self.assertFalse( user1.inc_product_amount(0, 10, 3).val, "need return False")
def test_add_product_to_cart(self): basket = ShoppingBasket() discount_service = DiscountService() buying_policy = BuyingPolicyService() store = Store('effect', 123, 123, discount_service, buying_policy) product_a = Product('france schnitzel', 'schnitzel', ['hot', 'crispy'], 35) self.assertFalse((basket.add_product_to_cart(product_a, store)).val) store.add_new_product(product_a) self.assertFalse((basket.add_product_to_cart(product_a, store)).val) store.inc_product_amount(product_a.catalog_number, 5) self.assertTrue((basket.add_product_to_cart(product_a, store)).val) self.assertEqual(len(basket.shopping_carts), 1) product_b = Product('israeli schnitzel', 'schnitzel', ['hot', 'casher'], 15) store.add_new_product(product_b) store.inc_product_amount(product_b.catalog_number, 5) self.assertTrue((basket.add_product_to_cart(product_b, store)).val) self.assertEqual(len(basket.shopping_carts), 1) self.assertEqual(len(basket.shopping_carts[0].products), 2)
def test_execute_transaction(self): discount_service = DiscountService() buying_policy = BuyingPolicyService() store = Store('effect', 123, 123, discount_service, buying_policy) cart = ShoppingCart(store) product_a = Product('france schnitzel', 'schnitzel', ['hot', 'krispy'], 35) cart.add_product(product_a) delivery_address = DeliveryAddress(123, 'Israel') store.add_new_product(product_a) store.inc_product_amount(product_a.catalog_number, 5) trans = (self.transaction_management.execute_transaction( 123, cart, 'paypal', ['ofek', '4580160114431651', '7', '20', '458'], delivery_address, 123)).val self.assertEqual(trans.total_price, 35) self.assertEqual(trans.buyer_identifier, 123) self.assertEqual(trans.products[product_a.catalog_number]['product'], product_a) self.assertEqual(trans.store_number, store.store_number) self.assertEqual(trans.store_account, store.account_number) self.assertEqual(len(self.transaction_management.get_transactions()), 1) product_b = Product('israeli schnitzel', 'schnitzel', ['hot', 'casher'], 15) store.add_new_product(product_b) store.inc_product_amount(product_b.catalog_number, 5) cart.add_product(product_b) trans = (self.transaction_management.execute_transaction( 12, cart, 'paypal', ['ofek', '4580160114431651', '7', '20', '458'], delivery_address, 123)).val self.assertEqual(trans.total_price, 50) self.assertEqual(trans.buyer_identifier, 12) self.assertEqual(trans.products[product_a.catalog_number]['product'], product_a) self.assertEqual(trans.products[product_b.catalog_number]['product'], product_b) self.assertEqual(trans.store_number, store.store_number) self.assertEqual(trans.store_account, store.account_number) self.assertEqual(len(self.transaction_management.get_transactions()), 2)
def test_change_details_of_product(self): user1 = User("amir", 1) user1.identifier = 0 user1.username = "******" user1.password = "******" user1.state = State.STORE_OWNER user1.is_logged_in = True store1 = Store("mega", 1, "123123", None, None) store1.store_number = 1 product1 = Product('chocholate', 'Food', ['Food', 'Sweet'], 10) product1.catalog_number = 1 store1.owners = [0] store1.add_new_product(product1) Ecommerce.get_instance().subscribers = [user1] Ecommerce.get_instance().stores = [store1] self.assertTrue( user1.change_details_of_product(1, "name", "whiteChocholate").val, "need return True") self.assertFalse( user1.change_details_of_product(2, "name", "whiteChocholate").val, "need return False")
def test_remove_product_from_cart(self): basket = ShoppingBasket() discount_service = DiscountService() buying_policy = BuyingPolicyService() store = Store('effect', 123, 123, discount_service, buying_policy) product = Product('france schnitzel', 'schnitzel', ['hot', 'crispy'], 35) cart = ShoppingCart(store) self.assertFalse((basket.remove_product_from_cart(product, cart)).val) basket.shopping_carts.append(cart) self.assertFalse((basket.remove_product_from_cart(product, cart)).val) cart.add_product(product) self.assertTrue((basket.remove_product_from_cart(product, cart)).val)
def test_check_conditional_discount(self): discount = DiscountService() mango = Product('mango', 'fruit', ['yellow', 'sweet'], 7) pear = Product('pear', 'fruit', ['green', 'sweet'], 4) shopping_cart = ShoppingCart(Store('effect', 123, 123, None, None)) shopping_cart.add_product(mango) self.assertFalse( discount.check_conditional_discount(('And', pear, mango), shopping_cart)) shopping_cart.add_product(pear) self.assertTrue( discount.check_conditional_discount(('And', pear, mango), shopping_cart))
def test_calculate_price(self): discount_service = DiscountService() buying_policy = BuyingPolicyService() store = Store('schnitzale', 23444, 4, discount_service, buying_policy) cart = ShoppingCart(store) product_a = Product('france schnitzel', 'schnitzel', ['hot', 'crispy'], 35) product_b = Product('israeli schnitzel', 'schnitzel', ['hot', 'casher'], 15) store.add_new_product(product_a) store.inc_product_amount(product_a.catalog_number, 5) store.add_new_product(product_b) store.inc_product_amount(product_b.catalog_number, 5) cart.products[product_a.catalog_number] = { 'product': product_a, 'amount': 2 } self.assertEqual(cart.calculate_price(), 70) cart.products[product_b.catalog_number] = { 'product': product_b, 'amount': 1 } self.assertEqual(cart.calculate_price(), 85)
def test_calculate_price(self): basket = ShoppingBasket() discount_service = DiscountService() buying_policy = BuyingPolicyService() store = Store('effect', 123, 123, discount_service, buying_policy) cart = ShoppingCart(store) product_a = Product('france schnitzel', 'schnitzel', ['hot', 'crispy'], 35) product_b = Product('israeli schnitzel', 'schnitzel', ['hot', 'casher'], 15) cart.add_product(product_a) basket.shopping_carts.append(cart) self.assertEqual(basket.calculate_price(), 35) cart.add_product(product_b) self.assertEqual(basket.calculate_price(), 50)
def test_add_to_cart(self): #ok user1 = User("amir", 12) product1 = Product('chocholate', 'Food', ['Food', 'Sweet'], 10) product1.catalog_number = 1 store1 = Store("ramiLevi", 0, "123123", None, None) store1.add_new_product(product1) Ecommerce.get_instance().stores = [store1] store1.inc_product_amount(1, 5) self.assertTrue(user1.add_to_cart(1).val, "need return True") self.assertFalse(user1.add_to_cart(9).val, "need return False")
def test_remove_from_cart(self): #ok user1 = User("amir", 32) user1.identifier = 1 user1.state = State.STORE_OWNER product1 = Product('chocholate', 'Food', ['Food', 'Sweet'], 10) product1.catalog_number = 1 store1 = Store("ramiLevi", 0, "123123", None, None) store1.store_number = 0 store1.supervisor = 1 store1.add_new_product(product1) store1.owners = [user1.identifier] Ecommerce.get_instance().stores = [store1] self.assertTrue(user1.remove_product(0, 1).val, "need return True") self.assertFalse(user1.remove_product(0, 1).val, "need return False")
def test_calculate_individual_discount(self): discount = DiscountService() apple = Product('apple', 'fruit', ['green', 'sweet'], 5) shopping_cart = ShoppingCart(Store('effect', 123, 123, None, None)) start_date = datetime.datetime(2016, 2, 1, 12, 12, 12, 12) end_date = datetime.datetime(2020, 2, 1, 12, 12, 12, 12) discount.add_product_discount(apple, 20, True, start_date, end_date, coupon_code=123) x = discount.calculate_individual_discount( discount.product_discount_table[apple.catalog_number] ['CouponDiscount'], shopping_cart) self.assertEqual(x[0], 20) self.assertEqual(x[1], 'CouponDiscount')
def test_contains_product(self): store = Store('schnitzale', 23444, 4, None, None) cart = ShoppingCart(store) product = Product('france schnitzel', 'schnitzel', ['hot', 'crispy'], 35) self.assertFalse(cart.contains_product(product)) store.add_new_product(product) store.inc_product_amount(product.catalog_number, 5) cart.products[product.catalog_number] = { 'product': product, 'amount': 1 } self.assertTrue(cart.contains_product(product))
def test_make_purchase(self): user = User('ofek', 18) discount_service = DiscountService() buying_policy = BuyingPolicyService() address = DeliveryAddress(13, 'Israel') store = Store('effect', 123, 123, discount_service, buying_policy) Ecommerce.get_instance().stores.append(store) cart = ShoppingCart(store) product = Product('israeli schnitzel', 'schnitzel', ['hot', 'casher'], 15) store.products.append({'product': product, 'amount': 5}) cart.products[product.catalog_number] = { 'product': product, 'amount': 4 } user.shopping_basket.shopping_carts.append(cart) all_transactions_been_made = user.make_purchase( 'paypal', ['ofek', '4580160114431651', '7', '20', '458'], address) self.assertEqual(len(all_transactions_been_made), 1) self.assertEqual(store.products[0]['amount'], 1)
def test_remove_product_from_cart(self): user = User('Shlomo', 18) user.state = State.SUBSCRIBER store = Store("Fruit Store", 5, 123456, None, None) store.store_number = 0 existing_product = Product('Mexican Schnitzel', 'Schnitzels', ['hot', 'crispy', 'spicy'], 45) non_existing_product = Product('African Schnitzel', 'Schnitzels', ['???'], 567) Ecommerce.get_instance().subscribers = [user] Ecommerce.get_instance().stores = [store] store.add_new_product(existing_product) store.inc_product_amount(existing_product.catalog_number, 5) Ecommerce.get_instance().add_to_cart(user.shopping_basket, existing_product.catalog_number) self.assertFalse((Ecommerce.get_instance().remove_from_cart(user.shopping_basket, non_existing_product.catalog_number)).val) self.assertTrue(user.shopping_basket.shopping_carts[store.store_number].products[existing_product.catalog_number]['product'] == existing_product) self.assertTrue(Ecommerce.get_instance().remove_from_cart(user.shopping_basket, existing_product.catalog_number)) self.assertTrue(len(user.shopping_basket.shopping_carts[store.store_number].products) == 0)
def connect(): id = request.get_json()["id"] player = find_player(id) if player: return { "success": player._userdata.connected, "id": player._userdata.id }, status.HTTP_201_CREATED else: player = mqtt.Client(userdata=Store()) player.on_connect = on_connect player.on_message = on_message player._userdata.set_id(id) player.connect("10.45.3.18", 1883, 60) players.append(player) print(id) print("added") threading.Thread(target=player.loop_forever).start() return { "success": player._userdata.connected, "id": player._userdata.id }, status.HTTP_201_CREATED