Пример #1
0
    def test_cache_backward(self):
        json = '[{"title": "Russia", "tooltip": "/soccer/country/Russia", "key": "/soccer/country/Russia", "expand": true, "icon": "", "children": []}]'
        xpath = "/soccer/country"
        cache_tree = CacheTree(json)
        cache_tree.cache_node(xpath)

        tree_json = cache_tree.get_json()
        print("Cached xpath:'{}', JSON:{}".format(xpath, tree_json))
        self.assertEqual('[{"title": "country", "tooltip": "/soccer/country", "key": "/soccer/country", "expand": true, "icon": "../../css/warning-icon.png", "children": [{"title": "Russia", "tooltip": "/soccer/country/Russia", "key": "/soccer/country/Russia", "expand": true, "icon": "", "children": []}]}]', tree_json)

        xpath = "/soccer/country"
        json = '[{"title":"Russia","key":"/soccer/country/Russia","isFolder":false,"isLazy":false,"tooltip":"/soccer/country/Russia","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"England","key":"/soccer/country/England","isFolder":false,"isLazy":false,"tooltip":"/soccer/country/England","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"soccer","key":"/soccer","isFolder":false,"isLazy":false,"tooltip":"/soccer","href":null,"icon":"","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]'
        cache_tree = CacheTree(json)
        cache_tree.cache_node(xpath)
        tree_json = cache_tree.get_json()
        print("Cached xpath:'{}', JSON:{}".format(xpath, tree_json))
        self.assertEqual('[{"title": "soccer", "tooltip": "/soccer", "key": "/soccer", "expand": true, "icon": "", "children": [{"title": "country", "tooltip": "/soccer/country", "key": "/soccer/country", "expand": true, "icon": "", "children": [{"title": "Russia", "tooltip": "/soccer/country/Russia", "key": "/soccer/country/Russia", "expand": true, "icon": null, "children": []}, {"title": "England", "tooltip": "/soccer/country/England", "key": "/soccer/country/England", "expand": true, "icon": null, "children": []}]}]}]', tree_json)

        xpath = '/soccer/country'
        json = '[{"title":"Russia","key":"/soccer/country/Russia","isFolder":false,"isLazy":false,"tooltip":"/soccer/country/Russia","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"England","key":"/soccer/country/England","isFolder":false,"isLazy":false,"tooltip":"/soccer/country/England","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"soccer","key":"/soccer","isFolder":false,"isLazy":false,"tooltip":"/soccer","href":null,"icon":"","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]'
        cache_tree = CacheTree(json)
        cache_tree.cache_node(xpath)
        tree_json = cache_tree.get_json()
        print("Cached xpath:'{}', JSON:{}".format(xpath, tree_json))
        self.assertEqual('[{"title": "soccer", "tooltip": "/soccer", "key": "/soccer", "expand": true, "icon": "", "children": [{"title": "country", "tooltip": "/soccer/country", "key": "/soccer/country", "expand": true, "icon": "", "children": [{"title": "Russia", "tooltip": "/soccer/country/Russia", "key": "/soccer/country/Russia", "expand": true, "icon": null, "children": []}, {"title": "England", "tooltip": "/soccer/country/England", "key": "/soccer/country/England", "expand": true, "icon": null, "children": []}]}]}]', tree_json)
Пример #2
0
def add_record(request):
    """
        Function simulates the add new element into Cache Tree.
        INPUT POST parameters:
        1) [optional] data -- current content of Cache Tree in JSON format;
        2) [optional] parent_xpath -- full path of parent element where we'll add a child;
        3) [mandatory] parent_xpath -- full path of parent element where we'll add a child.

        :returns updated Cache Tree in JSON format.
    """
    data = get_str_param(request, 'data')
    parent_key = get_str_param(request, 'parent_key')
    tag_name = get_str_param(request, 'tag_name')
    logger.info("Request received:\n tag = {}; \nparent_key={};\nCurrent Cache data: {} "
                .format(tag_name, parent_key, data))

    cache_tree = CacheTree(data)
    logger.info("Cache tree has been built.")
    if tag_name != "":
        cache_tree.add_new_node_by_key(parent_key, tag_name)
        logger.info("New note {} has been added.".format(parent_key))
    else:
        logger.info("New note {} has not been added cuz tag name is blank.".format(parent_key))
    tree_json = cache_tree.get_json()
    logger.debug("Response JSON has been built: {}".format(tree_json))

    return send_json(tree_json)
