コード例 #1
0
ファイル: IntegrationTests.py プロジェクト: omriattiya/uTrade
    def test_policies_torture(self):
        UsersLogic.register(RegisteredUser('ShaharBenS', "SsS0897SsS"))
        UsersLogic.update_details('ShaharBenS', 'AFG', 20, 'Male')

        UsersLogic.register(RegisteredUser('ShaharBenS2', "SsS0897SsS"))
        ShopLogic.create_shop(Shop('eBay', "Active"), 'ShaharBenS2')
        ShopLogic.create_shop(Shop('Amazon', "Active"), 'ShaharBenS2')
        item1 = Item(1, 'eBay', 'apple', 'vegas', 'good', 10, 500, 'regular',
                     None, 0, 0, 0)
        item2 = Item(2, 'Amazon', 'apple', 'fruits', 'good', 10, 500,
                     'regular', None, 0, 0, 0)
        ItemsLogic.add_item_to_shop(item1, 'ShaharBenS2')
        ItemsLogic.add_item_to_shop(item2, 'ShaharBenS2')

        ShoppingPolicyLogic.add_shopping_policy_on_shop(
            'ShaharBenS2', 'eBay', "age = ''20''", "AL", 3)
        ShoppingPolicyLogic.add_shopping_policy_on_shop(
            'ShaharBenS2', 'Amazon', "age > ''15''", "UT", 5)
        ShoppingPolicyLogic.add_shopping_policy_on_identity(
            'Ultimate_ShaharShahar', "sex = ''Male''", "AL", 9)
        ShoppingPolicyLogic.add_shopping_policy_on_category(
            'Ultimate_ShaharShahar', "vegas", "state = ''AFG''", "UT", 5)
        ShoppingPolicyLogic.add_shopping_policy_on_items(
            'Ultimate_ShaharShahar', "apple", "state != ''AFG''", "E", 2)

        access_token = hashlib.md5('ShaharBenS'.encode()).hexdigest()
        Consumer.loggedInUsers[access_token] = 'ShaharBenS'
        Consumer.loggedInUsersShoppingCart[access_token] = []

        UserShoppingCartLogic.add_item_shopping_cart(
            access_token, ShoppingCartItem('ShaharBenS', 2, 3, None))
        UserShoppingCartLogic.add_item_shopping_cart(
            access_token, ShoppingCartItem('ShaharBenS', 1, 7, None))
        status = UserShoppingCartLogic.pay_all(access_token)
        self.assertFalse(StoB(status))
コード例 #2
0
ファイル: ItemsService.py プロジェクト: omriattiya/uTrade
def add_review_on_item(request):
    if request.method == 'POST':
        item_id = request.POST.get('item_id')
        description = request.POST.get('description')
        rank = request.POST.get('rank')

        event = "ADD REVIEW"
        suspect_sql_injection = False
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            item_id, event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            description, event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            rank, event) or suspect_sql_injection
        if suspect_sql_injection:
            return HttpResponse(MESSAGE_SQL_INJECTION)

        login = request.COOKIES.get('login_hash')
        if login is not None:
            writer_name = Consumer.loggedInUsers.get(login)
            old_review = ItemsLogic.get_item_review_with_writer(
                item_id, writer_name)
            if old_review is not False:
                return HttpResponse('has reviews')
            review = ItemReview(writer_name, item_id, description, rank)
            if ItemsLogic.add_review_on_item(review):
                return HttpResponse('success')
        return HttpResponse('fail')
