Exemple #1
0
    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)
Exemple #2
0
    def test_permissions(self):
        UsersLogic.register(RegisteredUser('ShaharShahar', '1212345678'))
        UsersLogic.register(RegisteredUser('TomerTomerLev', '65412321'))
        shop = Shop('myShop', 'Active')
        ShopLogic.create_shop(shop, 'ShaharShahar')
        UsersLogic.add_manager(
            'ShaharShahar',
            StoreManager('TomerTomerLev', 'myShop', 1, 1, 1, 1, 1, 1, 1, 1))
        ItemsLogic.add_item_to_shop(
            Item(None, 'myShop', 'doll', 'toys', 'toys:kids', 20, 300,
                 'regular', None, 0, 0, 0), 'TomerTomerLev')
        item = Items.get_item(1)
        self.assertEqual(item.shop_name, 'myShop')
        self.assertEqual(item.price, 20)
        self.assertEqual(item.quantity, 300)

        status = ItemsLogic.edit_shop_item('TomerTomerLev', 1, 'price', 40)
        self.assertTrue(status)
        status = ItemsLogic.edit_shop_item('TomerTomerLev', 1, 'name',
                                           'doll_new')
        self.assertTrue(status)
        status = ItemsLogic.edit_shop_item('TomerTomerLev', 1, 'quantity', 40)
        self.assertTrue(status)

        item = Items.get_item(1)
        self.assertEqual(item.name, 'doll_new')
        self.assertEqual(item.quantity, 40)
        self.assertEqual(item.keyWords, 'toys:kids')

        status = ItemsLogic.remove_item_from_shop(1, 'TomerTomerLev')
        self.assertTrue(status)
    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))
Exemple #4
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, [])
Exemple #5
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')
Exemple #6
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)
Exemple #7
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))
Exemple #8
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))
Exemple #9
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))
Exemple #10
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)
Exemple #11
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'))
Exemple #12
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)
Exemple #13
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)
Exemple #14
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)
Exemple #15
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)
Exemple #16
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))
Exemple #17
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)
Exemple #18
0
 def setUp(self):
     init_database('db.sqlite3')
     register(RegisteredUser('TomerTomer', '1234567878'))
     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')
     ItemsLogic.add_item_to_shop(
         Item(2, 'My Shop', 'steak', 'meat', 'bad', 12, 100, 'regular',
              None, 0, 0, 0), 'TomerTomer')
     ItemsLogic.add_item_to_shop(
         Item(3, 'My Shop', 'banana', 'fruit', 'best', 12, 100, 'regular',
              None, 0, 0, 0), 'TomerTomer')
     ItemsLogic.add_item_to_shop(
         Item(4, 'My Shop', 'water', 'drinks', 'one two', 12, 100,
              'regular', None, 0, 0, 0), 'TomerTomer')
Exemple #19
0
    def test_no_permission(self):
        UsersLogic.register(RegisteredUser('ShaharShahar', '12312456'))
        UsersLogic.register(RegisteredUser('TomerTomerLev', '65431221'))
        shop = Shop('myShop', 'Active')
        ShopLogic.create_shop(shop, 'ShaharShahar')
        UsersLogic.add_manager(
            'ShaharShahar',
            StoreManager('TomerTomerLev', 'myShop', 0, 0, 0, 0, 0, 0, 0, 0))
        status = ItemsLogic.add_item_to_shop(
            Item(None, 'myShop', 'doll', 'toys', 'toys;kids', 20, 300,
                 'regular', None, 0, 0, 0), 'TomerTomerLev')
        self.assertFalse(status)

        message = Message(None, 'myShop', 'ShaharShahar', 'Hi There')
        status = MessagingLogic.send_message_from_shop('TomerTomerLev',
                                                       message)
        self.assertFalse(returnStringToBoolean(status))
