Exemplo n.º 1
0
def add_owner(username, owner):
    if username is not None:
        if Owners.get_owner(username, owner.shop_name) is not False:
            if RegisteredUsers.get_user(owner.username) is not False:
                if Owners.get_owner(owner.username,
                                    owner.shop_name) is not False:
                    to_return = 'FAILED! ' + owner.username + ' is already an owner'
                    return to_return
                result = Owners.add_owner(owner)
                if result:
                    result = HistoryAppointings.add_history_appointing(
                        username, owner.username, 'Owner', owner.shop_name,
                        strftime("%d-%m-%Y %H:%M:%S", gmtime()), 'Owner')
                else:
                    return "FAILED"
                if result and is_manager_of_shop(owner.username,
                                                 owner.shop_name):
                    result = remove_store_manager(username, owner.shop_name,
                                                  owner.username)
                    if result:
                        return "SUCCESS"
                    else:
                        return "FAILED"
                elif result:
                    return "SUCCESS"
                else:
                    return "FAILED"
            else:
                return "FAILED: Username does not exists"
        else:
            return "FAILED: You are not the owner of this shop"
    else:
        return "FAILED: Missing Parameters"
Exemplo n.º 2
0
    def test_modify_notifications(self):
        ShopLogic.create_shop(SHOP, USERNAME)
        UsersLogic.modify_notifications(USERNAME, 0, SHOP.name)
        owner = Owners.get_owner(USERNAME, SHOP_NAME)
        self.assertEqual(0, owner.should_notify)

        UsersLogic.modify_notifications(USERNAME, 1, SHOP.name)
        owner = Owners.get_owner(USERNAME, SHOP_NAME)
        self.assertEqual(1, owner.should_notify)
Exemplo n.º 3
0
def update_shopping_policy_on_shop(username, policy_id, field_name, new_value, shop_name):
    if policy_id is not None and field_name is not None and new_value is not None:
        if int(policy_id) < 0:
            return "FAILED: Invalid id of Policy"
        if field_name not in ['shop_name', 'conditions', 'restriction', 'quantity']:
            return "FAILED: Invalid field name"
        if Owners.get_owner(username, shop_name) is not False:
            if field_name in ['conditions']:
                status = checkConditionsSyntax(new_value)
                if new_value == "":
                    new_value = "1=1"
                if status is not True:
                    return status

            if not ShoppingPolicies.update_shopping_policy_on_shop(policy_id, field_name, new_value):
                return "FAILED: DB error."
            LoggerLogic.add_event_log(username, "POLICY: UPDATE SHOP SHOPPING POLICY")
            return True
        manager = StoreManagers.get_store_manager(username, shop_name)
        if manager is not False:
            if manager.permission_set_policy > 0:
                if field_name in ['conditions']:
                    status = checkConditionsSyntax(new_value)
                    if new_value == "":
                        new_value = "1=1"
                    if status is not True:
                        return status

                if not ShoppingPolicies.update_shopping_policy_on_shop(policy_id, field_name, new_value):
                    return "FAILED: DB error."
                LoggerLogic.add_event_log(username, "POLICY: UPDATE SHOP SHOPPING POLICY")
                return True
            return 'FAILED: no permissions!'
        return 'FAILED: you are not a the Owner of the shop'
    return "FAILED: One (or more) of the parameters is None"
Exemplo n.º 4
0
def send_message_from_shop(username, message):
    output = False
    manager = StoreManagers.get_store_manager(username, message.from_username)
    if Shops.search_shop(
            message.to_username) is False and RegisteredUsers.is_user_exists(
                message.to_username) is False:
        return "FAILED: Target does not exists"
    if manager is not False:
        if manager.permission_reply_messages > 0:
            output = Messages.send_message_from_shop(message)
        else:
            return "FAILED: You don't have the permissions"
    if Owners.get_owner(username, message.from_username) is not False:
        output = Messages.send_message_from_shop(message)
    else:
        return "FAILED: You are not authorized"
    if output:
        users = [message.to_username]
        if message.to_username == 'System':
            SMs = SystemManagers.get_all_system_managers()
            SM_names = []
            for sm in SMs:
                SM_names.append(sm.username)
            users = SM_names
        MessagingAlerts.notify_messaging_alerts(
            users, '<a href = "../app/home/messages/?content=received" >'
            ' You Have a new message from <strong>Shop</strong>' +
            message.from_username + '</a>')
        return "SUCCESS"
    else:
        return "FAILED"