Пример #3
0
    def test_cache_add(self):
        tag_name = "torpedo"
        parent_xpath="/soccer/country/Russia/RFPL/Moscow"
        json = '[{"title":"Moscow","key":"/soccer/country/Russia/RFPL/Moscow","isFolder":false,"isLazy":false,"tooltip":"/soccer/country/Russia/RFPL/Moscow","href":null,"icon":"","addClass":null,"noLink":false,"activate":true,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"CSKA","key":"/soccer/country/Russia/RFPL/Moscow/CSKA","isFolder":false,"isLazy":false,"tooltip":"/soccer/country/Russia/RFPL/Moscow/CSKA","href":null,"icon":"","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]}]'
        cache_tree = CacheTree(json)
        cache_tree.add_new_node(parent_xpath, tag_name)

        tree_json = cache_tree.get_json()
        print("Added '{}' into '{}', JSON:{}".format(tag_name, parent_xpath, tree_json))
        self.assertEqual('[{"title": "Moscow", "tooltip": "/soccer/country/Russia/RFPL/Moscow", "key": "/soccer/country/Russia/RFPL/Moscow", "expand": true, "icon": "../../css/warning-icon.png", "children": [{"title": "CSKA", "tooltip": "/soccer/country/Russia/RFPL/Moscow/CSKA", "key": "/soccer/country/Russia/RFPL/Moscow/CSKA", "expand": true, "icon": "", "children": []}, {"title": "torpedo", "tooltip": "/soccer/country/Russia/RFPL/Moscow/torpedo", "key": "/soccer/country/Russia/RFPL/Moscow/torpedo", "expand": true, "icon": "../../css/add-icon.png", "children": []}]}]', tree_json)
Пример #4
0
    def test_cache(self):
        cache_tree = CacheTree("")
        self.assertEqual(cache_tree.roots, [])
        print("Empty CacheTree has been created.")

        xpath = "/soccer"
        cache_tree.cache_node(xpath)
        tree_json = cache_tree.get_json()
        print("Cached xpath:'{}', JSON:{}".format(xpath, tree_json))
        self.assertEqual('[{"title": "soccer", "tooltip": "/soccer", "key": "/soccer", "expand": true, "icon": "", "children": []}]', tree_json)

        xpath = "/soccer/country"
        cache_tree = CacheTree(tree_json)
        tree_json = cache_tree.get_json()
        print("Cached xpath:'{}', JSON:{}".format(xpath, tree_json))
        self.assertEqual('[{"title": "soccer", "tooltip": "/soccer", "key": "/soccer", "expand": true, "icon": "", "children": []}]', tree_json)

        cache_tree.cache_node(xpath)
        tree_json = cache_tree.get_json()
        self.assertEqual('[{"title": "soccer", "tooltip": "/soccer", "key": "/soccer", "expand": true, "icon": "", "children": [{"title": "country", "tooltip": "/soccer/country", "key": "/soccer/country", "expand": true, "icon": "", "children": []}]}]', tree_json)
        print("Caching xpath:'{}', JSON:{}".format(xpath, tree_json))
Пример #5
0
def cache_after_save(request):
    """
        Function simply unmark edit and add nodes.
    """
    cache_data = get_str_param(request, 'data')
    cache_tree = CacheTree(cache_data)
    logger.debug("Save cache request received:\n Current Cache data: {} ".format(cache_data))

    cache_tree.update_after_save()
    tree_json = cache_tree.get_json()
    logger.debug("Response JSON has been built: {}".format(tree_json))
    return send_json(tree_json)
Пример #6
0
def remove_record(request):
    """
        Function simulates the 'remove' element from Cache Tree.
        NOTE: it doesn't remove element from Cache Tree it just marks it and recursively all children as deleted nodes.
        INPUT POST parameters:
        1) [optional] data -- current content of Cache Tree in JSON format;
        2) [optional] xpath -- full path of element to be deleted;
        3) [mandatory] parent_xpath -- full path of parent element where we'll add a child.

        :returns updated Cache Tree in JSON format.
    """
    data = get_str_param(request, 'data')
    key = get_str_param(request, 'key')
    logger.info("Remove request received:\n xpath={};\nCurrent Cache data: {} ".format(key, data))

    cache_tree = CacheTree(data)
    logger.info("Cache tree has been built.")
    cache_tree.delete_node_by_key(key)
    logger.info("Note {} has been removed.".format(key))
    tree_json = cache_tree.get_json()
    logger.debug("Response JSON has been built: {}".format(tree_json))
    return send_json(tree_json)
Пример #7
0
def cache_record(request):
    """
        Function simulates the DB record caching process.
        INPUT POST parameters:
        1) [optional] data -- current content of Cache Tree in JSON format;
        2) [mandatory] xpath -- full path of caching element.

        :returns updated Cache Tree in JSON format.
    """
    data = get_str_param(request, 'data')
    title = get_str_param(request, 'title')
    #xpath = get_str_param(request, 'xpath')
    key = get_str_param(request, 'key')
    parent_key = get_str_param(request, 'parent_key')
    logger.info("Request received:\n xpath = {}; title: {}; parent_key: {}; \nCurrent Cache data: {} ".format(key, title, parent_key, data))

    cache_tree = CacheTree(data)
    logger.info("Cache tree has been built.")
    cache_tree.cache_node_by_key(key, parent_key, title)
    logger.info("Note {} has been inserted.".format(key))
    tree_json = cache_tree.get_json()
    logger.debug("Response JSON has been built: {}".format(tree_json))

    return send_json(tree_json)