def test_url_exists(self):
        """weblinkback - test URL existence"""
        add_url_to_list('url1', CFG_WEBLINKBACK_LIST_TYPE['BLACKLIST'], self.user_info)
        add_url_to_list('url2', CFG_WEBLINKBACK_LIST_TYPE['BLACKLIST'], self.user_info)
        add_url_to_list('url3', CFG_WEBLINKBACK_LIST_TYPE['WHITELIST'], self.user_info)

        self.assertTrue(url_exists('url1'))
        self.assertTrue(url_exists('url1', CFG_WEBLINKBACK_LIST_TYPE['BLACKLIST']))
        self.assertFalse(url_exists('url1', CFG_WEBLINKBACK_LIST_TYPE['WHITELIST']))

        remove_url('url1')
        self.assertFalse(url_exists('url1'))
        self.assertFalse(url_exists('url1', CFG_WEBLINKBACK_LIST_TYPE['BLACKLIST']))
        self.assertFalse(url_exists('url1', CFG_WEBLINKBACK_LIST_TYPE['WHITELIST']))

        self.assertTrue(url_exists('url3'))
        self.assertFalse(url_exists('url3', CFG_WEBLINKBACK_LIST_TYPE['BLACKLIST']))
        self.assertTrue(url_exists('url3', CFG_WEBLINKBACK_LIST_TYPE['WHITELIST']))
예제 #2
0
def perform_moderate_url(req, url, action, list_type):
    """
    Perform a url action
    @param url
    @param action: CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['INSERT'] or CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['DELETE']
    @param list_type: of CFG_WEBLINKBACK_LIST_TYPE
    @return (String, CFG_WEBLINKBACK_ACTION_RETURN_CODE) the String is url if CFG_WEBLINKBACK_ACTION_RETURN_CODE['BAD_INPUT')
    """
    if url == '' or ' ' in url:
        return (url, CFG_WEBLINKBACK_ACTION_RETURN_CODE['BAD_INPUT'])
    elif action == CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['INSERT']:
        if url_exists(url):
            return ('', CFG_WEBLINKBACK_ACTION_RETURN_CODE['DUPLICATE'])
        else:
            add_url_to_list(url, list_type, collect_user_info(req))
    elif action == CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['DELETE']:
        remove_url(url)
    else:
        return ('', CFG_WEBLINKBACK_ACTION_RETURN_CODE['INVALID_ACTION'])

    return ('', CFG_WEBLINKBACK_ACTION_RETURN_CODE['OK'])
예제 #3
0
def perform_moderate_url(req, url, action, list_type):
    """
    Perform a url action
    @param url
    @param action: CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['INSERT'] or CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['DELETE']
    @param list_type: of CFG_WEBLINKBACK_LIST_TYPE
    @return (String, CFG_WEBLINKBACK_ACTION_RETURN_CODE) the String is url if CFG_WEBLINKBACK_ACTION_RETURN_CODE['BAD_INPUT')
    """
    if url == '' or ' ' in url:
        return (url, CFG_WEBLINKBACK_ACTION_RETURN_CODE['BAD_INPUT'])
    elif action == CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['INSERT']:
        if url_exists(url):
            return ('', CFG_WEBLINKBACK_ACTION_RETURN_CODE['DUPLICATE'])
        else:
            add_url_to_list(url, list_type, collect_user_info(req))
    elif action == CFG_WEBLINKBACK_ADMIN_MODERATION_ACTION['DELETE']:
        remove_url(url)
    else:
        return ('', CFG_WEBLINKBACK_ACTION_RETURN_CODE['INVALID_ACTION'])

    return ('', CFG_WEBLINKBACK_ACTION_RETURN_CODE['OK'])