コード例 #3
0
ファイル: ExternalTests.py プロジェクト: omriattiya/uTrade
    def test_supply_system(self):
        UsersLogic.register(RegisteredUser('ShaharBenS', "SsS0897SsS"))
        UsersLogic.update_details('ShaharBenS', 'AFG', 20, 'Male')

        UsersLogic.register(RegisteredUser('ShaharBenS2', "SsS0897SsS"))
        ShopLogic.create_shop(Shop('eBay', "Active"), 'ShaharBenS2')
        ShopLogic.create_shop(Shop('Amazon', "Active"), 'ShaharBenS2')
        item1 = Item(1, 'eBay', 'apple', 'vegas', 'good', 10, 500, 'regular',
                     None, 0, 0, 0)
        item2 = Item(2, 'Amazon', 'apple', 'fruits', 'good', 10, 500,
                     'regular', None, 0, 0, 0)
        ItemsLogic.add_item_to_shop(item1, 'ShaharBenS2')
        ItemsLogic.add_item_to_shop(item2, 'ShaharBenS2')

        access_token = hashlib.md5('ShaharBenS'.encode()).hexdigest()
        Consumer.loggedInUsers[access_token] = 'ShaharBenS'
        Consumer.loggedInUsersShoppingCart[access_token] = []

        UserShoppingCartLogic.add_item_shopping_cart(
            access_token, ShoppingCartItem('ShaharBenS', 2, 3, None))
        UserShoppingCartLogic.add_item_shopping_cart(
            access_token, ShoppingCartItem('ShaharBenS', 1, 7, None))

        ExternalSystems.supply = ProxySupplySystem.ProxySupplySystem()
        status = UserShoppingCartLogic.pay_all(access_token)
        if isinstance(status, list) is not True:
            status = False
        self.assertFalse(status)

        ExternalSystems.supply = SupplySystem.SupplySystem()
        status = UserShoppingCartLogic.pay_all(access_token)
        if isinstance(status, list):
            status = True
        self.assertTrue(status)
コード例 #4
0
ファイル: ItemsService.py プロジェクト: omriattiya/uTrade
def remove_item_from_shop(request):
    if request.method == 'POST':
        login = request.COOKIES.get('login_hash')
        username = None
        if login is not None:
            username = Consumer.loggedInUsers.get(login)
            if username is None:
                return HttpResponse('fail')

        item_id = request.POST.get('item_id')

        item = ItemsLogic.get_item(item_id)
        if item is False:
            return HttpResponse('fail')
        if not UsersLogic.is_owner_of_shop(username, item.shop_name):
            if UsersLogic.is_manager_of_shop(username, item.shop_name):
                manager = UsersLogic.get_manager(username, item.shop_name)
                if manager.permission_remove_item is not 1:  # no permission
                    return HttpResponse('no permission to remove item')
            else:
                return HttpResponse('fail')  # not manager not owner

        status = ItemsLogic.remove_item_from_shop(item_id, username)
        if status is False:
            return HttpResponse('fail')
        return HttpResponse('success')
コード例 #5
0
ファイル: ShoppingLogic.py プロジェクト: omriattiya/uTrade
def check_stock_for_shopping_cart(cart_items):
    for cart_item in cart_items:
        if ItemsLogic.check_in_stock(cart_item.item_id,
                                     cart_item.item_quantity) is False:
            item = ItemsLogic.get_item(cart_item.item_id)
            return 'Only ' + str(
                item.quantity) + ' ' + item.name + ' exist in the system'
    return True
コード例 #6
0
 def test_review_on_item_bad(self):
     register(RegisteredUser('TomerTomer', '1234567878'))
     ItemsLogic.add_item_to_shop(
         Item(1, 'My Shop', 'milk', 'diary', 'good', 12, 100, 'regular',
              None, 0, 0, 0), 'YoniYoni')
     ItemsLogic.add_review_on_item(ItemReview('TomerTomer', 1, 'Good', 10))
     reviews = get_all_reviews_on_item(1)
     self.assertEqual(reviews, [])
コード例 #7
0
    def setUp(self):
        init_database('db.sqlite3')
        UsersLogic.register(RegisteredUser('ShaharBenS', "SsS0897SsS"))
        UsersLogic.update_details('ShaharBenS', 'AFG', 20, 'Male')

        UsersLogic.register(RegisteredUser('ShaharBenS2', "SsS0897SsS"))
        ShopLogic.create_shop(Shop('eBay', "Active"), 'ShaharBenS2')
        item1 = Item(1, 'eBay', 'banana', 'vegas', 'good', 10, 500, 'regular', None, 0, 0, 0)
        ItemsLogic.add_item_to_shop(item1, 'ShaharBenS2')
コード例 #8
0
 def test_bad_quantity_of_item(self):
     item1 = Item(1, 'My Shop', 'milk', 'diary', 'good', 12, -5, 'regular',
                  None, 0, 0, 0)
     item2 = Item(2, 'My Shop', 'steak', 'meat', 'bad', 12, -7, 'regular',
                  None, 0, 0, 0)
     status1 = ItemsLogic.add_item_to_shop(item1, 'StoreManager1')
     status2 = ItemsLogic.add_item_to_shop(item2, 'StoreManager1')
     self.assertFalse(status1)
     self.assertFalse(status2)