Exemple #20
0
def add_item_to_shop(shop_name, item_name, item_category, keywords, price,
                     quantity, username, kind, url, item_rating,
                     sum_of_ranking, num_of_reviews):
    return ItemsLogic.add_item_to_shop(
        Item(0, shop_name, item_name, item_category, keywords, price, quantity,
             kind, url, item_rating, sum_of_ranking, num_of_reviews), username)
Exemple #21
0
def add_item_to_shop(request):
    if request.method == 'POST':
        shop_name = request.POST.get('shop_name')
        item_name = request.POST.get('item_name')
        item_quantity = int(request.POST.get('item_quantity'))
        item_category = request.POST.get('item_category')
        item_keywords = request.POST.get('item_keywords')
        item_price = float(request.POST.get('item_price'))
        item_url = request.POST.get('item_url')
        item_kind = request.POST.get('item_kind')

        if item_name is None or item_name == '':
            return HttpResponse('invalid item name')

        if item_quantity < 0:
            return HttpResponse('invalid quantity')

        if item_category is None or item_category == '':
            return HttpResponse('invalid category')

        if item_keywords is None:
            return HttpResponse('invalid keywords')

        if item_price <= 0:
            return HttpResponse('invalid price')

        event = "ADD ITEM"
        suspect_sql_injection = False
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            shop_name, event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            item_name, event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            item_category, event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            item_keywords, event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            item_url, event) or suspect_sql_injection
        suspect_sql_injection = LoggerLogic.identify_sql_injection(
            item_kind, event) or suspect_sql_injection
        if suspect_sql_injection:
            return HttpResponse(MESSAGE_SQL_INJECTION)

        if shop_name is None or ShopLogic.search_shop(shop_name) is False:
            return HttpResponse('invalid shop')

        if item_url == '':
            item_url = None

        sale_date = None
        sale_hour = None
        sale_minutes = None
        if item_kind == 'prize':
            sale_date = request.POST.get('sale_date')
            sale_hour = request.POST.get('sale_hour')
            sale_minutes = request.POST.get('sale_minutes')

        login = request.COOKIES.get('login_hash')
        if login is None:
            login = request.POST.get('login_hash')
        username = None
        if login is not None:
            username = Consumer.loggedInUsers.get(login)
            if username is None:
                return HttpResponse('user not logged in')
        if not UsersLogic.is_owner_of_shop(username, shop_name):
            if UsersLogic.is_manager_of_shop(username, shop_name):
                manager = UsersLogic.get_manager(username, shop_name)
                if manager.permission_add_item is not 1:  # no permission
                    return HttpResponse('no permission to add item')
            else:
                return HttpResponse('not owner or manager in this shop'
                                    )  # not manager not owner

        status = False
        if item_kind == 'regular':
            regular_item = Item(None, shop_name, item_name, item_category,
                                item_keywords, item_price, item_quantity,
                                item_kind, item_url, 0, 0, 0)
            status = ItemsLogic.add_item_to_shop(regular_item, username)
        elif item_kind == 'prize':
            prize = Item(None, shop_name, item_name, item_category,
                         item_keywords, item_price, 1, item_kind, item_url, 0,
                         0, 0)
            ticket = Item(None, shop_name, 'Ticket for ' + item_name,
                          item_category, item_keywords, item_price,
                          item_quantity, 'ticket', item_url, 0, 0, 0)
            status = LotteryLogic.add_lottery_and_items_and_return_id(
                prize, ticket, ticket.price,
                sale_date + ' ' + sale_hour + ':' + sale_minutes, username)
        if status is False:
            return HttpResponse('could not add item')
        return HttpResponse('success')
