Beispiel #1
0
    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_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)
Beispiel #3
0
 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 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)
Beispiel #5
0
 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")
Beispiel #6
0
 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")
Beispiel #7
0
 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_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)