コード例 #9
0
 def test_review_on_item_bad_writer(self):
     register(RegisteredUser('TomerTomer', '1234567878'))
     ItemsLogic.add_item_to_shop(
         Item(1, 'My Shop', 'milk', 'diary', 'good', 12, 100, 'regular',
              None, 0, 0, 0), 'YoniYoni')
     purchase_id = add_purchase_and_return_id(datetime.now(), 'TomerTomer',
                                              0)
     PurchasedItems.add_purchased_item(purchase_id, 1, 5, 10)
     ItemsLogic.add_review_on_item(ItemReview('YoniYoni', 1, 'Good', 10))
     self.assertFalse(get_all_reviews_on_item(1))
コード例 #10
0
 def test_bad_man_remove_item_from_shop(self):
     register(RegisteredUser('TomerTomer', '1234567878'))
     shop = search_shop('My Shop')
     item1 = Item(1, 'My Shop', 'milk', 'diary', 'good', 12, 100, 'regular',
                  None, 0, 0, 0)
     ItemsLogic.add_item_to_shop(item1, 'StoreManager1')
     searched_1 = search_item_in_shop(shop.name, item1.name)
     self.assertEqual(searched_1.id, item1.id)
     self.assertFalse(remove_item_from_shop(item1.id, 'TomerTomer'))
     self.assertTrue(search_item_in_shop(shop.name, item1.name))
コード例 #11
0
 def test_bad_shop_less_item_remove_item_from_shop(self):
     shop = search_shop('My Shop')
     item1 = Item(1, 'My Shop', 'milk', 'diary', 'good', 12, 100, 'regular',
                  None, 0, 0, 0)
     item2 = Item(2, 'My Shop', 'steak', 'meat', 'bad', 12, 100, 'regular',
                  None, 0, 0, 0)
     ItemsLogic.add_item_to_shop(item1, 'StoreManager1')
     searched_1 = search_item_in_shop(shop.name, item1.name)
     self.assertEqual(searched_1.id, item1.id)
     self.assertFalse(remove_item_from_shop(item2.id, 'StoreManager1'))
     self.assertTrue(search_item_in_shop(shop.name, item1.name))
コード例 #12
0
 def test_add_item_to_shop(self):
     shop = search_shop('My Shop')
     item1 = Item(1, 'My Shop', 'milk', 'diary', 'good', 12, 100, 'regular',
                  None, 0, 0, 0)
     item2 = Item(2, 'My Shop', 'steak', 'meat', 'bad', 12, 100, 'regular',
                  None, 0, 0, 0)
     ItemsLogic.add_item_to_shop(item1, 'StoreManager1')
     ItemsLogic.add_item_to_shop(item2, 'StoreManager1')
     searched_1 = search_item_in_shop(shop.name, item1.name)
     searched_2 = search_item_in_shop(shop.name, item2.name)
     # condition1 = check_in_stock(item1.id, 100) and check_in_stock(item2.id, 100)
     self.assertEqual(searched_1.id, item1.id)
     self.assertEqual(searched_2.id, item2.id)
コード例 #13
0
ファイル: ItemsService.py プロジェクト: omriattiya/uTrade
def edit_shop_item(request):
    if request.method == 'POST':
        login = request.COOKIES.get('login_hash')
        username = None
        if login is not None:
            username = Consumer.loggedInUsers.get(login)
            if username is None:
                return HttpResponse('fail')
        item_id = request.POST.get('item_id')

        fields = ['quantity', 'category', 'keywords', 'price', 'url']
        new_values = [
            request.POST.get('item_quantity'),
            request.POST.get('item_category'),
            request.POST.get('item_keywords'),
            request.POST.get('item_price'),
            request.POST.get('item_url')
        ]

        event = "EDIT ITEM"
        suspect_sql_injection = False
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            new_values[0], event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            new_values[1], event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            new_values[2], event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            new_values[3], event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            new_values[4], event) or suspect_sql_injection
        if suspect_sql_injection:
            return HttpResponse(MESSAGE_SQL_INJECTION)

        item = ItemsLogic.get_item(item_id)
        if item is False:
            return HttpResponse('fail')
        if not UsersLogic.is_owner_of_shop(username, item.shop_name):
            if UsersLogic.is_manager_of_shop(username, item.shop_name):
                manager = UsersLogic.get_manager(username, item.shop_name)
                if manager.permission_edit_item is not 1:  # no permission
                    return HttpResponse('no permission to edit item')
            else:
                return HttpResponse('fail')  # not manager not owner

        for i in range(0, len(fields)):
            status = ItemsLogic.edit_shop_item(username, item_id, fields[i],
                                               new_values[i])
            if status is False:
                return HttpResponse('fail')
        return HttpResponse('success')