Exemple #22
0
    def test_discounts_torture(self):
        status = UsersLogic.register(RegisteredUser('YoniYoni', "SsS0897SsS"))
        self.assertEqual(status, "SUCCESS")
        status = UsersLogic.update_details('YoniYoni', 'AFG', 20, 'Male')
        self.assertEqual(status, "SUCCESS")

        status = UsersLogic.register(RegisteredUser('YoniYoni2', "SsS0897SsS"))
        self.assertEqual(status, "SUCCESS")
        status = UsersLogic.update_details('YoniYoni2', 'ZMB', 20, 'Male')
        self.assertEqual(status, "SUCCESS")

        status = UsersLogic.register(RegisteredUser('YoniYoni3', "SsS0897SsS"))
        self.assertEqual(status, "SUCCESS")
        status = UsersLogic.update_details('YoniYoni3', 'ISR', 100, 'Female')
        self.assertEqual(status, "SUCCESS")

        status = ShopLogic.create_shop(Shop('eBay', "Active"), 'YoniYoni')
        self.assertEqual(status, "SUCCESS")
        status = ShopLogic.create_shop(Shop('Amazon', "Active"), 'YoniYoni2')
        self.assertEqual(status, "SUCCESS")
        status = ShopLogic.create_shop(Shop('Carmel', "Active"), 'YoniYoni3')
        self.assertEqual(status, "SUCCESS")

        item1 = Item(1, 'eBay', 'carrot', 'vegas', 'good', 10, 500, 'regular',
                     None, 0, 0, 0)
        item2 = Item(2, 'Amazon', 'apple', 'fruits', 'good', 10, 500,
                     'regular', None, 0, 0, 0)
        item3 = Item(3, 'Carmel', 'Kipa', 'Yudaika', 'good', 10, 500,
                     'regular', None, 0, 0, 0)

        status = ItemsLogic.add_item_to_shop(item1, 'YoniYoni')
        self.assertTrue(status)
        status = ItemsLogic.add_item_to_shop(item2, 'YoniYoni2')
        self.assertTrue(status)
        status = ItemsLogic.add_item_to_shop(item3, 'YoniYoni3')
        self.assertTrue(status)

        disc1 = VisibleDiscount(item1.id, item1.shop_name, 10, '2018-17-06',
                                '2019-21-03')
        disc2 = VisibleDiscount(item2.id, item2.shop_name, 20, '2018-17-06',
                                '2019-22-03')
        disc3 = VisibleDiscount(item3.id, item3.shop_name, 30, '2018-17-06',
                                '2019-23-03')

        status = DiscountLogic.add_visible_discount(disc1, 'YoniYoni')
        self.assertTrue(status)
        status = DiscountLogic.add_visible_discount(disc2, 'YoniYoni2')
        self.assertTrue(status)
        status = DiscountLogic.add_visible_discount(disc3, 'YoniYoni3')
        self.assertTrue(status)

        disc1 = VisibleDiscountCategory(item1.category, item1.shop_name, 10,
                                        '2018-17-06', '2019-21-03')
        disc2 = VisibleDiscountCategory(item2.category, item2.shop_name, 20,
                                        '2018-17-06', '2019-22-03')
        disc3 = VisibleDiscountCategory(item3.category, item3.shop_name, 30,
                                        '2018-17-06', '2019-23-03')

        status = DiscountLogic.add_visible_discount_category(disc1, 'YoniYoni')
        self.assertTrue(status)
        status = DiscountLogic.add_visible_discount_category(
            disc2, 'YoniYoni2')
        self.assertTrue(status)
        status = DiscountLogic.add_visible_discount_category(
            disc3, 'YoniYoni3')
        self.assertTrue(status)

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

        status = UserShoppingCartLogic.add_item_shopping_cart(
            access_token, ShoppingCartItem('YoniYoni', 2, 10, None))
        self.assertTrue(status)
        status = UserShoppingCartLogic.add_item_shopping_cart(
            access_token, ShoppingCartItem('YoniYoni', 3, 10, None))
        self.assertTrue(status)

        status = UserShoppingCartLogic.get_cart_cost(access_token)
        self.assertEqual(status, 113)

        status = UserShoppingCartLogic.pay_all(access_token)
        self.assertTrue(StoB(status))

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

        status = UserShoppingCartLogic.add_item_shopping_cart(
            access_token, ShoppingCartItem('YoniYoni2', 1, 10, None))
        self.assertTrue(status)
        status = UserShoppingCartLogic.add_item_shopping_cart(
            access_token, ShoppingCartItem('YoniYoni2', 3, 10, None))
        self.assertTrue(status)

        status = UserShoppingCartLogic.get_cart_cost(access_token)
        self.assertEqual(status, 130)

        status = UserShoppingCartLogic.pay_all(access_token)
        self.assertTrue(StoB(status))

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

        status = UserShoppingCartLogic.add_item_shopping_cart(
            access_token, ShoppingCartItem('YoniYoni3', 2, 10, None))
        self.assertTrue(status)
        status = UserShoppingCartLogic.add_item_shopping_cart(
            access_token, ShoppingCartItem('YoniYoni3', 1, 10, None))
        self.assertTrue(status)

        status = UserShoppingCartLogic.get_cart_cost(access_token)
        self.assertEqual(status, 145)

        status = UserShoppingCartLogic.pay_all(access_token)
        self.assertTrue(StoB(status))