Exemplo n.º 5
0
def add_invisible_discount_category(disc, username):
    if disc is not None and username is not None and 0 <= disc.percentage <= 100:
        is_owner = Owners.get_owner(username, disc.shop_name)
        is_manager = StoreManagers.get_store_manager(username, disc.shop_name)
        if is_owner is not False or (is_manager is not False
                                     and is_manager.discount_permission == 1):
            return Discount.add_invisible_discount_category(disc)
    return False
Exemplo n.º 6
0
def remove_shopping_policy_on_shop(username, policy_id, shop_name):
    if policy_id is not None and policy_id > 0:
        if Owners.get_owner(username, shop_name) is not False:
            if not ShoppingPolicies.remove_shopping_policy_on_shop(policy_id):
                return "FAILED: DB error."
            LoggerLogic.add_event_log(username, "POLICY: REMOVE SHOP SHOPPING POLICY")
            return True
        return 'FAILED: you are not a the Owner of the shop'
    return "FAILED: Invalid id of Policy"
Exemplo n.º 7
0
def get_shop_purchase_history(username, shop_name):
    manager = StoreManagers.get_store_manager(username, shop_name)
    owner = Owners.get_owner(username, shop_name)
    if manager is not False:
        if manager.permission_get_purchased_history > 0:
            return PurchasedItems.get_purchased_items_by_shop(shop_name)
    else:
        if owner is not False:
            return PurchasedItems.get_purchased_items_by_shop(shop_name)
    return False
Exemplo n.º 8
0
def re_open_shop(username, shop_name):
    owner_of_shop = Owners.get_owner(username, shop_name)
    if owner_of_shop is not False:
        result = Shops.re_open_shop(shop_name)
        if result:
            LoggerLogic.add_event_log(username,
                                      "SHOP STATUS CHANGED - RE-OPEN")
        return result
    else:
        return False
Exemplo n.º 9
0
def get_all_sent_shop_messages(username, shop_name):
    manager = StoreManagers.get_store_manager(username, shop_name)
    if manager is not False:
        if manager.permission_get_all_messages > 0:
            if Shops.search_shop(shop_name) is not False:
                return Messages.get_all_sent_shop_messages(shop_name)
    if Owners.get_owner(username, shop_name) is not False:
        if Shops.search_shop(shop_name) is not False:
            return Messages.get_all_sent_shop_messages(shop_name)
    return False
Exemplo n.º 10
0
def add_item_to_shop(item, username):
    if item is not None and item.shop_name is not None and username is not None and item.quantity >= 0 \
            and item.price >= 0:
        manager = StoreManagers.get_store_manager(username, item.shop_name)
        if manager is not False:
            add_item_permission = manager.permission_add_item
            if add_item_permission > 0:
                return Items.add_item_to_shop(item)
        if Owners.get_owner(username, item.shop_name) is not False:
            return Items.add_item_to_shop(item)
    return False
Exemplo n.º 11
0
def edit_shop_item(username, item_id, field_name, new_value):
    item = Items.get_item(item_id)
    result = StoreManagers.get_store_manager(username, item.shop_name)
    if result is not False:
        edit_item_permission = result.permission_edit_item
        if edit_item_permission > 0:
            return Items.update_item(item_id, field_name, new_value)
    else:
        if Owners.get_owner(username, item.shop_name) is not False:
            return Items.update_item(item_id, field_name, new_value)
    return False