コード例 #14
0
    def setUp(self):
        init_database('db.sqlite3')

        username = '******'
        shop_name = 'My New Shop'
        register(RegisteredUser(username, '12341256'))  # register user
        ShopLogic.create_shop(Shop.Shop(shop_name, 'Active'),
                              username)  # add shop
        ItemsLogic.add_item_to_shop(
            Item.Item(1, shop_name, 'milk', 'milk', 'keywords', 12, 100,
                      'regular', None, 0, 0, 0), username)
        ItemsLogic.add_item_to_shop(
            Item.Item(2, shop_name, 'glue', 'glue', 'keywords', 12, 100,
                      'regular', None, 0, 0, 0), username)
コード例 #15
0
 def test_add_invisible_discount_bad(self):
     register(RegisteredUser('YoniYoni', '1234567878'))
     register(RegisteredUser('StoreManager1', '1234567878'))
     shop = Shop('My Shop', 'Active')
     ShopLogic.create_shop(shop, 'YoniYoni')
     UsersLogic.add_manager(
         'YoniYoni',
         StoreManager('StoreManager1', 'My Shop', 1, 1, 1, 1, 1, 1, 1, 1))
     item1 = Item(1, 'My Shop', 'milk', 'diary', 'good', 12, 100, 'regular',
                  None, 0, 0, 0)
     ItemsLogic.add_item_to_shop(item1, 'StoreManager1')
     invdisc = InvisibleDiscount('ABCDEFGHIJKLMNO', item1.id, shop.name, -1,
                                 '2018-12-01', '2019-12-01')
     self.assertFalse(add_invisible_discount(invdisc, 'YoniYoni'))
コード例 #16
0
 def test_review_on_shop(self):
     register(RegisteredUser('TomerTomer', '1234567878'))
     user = get_user('TomerTomer')
     shop = Shop('My Shop', 'Active')
     ShopLogic.create_shop(shop, 'TomerTomer')
     ItemsLogic.add_item_to_shop(Item(1, 'My Shop', 'milk', 'diary', 'good', 12, 100, 'regular', None, 0, 0, 0),
                                 'TomerTomer')
     purchase_id = add_purchase_and_return_id(datetime.now(), 'TomerTomer', 0)
     status = PurchasedItems.add_purchased_item(purchase_id, 1, 10, 10)
     shop_review = ShopReview('TomerTomer', 'Best', 10, 'My Shop')
     status = ShopLogic.add_review_on_shop(shop_review)
     reviews = get_all_reviews_on_shop('My Shop')
     answer = len(reviews) == 1
     self.assertTrue(answer)
コード例 #17
0
 def test_edit_shop_item(self):
     shop = search_shop('My Shop')
     item1 = Item(1, 'My Shop', 'milk', 'diary', 'good', 12, 100, 'regular',
                  None, 0, 0, 0)
     item2 = Item(2, 'My Shop', 'steak', 'meat', 'bad', 12, 100, 'regular',
                  None, 0, 0, 0)
     ItemsLogic.add_item_to_shop(item1, 'StoreManager1')
     ItemsLogic.add_item_to_shop(item2, 'StoreManager1')
     searched_1 = search_item_in_shop(shop.name, item1.name)
     searched_2 = search_item_in_shop(shop.name, item2.name)
     self.assertEqual(searched_1.id, item1.id)
     self.assertEqual(searched_2.id, item2.id)
     self.assertTrue(edit_shop_item('StoreManager1', item1.id, 'price', 15))
     price = search_item_in_shop(shop.name, item1.name).price
     self.assertEqual(15, price)
