Beispiel #1
0
def remove_item_shopping_cart(request):
    if request.method == 'POST':
        item_id = request.POST.get('item_id')
        login = request.COOKIES.get('login_hash')
        if login is not None and Consumer.loggedInUsers.get(login) is None:
            status = UserShoppingCartLogic.remove_item_shopping_cart(
                login, item_id)
        else:
            guest = request.COOKIES.get('guest_hash')
            if guest is None:
                return HttpResponse('fail')
            status = GuestShoppingCartLogic.remove_item_shopping_cart_guest(
                guest, item_id)
        if status is False:
            return HttpResponse('fail')
        else:
            return HttpResponse('OK')
Beispiel #2
0
    def test_torture3(self):
        # Adding Users
        status = UsersLogic.register(
            RegisteredUser('u1ser1u1ser1', 'wxde12exd12'))
        self.assertTrue(status)
        status = UsersLogic.register(RegisteredUser('u2ser2u2ser2',
                                                    '34c124c1'))
        self.assertTrue(status)
        status = UsersLogic.register(
            RegisteredUser('u3ser3u3ser3', '1c241c24c1'))
        self.assertTrue(status)
        status = UsersLogic.register(
            RegisteredUser('u4ser4u4ser4', '3214v132v4132'))
        self.assertTrue(status)
        status = UsersLogic.register(RegisteredUser('u5seru5ser', '12121212'))
        self.assertTrue(status)

        # Adding System Managers
        status = UsersLogic.add_system_manager(
            SystemManager('sys1sys1', 'POWER123'))
        self.assertTrue(status)

        # Creating Shops
        status = ShopLogic.create_shop(Shop('myShop1', 'Active'),
                                       'u1ser1u1ser1')
        self.assertTrue(status)

        status = ShopLogic.create_shop(Shop('myShop2', 'Active'),
                                       'u2ser2u2ser2')
        self.assertTrue(status)

        status = UsersLogic.add_owner('u1ser1u1ser1',
                                      Owner('u3ser3u3ser3', 'myShop1', 0))
        self.assertTrue(status)

        owner = Owners.get_owner('u1ser1u1ser1', 'myShop1')
        status = UsersLogic.add_manager(
            owner.username,
            StoreManager('u4ser4u4ser4', 'myShop1', 1, 1, 1, 1, 1, 1, 1, 1))
        status = UsersLogic.add_manager(
            'u2ser2u2ser2',
            StoreManager('u4ser4u4ser4', 'myShop2', 1, 1, 1, 1, 1, 1, 1, 1))

        ItemsLogic.add_item_to_shop(
            Item(None, 'myShop1', 'banana', 'fruits', 'fruit;healthy;yellow',
                 4.90, 300, 'regular', None, 0, 0, 0), 'u4ser4u4ser4')

        ItemsLogic.add_item_to_shop(
            Item(None, 'myShop2', 'doll', 'toys', 'fun', 30, 10, 'regular',
                 None, 0, 0, 0), 'u2ser2u2ser2')

        ItemsLogic.add_item_to_shop(
            Item(None, 'myShop1', 'soda', 'drinks', 'good', 4.90, 20,
                 'regular', None, 0, 0, 0), 'u1ser1u1ser1')

        ItemsLogic.add_item_to_shop(
            Item(None, 'myShop2', 'cucumber', 'vegetables', 'fun', 4.90, 300,
                 'regular', None, 0, 0, 0), 'u4ser4u4ser4')

        ItemsLogic.add_item_to_shop(
            Item(None, 'myShop1', 'vodka', 'drinks', 'bad;for;your;health', 70,
                 2, 'regular', None, 0, 0, 0), 'u3ser3u3ser3')
        username1 = 'u4ser4u4ser4'
        username2 = 'u2ser2u2ser2'
        username3 = 'u1ser1u1ser1'
        username4 = 'u3ser3u3ser3'
        username5 = 'u5seru5ser'

        access_token1 = hashlib.md5(username1.encode()).hexdigest()
        Consumer.loggedInUsers[access_token1] = username1
        Consumer.loggedInUsersShoppingCart[access_token1] = []

        access_token2 = hashlib.md5(username2.encode()).hexdigest()
        Consumer.loggedInUsers[access_token2] = username2
        Consumer.loggedInUsersShoppingCart[access_token2] = []

        access_token3 = hashlib.md5(username3.encode()).hexdigest()
        Consumer.loggedInUsers[access_token3] = username3
        Consumer.loggedInUsersShoppingCart[access_token3] = []

        access_token4 = hashlib.md5(username4.encode()).hexdigest()
        Consumer.loggedInUsers[access_token4] = username4
        Consumer.loggedInUsersShoppingCart[access_token4] = []

        access_token5 = hashlib.md5(username5.encode()).hexdigest()
        Consumer.loggedInUsers[access_token5] = username5
        Consumer.loggedInUsersShoppingCart[access_token5] = []

        UserShoppingCartLogic.add_item_shopping_cart(
            access_token5, ShoppingCartItem('u5seru5ser', 1, 10, None))
        UserShoppingCartLogic.add_item_shopping_cart(
            access_token5, ShoppingCartItem('u5seru5ser', 2, 5, None))
        UserShoppingCartLogic.add_item_shopping_cart(
            access_token5, ShoppingCartItem('u5seru5ser', 3, 15, None))

        items = UserShoppingCartLogic.get_cart_items(access_token5)
        self.assertEqual(len(items), 3)
        self.assertEqual(items[0].code, None)

        UserShoppingCartLogic.remove_item_shopping_cart(access_token5, 1)
        items = UserShoppingCartLogic.get_cart_items(access_token5)
        self.assertEqual(len(items), 2)

        UserShoppingCartLogic.remove_item_shopping_cart(access_token5, 2)
        items = UserShoppingCartLogic.get_cart_items(access_token5)
        self.assertEqual(len(items), 1)

        # Only item id 3 left

        UserShoppingCartLogic.pay_all(access_token5)
        items1 = UsersLogic.get_purchase_history('u5seru5ser')
        items2 = ItemsLogic.get_all_purchased_items('sys1sys1')
        items3 = ShopLogic.get_shop_purchase_history('u4ser4u4ser4', 'myShop1')
        self.assertEqual(items1[0].item_id, items2[0].item_id)
        self.assertEqual(items2[0].quantity, items3[0].quantity)
        self.assertEqual(items1[0].price, items3[0].price)

        self.assertTrue('Nadav Ha Gever')