Exemplo n.º 12
0
def close_shop(username, shop_name):
    owner_of_shop = Owners.get_owner(username, shop_name)
    if owner_of_shop is not False:
        result = Shops.close_shop(shop_name)
        if result:
            lotteries = get_lotteries_by_shop(shop_name)
            for lottery in lotteries:
                lottery_timer(lottery.id)
            LoggerLogic.add_event_log(username, "SHOP STATUS CHANGED - CLOSE")
        return result
    else:
        return False
Exemplo n.º 13
0
def add_manager(username, store_manager):
    if username is not None:
        if Owners.get_owner(username, store_manager.store_name) is not False:
            if RegisteredUsers.get_user(store_manager.username) is not False:
                if store_manager.store_name is not None:
                    if Owners.get_owner(store_manager.username,
                                        store_manager.store_name):
                        return "FAILED! An owner can't be store manager"
                    if StoreManagers.add_manager(store_manager):
                        if HistoryAppointings.add_history_appointing(
                                username, store_manager.username,
                                'Store Manager', store_manager.store_name,
                                strftime("%d-%m-%Y %H:%M:%S", gmtime()), ''):
                            return 'SUCCESS'
                        return "FAILED"
                    return "FAILED"
                else:
                    return "FAILED: Shop does not exists"
            else:
                return "FAILED: User does not exists"
        else:
            return "FAILED: You are not the owner of this shop"
    else:
        return "FAILED: Missing Parameters"
Exemplo n.º 14
0
def add_shopping_policy_on_shop(username, shop_name, conditions, restriction, quantity):
    if shop_name is not None and conditions is not None:
        if restriction is not None and quantity is not None:
            if restriction not in ['N', 'AL', 'E', 'UT']:
                return "FAILED: Invalid value of restriction."
            if int(quantity) < 0:
                return "FAILED: Negative quantity is invalid."
            if Owners.get_owner(username, shop_name) is not False:
                if not ShoppingPolicies.add_shopping_policy_on_shop(shop_name, conditions, restriction, quantity):
                    return "FAILED: DB error."
                LoggerLogic.add_event_log(username, "POLICY: ADD SHOP SHOPPING POLICY")
                return True
            manager = StoreManagers.get_store_manager(username,shop_name)
            if manager is not False:
                if manager.permission_set_policy > 0:
                    if not ShoppingPolicies.add_shopping_policy_on_shop(shop_name, conditions, restriction, quantity):
                        return "FAILED: DB error."
                    LoggerLogic.add_event_log(username, "POLICY: ADD SHOP SHOPPING POLICY")
                    return True
                return 'FAILED: no permissions!'
            return 'FAILED: you are not a the Owner of the shop'
        return "FAILED: One (or more) of the parameters is None"
    return "FAILED: One (or more) of the parameters is None"
Exemplo n.º 15
0
def is_owner(username, shop_name):
    return Owners.get_owner(username, shop_name) is not False
Exemplo n.º 16
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)
Exemplo n.º 17
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')
Exemplo n.º 18
0
 def test_add_owner(self):
     ShopLogic.create_shop(SHOP, USERNAME)
     owner = Owners.get_owner(USERNAME, SHOP.name)
     self.assertEqual(USERNAME, owner.username)
     self.assertEqual(SHOP.name, owner.shop_name)
Exemplo n.º 19
0
 def test_add_owner_bad_owner(self):
     ShopLogic.create_shop(SHOP, USERNAME)
     is_owner = Owners.get_owner(OTHER_USERNAME, SHOP.name)
     self.assertFalse(is_owner)
Exemplo n.º 20
0
 def test_add_owner_bad_shop(self):
     ShopLogic.create_shop(SHOP, USERNAME)
     is_owner = Owners.get_owner(USERNAME, OTHER_SHOP_NAME)
     self.assertFalse(is_owner)