コード例 #18
0
def add_item_to_cart(request):
    if request.method == 'POST':
        item_id = int(request.POST.get('item_id'))
        quantity = int(request.POST.get('quantity'))
        item = ItemsLogic.get_item(item_id)
        if item.quantity < quantity:
            return HttpResponse('Stock_Error')
        login = request.COOKIES.get('login_hash')
        if login is None:
            login = request.POST.get('login_hash')
        if login is not None and Consumer.loggedInUsers.get(login) is not None:
            username = Consumer.loggedInUsers.get(login)
            status = UserShoppingCartLogic.add_item_shopping_cart(
                login, ShoppingCartItem(username, item_id, quantity, None))
            if status is False:
                return HttpResponse('fail')
            else:
                return HttpResponse('OK')
        else:
            if item.kind == 'ticket':
                return HttpResponse('guest ticket')
            guest = request.COOKIES.get('guest_hash')
            if guest is None:
                guest = 'guest' + Consumer.guestIndex
                Consumer.guestIndex += 1
            status = GuestShoppingCartLogic.add_guest_item_shopping_cart(
                guest, item_id, quantity)
            if status is False:
                return HttpResponse('fail')
            else:
                string_guest = str(guest)
                return HttpResponse(string_guest)
コード例 #19
0
 def test_bad_no_man_edit_shop_item(self):
     register(RegisteredUser('TomerTomer', '1234567878'))
     shop = search_shop('My Shop')
     item1 = Item(1, 'My Shop', 'milk', 'diary', 'good', 12, 100, 'regular',
                  None, 0, 0, 0)
     item2 = Item(2, 'My Shop', 'steak', 'meat', 'bad', 12, 100, 'regular',
                  None, 0, 0, 0)
     ItemsLogic.add_item_to_shop(item1, 'StoreManager1')
     ItemsLogic.add_item_to_shop(item2, 'StoreManager1')
     searched_1 = search_item_in_shop(shop.name, item1.name)
     searched_2 = search_item_in_shop(shop.name, item2.name)
     self.assertEqual(searched_1.id, item1.id)
     self.assertEqual(searched_2.id, item2.id)
     self.assertFalse(edit_shop_item('TomerTomer', item1.id, 'price', 15))
     price = search_item_in_shop(shop.name, item1.name).price
     self.assertEqual(12, price)
コード例 #20
0
def check_shop_shopping_policies(username, cart_items):
    shop_policies = ShoppingPolicyLogic.get_all_shops_shopping_policies()
    for shop_policy in shop_policies:
        if not (username == "guest"):
            if is_meet_conditions(username, shop_policy.conditions) is False:
                continue
        if shop_policy.restriction == 'N':
            continue
        num_of_items = 0
        relevant = False
        cart_item_shop = None
        for cart_item in cart_items:
            cart_item_shop = ItemsLogic.get_item(cart_item.item_id).shop_name
            if shop_policy.shop_name == cart_item_shop:
                num_of_items = num_of_items + cart_item.item_quantity
                relevant = True
        if shop_policy.restriction == 'AL':
            if relevant and num_of_items < shop_policy.quantity:
                return "FAILED: Not enough " + cart_item_shop + " items in cart; You allowed at least " + str(
                    shop_policy.quantity)
        elif shop_policy.restriction == 'E':
            if relevant and num_of_items != shop_policy.quantity:
                return "FAILED: Not exact num of " + cart_item_shop + " items in cart; You allowed exactly " + str(
                    shop_policy.quantity)
        elif shop_policy.restriction == 'UT':
            if relevant and num_of_items > shop_policy.quantity:
                return "FAILED: Too much " + cart_item_shop + " items in cart; You allowed at most " + str(
                    shop_policy.quantity)
    return True
コード例 #21
0
ファイル: Profile.py プロジェクト: omriattiya/uTrade
def get_order(request):
    if request.method == 'GET':
        login = request.COOKIES.get('login_hash')
        purchase_id = request.GET.get('order_id')

        if login is not None:
            username = Consumer.loggedInUsers.get(login)
            if username is not None:
                items_html = ""
                items = ShoppingLogic.get_purchased_items_by_purchase_id(
                    purchase_id)
                for item in items:
                    full_item = ItemsLogic.get_item(item.item_id)
                    items_html += loader.render_to_string(
                        'components/PurchasedItem.html',
                        context={
                            'item_id': item.item_id,
                            'item_url': full_item.url,
                            'item_name': full_item.name,
                            'item_quantity': item.quantity,
                            'item_price': item.price,
                            'shop_name': full_item.shop_name,
                        })
                date = ShoppingLogic.get_purchase(purchase_id).purchase_date
                context = {
                    'topbar': Topbar_Navbar.get_top_bar(login),
                    'navbar': Topbar_Navbar.get_nav_bar(login, None)
                }
                context.update({
                    'items': items_html,
                    'order_id': purchase_id,
                    'order_date': date
                })
                return render(request, 'customer-order.html', context=context)
        return HttpResponse('You are not logged in!')