Exemple #23
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')
Exemple #24
0
    def test_torture2(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))

        manager = StoreManagers.get_store_manager('u4ser4u4ser4', 'myShop1')

        self.assertEqual(manager.permission_reply_messages, 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')

        items = SearchLogic.search_by_name('banana')
        self.assertEqual(items[0].quantity, 300)
        self.assertEqual(items[0].price, 4.90)
        self.assertEqual(len(items), 1)

        items = SearchLogic.search_by_category('drinks')
        self.assertEqual(items[0].quantity, 20)
        self.assertEqual(items[1].price, 70)
        self.assertEqual(len(items), 2)

        items = SearchLogic.search_by_keywords('fun')
        self.assertEqual(items[0].quantity, 10)
        self.assertEqual(items[1].price, 4.90)
        self.assertEqual(len(items), 2)

        items = SearchLogic.search_items_in_shop('myShop2')
        self.assertEqual(items[0].name, 'doll')
        self.assertEqual(items[1].name, 'cucumber')
        self.assertEqual(len(items), 2)

        MessagingLogic.send_message_from_shop(
            'u4ser4u4ser4',
            Message(None, 'myShop1', 'u5seru5ser',
                    'Nadav is our lord and savior'))
        messages = MessagingLogic.get_all_messages('u5seru5ser')
        self.assertEqual(len(messages), 1)
        self.assertEqual(messages[0].content, 'Nadav is our lord and savior')

        MessagingLogic.send_message(
            Message(None, 'u5seru5ser', 'myShop1', 'Hello Shop'))
        messages = MessagingLogic.get_all_shop_messages(
            'u4ser4u4ser4', 'myShop1')
        self.assertEqual(len(messages), 1)
        self.assertEqual(messages[0].content, 'Hello Shop')

        MessagingLogic.send_message_from_shop(
            'u1ser1u1ser1', Message(None, 'myShop1', 'myShop2', 'Hello Shop2'))
        messages = MessagingLogic.get_all_shop_messages(
            'u2ser2u2ser2', 'myShop2')
        self.assertEqual(len(messages), 1)
        self.assertEqual(messages[0].content, 'Hello Shop2')

        MessagingLogic.send_message(
            Message(None, 'u1ser1u1ser1', 'u3ser3u3ser3', 'Shop2 Sucks!'))
        messages = MessagingLogic.get_all_messages('u3ser3u3ser3')
        self.assertEqual(messages[0].content, 'Shop2 Sucks!')

        UsersLogic.close_shop('u1ser1u1ser1', 'myShop1')
        items = SearchLogic.search_by_name('banana')
        self.assertEqual(len(items), 0)