コード例 #22
0
ファイル: ShoppingLogic.py プロジェクト: omriattiya/uTrade
def check_category_shopping_policies(username, cart_items):
    category_policies = ShoppingPolicyLogic.get_all_shopping_policy_on_category(
    )
    for category_policy in category_policies:
        if username is not "guest":
            if is_meet_conditions(username,
                                  category_policy.conditions) is False:
                continue
        if category_policy.restriction is 'N':
            continue
        num_of_items = 0
        cart_item_category = None
        for cart_item in cart_items:
            cart_item_category = ItemsLogic.get_item(
                cart_item.item_id).category
            if category_policy.category == cart_item_category:
                num_of_items = num_of_items + cart_item.item_quantity
        if category_policy.restriction is 'AL':
            if num_of_items < category_policy.quantity:
                return "FAILED: Not enough " + cart_item_category + " items in cart; You allowed at least " + category_policy.quantity
        elif category_policy.restriction is 'E':
            if num_of_items != category_policy.quantity:
                return "FAILED: Not exact num of " + cart_item_category + " items in cart; You allowed exactly " + category_policy.quantity
        elif category_policy.restriction is 'UT':
            if num_of_items > category_policy.quantity:
                return "FAILED: Too much " + cart_item_category + " items in cart; You allowed at most " + category_policy.quantity
    return True
コード例 #23
0
ファイル: ItemsService.py プロジェクト: omriattiya/uTrade
def get_id_by_name(request):
    if request.method == 'GET':
        item_name = request.GET.get('item_name')

        id = ItemsLogic.get_id_by_name(item_name)
        print(id)
        return HttpResponse(str(id))
コード例 #24
0
def update_code_shopping_cart(request):
    if request.method == 'POST':
        code = request.POST.get("code")

        event = "UPDATE CODE SHOPPING CART"
        suspect_sql_injection = LoggerLogic.identify_sql_injection(code, event)

        if suspect_sql_injection:
            return HttpResponse(LoggerLogic.MESSAGE_SQL_INJECTION)

        item = ItemsLogic.get_item_by_code(code)
        if item is False:
            return HttpResponse('fail')
        login = request.COOKIES.get('login_hash')
        if login is None or Consumer.loggedInUsers.get(login) is None:
            guest = request.COOKIES.get('guest_hash')
            if guest is None:
                return HttpResponse('fail')
            status = GuestShoppingCartLogic.update_code_shopping_cart_guest(
                guest, item.id, code)
        else:
            status = UserShoppingCartLogic.update_code_shopping_cart(
                login, item.id, code)
        if status is False:
            return HttpResponse('fail')
        else:
            return HttpResponse('OK')
コード例 #25
0
def get_cart_cost(login_token):
    empty = check_empty_cart_user(login_token)
    if empty is not True:
        #  if so, check foreach item if the requested amount exist
        cart_items = get_cart_items(login_token)
        # cart_items is a array consist of shopping_cart objects
        for shopping_cart_item in cart_items:
            if ItemsLogic.check_in_stock(shopping_cart_item.item_id, shopping_cart_item.item_quantity) is False:
                return False
        # if so, sum all items costs, get from costumer his credentials
        total_cost = 0
        # for each item, calculate visible_discount
        for shopping_cart_item in cart_items:
            item = get_item(shopping_cart_item.item_id)
            if shopping_cart_item.item_quantity > item.quantity:
                return False
            new_price = get_new_price_for_item(item, shopping_cart_item)
            lottery = get_lottery(item.id)
            if item.kind == 'ticket':
                final_date = datetime.strptime(lottery.final_date, '%Y-%m-%d')
                if final_date > datetime.now():
                    lottery_sum = get_lottery_sum(lottery.lotto_id)
                    if lottery_sum + shopping_cart_item.item_quantity * item.price > lottery.max_price:
                        return False
                    else:
                        return False
                else:
                    return False
            total_cost = total_cost + shopping_cart_item.item_quantity * new_price
        return total_cost
    return False
コード例 #26
0
ファイル: LotteryLogic.py プロジェクト: omriattiya/uTrade
def add_lottery_and_items(prize, ticket, ticket_price, final_date, username):
    if prize is not None and ticket is not None and ticket_price is not None and final_date is not None and username is not None:
        item_id = ItemsLogic.add_item_to_shop_and_return_id(prize, username)
        lottery_date = datetime.strptime(final_date, '%Y-%m-%d %H:%M')
        date = datetime.now()
        if date > lottery_date:
            return False
        if item_id is not False:
            ticket_id = ItemsLogic.add_item_to_shop_and_return_id(
                ticket, username)
            if ticket_id is not False:
                lottery = Lottery(ticket_id, final_date, None, item_id)
                status = Lotteries.add_lottery(lottery)
                if status is not False:
                    return True
    return False
コード例 #27
0
 def test_get_visible_discount_bad_item(self):
     register(RegisteredUser('YoniYoni', '1234567878'))
     register(RegisteredUser('StoreManager1', '1234567878'))
     shop = Shop('My Shop', 'Active')
     ShopLogic.create_shop(shop, 'YoniYoni')
     UsersLogic.add_manager(
         'YoniYoni',
         StoreManager('StoreManager1', 'My Shop', 1, 1, 1, 1, 1, 1, 1, 1))
     item1 = Item(1, 'My Shop', 'milk', 'diary', 'good', 12, 100, 'regular',
                  None, 0, 0, 0)
     item2 = Item(2, 'My Shop', 'milk1', 'diary1', 'good', 12, 100,
                  'regular', None, 0, 0, 0)
     ItemsLogic.add_item_to_shop(item1, 'StoreManager1')
     disc = VisibleDiscount(item1.id, shop.name, 50, '2018-12-01',
                            '2019-12-01')
     self.assertTrue(add_visible_discount(disc, 'YoniYoni'))
     self.assertFalse(get_visible_discount(item2.id, shop.name))
コード例 #28
0
 def test_get_visible_discount(self):
     register(RegisteredUser('YoniYoni', '1234567878'))
     register(RegisteredUser('StoreManager1', '1234567878'))
     shop = Shop('My Shop', 'Active')
     ShopLogic.create_shop(shop, 'YoniYoni')
     UsersLogic.add_manager(
         'YoniYoni',
         StoreManager('StoreManager1', 'My Shop', 1, 1, 1, 1, 1, 1, 1, 1))
     item1 = Item(1, 'My Shop', 'milk', 'diary', 'good', 12, 100, 'regular',
                  None, 0, 0, 0)
     ItemsLogic.add_item_to_shop(item1, 'StoreManager1')
     disc = VisibleDiscount(item1.id, shop.name, 50, '2018-12-01',
                            '2019-12-01')
     self.assertTrue(add_visible_discount(disc, 'YoniYoni'))
     getted = get_visible_discount(item1.id, shop.name)
     self.assertEqual(getted.item_id, disc.item_id)
     self.assertEqual(getted.shop_name, disc.shop_name)
     self.assertEqual(getted.percentage, disc.percentage)
コード例 #29
0
ファイル: Item.py プロジェクト: omriattiya/uTrade
def get_reviews(request):
    if request.method == 'GET':
        item_id = request.GET.get('item_id')
        item = ItemsLogic.get_item(item_id)
        if item is not False:
            reviews = ItemsLogic.get_all_reviews_on_item(item.id)
            string_reviews = ""
            for review in reviews:
                string_reviews += loader.render_to_string(
                    'component/../../../PresentationLayer/templates/components/review.html',
                    {'writer_name': review.writerId, 'rank': review.rank, 'description': review.description}, None,
                    None)
            login = request.COOKIES.get('login_hash')
            guest = request.COOKIES.get('guest_hash')
            context = {'topbar': Topbar_Navbar.get_top_bar(login), 'navbar': Topbar_Navbar.get_nav_bar(login, guest)}
            context.update({'item_name': item.name, 'shop_name': item.shop_name, 'reviews': string_reviews})
            return render(request, 'item_reviews.html', context=context)
        return HttpResponse(shop_not_exist)
    return HttpResponse(not_get_request)
コード例 #30
0
ファイル: ShoppingLogic.py プロジェクト: omriattiya/uTrade
def update_item_shopping_cart(username, item_id, new_quantity):
    if username is not None and item_id is not None and new_quantity >= 0:
        if new_quantity is 0:
            return remove_item_shopping_cart(username, item_id)
        if ItemsLogic.check_in_stock(item_id, new_quantity) is False:
            return False
        user = RegisteredUsers.get_user(username)
        if user is not False:
            return ShoppingCartDB.update_item_shopping_cart(
                username, item_id, new_quantity)
    return False