Esempio n. 1
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)
Esempio n. 2
0
    def test_save(self):
        db_json = '[{"title":"Soccer","key":"/Soccer","isFolder":false,"isLazy":false,"tooltip":"/Soccer","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"countries","key":"/Soccer/countries","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Russia","key":"/Soccer/countries/Russia","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"RFPL","key":"/Soccer/countries/Russia/RFPL","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Moscow","key":"/Soccer/countries/Russia/RFPL/Moscow","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Moscow","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"CSKA","key":"/Soccer/countries/Russia/RFPL/Moscow/CSKA","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Moscow/CSKA","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Lokomotiv","key":"/Soccer/countries/Russia/RFPL/Moscow/Lokomotiv","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Moscow/Lokomotiv","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Dinamo","key":"/Soccer/countries/Russia/RFPL/Moscow/Dinamo","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Moscow/Dinamo","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Spartak","key":"/Soccer/countries/Russia/RFPL/Moscow/Spartak","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Moscow/Spartak","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]},{"title":"Saint-Petersburg","key":"/Soccer/countries/Russia/RFPL/Saint-Petersburg","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Saint-Petersburg","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Zenit","key":"/Soccer/countries/Russia/RFPL/Saint-Petersburg/Zenit","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Saint-Petersburg/Zenit","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]},{"title":"Krasnodar","key":"/Soccer/countries/Russia/RFPL/Krasnodar","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Krasnodar","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Kuban","key":"/Soccer/countries/Russia/RFPL/Krasnodar/Kuban","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Krasnodar/Kuban","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Krasnodar","key":"/Soccer/countries/Russia/RFPL/Krasnodar/Krasnodar","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Krasnodar/Krasnodar","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]},{"title":"Tomsk","key":"/Soccer/countries/Russia/RFPL/Tomsk","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Tomsk","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Tom","key":"/Soccer/countries/Russia/RFPL/Tomsk/Tom","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Tomsk/Tom","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]},{"title":"others","key":"/Soccer/countries/Russia/RFPL/others","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/others","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Rubin","key":"/Soccer/countries/Russia/RFPL/others/Rubin","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/others/Rubin","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Ural","key":"/Soccer/countries/Russia/RFPL/others/Ural","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/others/Ural","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Terek","key":"/Soccer/countries/Russia/RFPL/others/Terek","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/others/Terek","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Amkar","key":"/Soccer/countries/Russia/RFPL/others/Amkar","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/others/Amkar","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Krilya","key":"/Soccer/countries/Russia/RFPL/others/Krilya","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/others/Krilya","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]}]}]},{"title":"England","key":"/Soccer/countries/England","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/England","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Manchester","key":"/Soccer/countries/England/Manchester","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/England/Manchester","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"MC","key":"/Soccer/countries/England/Manchester/MC","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/England/Manchester/MC","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"MU","key":"/Soccer/countries/England/Manchester/MU","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/England/Manchester/MU","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]},{"title":"London","key":"/Soccer/countries/England/London","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/England/London","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Is_the_capital_of_Great_Britain","key":"/Soccer/countries/England/London/Is_the_capital_of_Great_Britain","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/England/London/Is_the_capital_of_Great_Britain","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Arsenal","key":"/Soccer/countries/England/London/Arsenal","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/England/London/Arsenal","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Chelsea","key":"/Soccer/countries/England/London/Chelsea","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/England/London/Chelsea","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Totenham","key":"/Soccer/countries/England/London/Totenham","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/England/London/Totenham","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Fulham","key":"/Soccer/countries/England/London/Fulham","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/England/London/Fulham","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]},{"title":"Liverpool","key":"/Soccer/countries/England/Liverpool","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/England/Liverpool","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Liverpool","key":"/Soccer/countries/England/Liverpool/Liverpool","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/England/Liverpool/Liverpool","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]}]}]},{"title":"country","key":"/Soccer/country","isFolder":false,"isLazy":false,"tooltip":"/Soccer/country","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"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,"children":[{"title":"RFPL","key":"/Soccer/country/Russia/RFPL","isFolder":false,"isLazy":false,"tooltip":"/Soccer/country/Russia/RFPL","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"others","key":"/Soccer/country/Russia/RFPL/others","isFolder":false,"isLazy":false,"tooltip":"/Soccer/country/Russia/RFPL/others","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Krilya","key":"/Soccer/country/Russia/RFPL/others/Krilya","isFolder":false,"isLazy":false,"tooltip":"/Soccer/country/Russia/RFPL/others/Krilya","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Amkar","key":"/Soccer/country/Russia/RFPL/others/Amkar","isFolder":false,"isLazy":false,"tooltip":"/Soccer/country/Russia/RFPL/others/Amkar","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,"children":[{"title":"Manchester","key":"/Soccer/country/England/Manchester","isFolder":false,"isLazy":false,"tooltip":"/Soccer/country/England/Manchester","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"MU","key":"/Soccer/country/England/Manchester/MU","isFolder":false,"isLazy":false,"tooltip":"/Soccer/country/England/Manchester/MU","href":null,"icon":null,"addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]}]}]}]}]'
        cache_json = '[{"title":"Krilya","key":"/soccer/country/Russia/RFPL/others/Krilya","isFolder":false,"isLazy":false,"tooltip":"/soccer/country/Russia/RFPL/others/Krilya","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Amkar","key":"/soccer/country/Russia/RFPL/others/Amkar","isFolder":false,"isLazy":false,"tooltip":"/soccer/country/Russia/RFPL/others/Amkar","href":null,"icon":"../../css/warning-icon.png","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,"children":[{"title":"countries","key":"/Soccer/countries","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries","href":null,"icon":"","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Russia","key":"/Soccer/countries/Russia","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"RFPL","key":"/Soccer/countries/Russia/RFPL","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Tomsk","key":"/Soccer/countries/Russia/RFPL/Tomsk","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Tomsk","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false},{"title":"Moscow","key":"/Soccer/countries/Russia/RFPL/Moscow","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Moscow","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Spartak","key":"/Soccer/countries/Russia/RFPL/Moscow/Spartak","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Moscow/Spartak","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]},{"title":"Saint-Petersburg","key":"/Soccer/countries/Russia/RFPL/Saint-Petersburg","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Saint-Petersburg","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"Zenit","key":"/Soccer/countries/Russia/RFPL/Saint-Petersburg/Zenit","isFolder":false,"isLazy":false,"tooltip":"/Soccer/countries/Russia/RFPL/Saint-Petersburg/Zenit","href":null,"icon":"../../css/delete-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]}]}]}]}]},{"title":"MU","key":"/soccer/country/England/Manchester/MU","isFolder":false,"isLazy":false,"tooltip":"/soccer/country/England/Manchester/MU","href":null,"icon":"../../css/warning-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false,"children":[{"title":"12","key":"/soccer/country/England/Manchester/MU/12","isFolder":false,"isLazy":false,"tooltip":"/soccer/country/England/Manchester/MU/12","href":null,"icon":"../../css/add-icon.png","addClass":null,"noLink":false,"activate":false,"focus":false,"expand":true,"select":false,"hideCheckbox":false,"unselectable":false}]}]'
        db_tree = DBTree("", db_json)
        cache_tree = CacheTree(cache_json)

        cache_tree.save(db_tree)
        print("Cache Tree changes has been saved.")
        tree_json = db_tree.get_json()
        self.assertEqual('[{"title": "Soccer", "tooltip": "/Soccer", "key": "/Soccer", "expand": true, "icon": null, "children": [{"title": "countries", "tooltip": "/Soccer/countries", "key": "/Soccer/countries", "expand": true, "icon": null, "children": [{"title": "Russia", "tooltip": "/Soccer/countries/Russia", "key": "/Soccer/countries/Russia", "expand": true, "icon": "../../css/delete-icon.png", "children": [{"title": "RFPL", "tooltip": "/Soccer/countries/Russia/RFPL", "key": "/Soccer/countries/Russia/RFPL", "expand": true, "icon": "../../css/delete-icon.png", "children": [{"title": "Moscow", "tooltip": "/Soccer/countries/Russia/RFPL/Moscow", "key": "/Soccer/countries/Russia/RFPL/Moscow", "expand": true, "icon": "../../css/delete-icon.png", "children": [{"title": "CSKA", "tooltip": "/Soccer/countries/Russia/RFPL/Moscow/CSKA", "key": "/Soccer/countries/Russia/RFPL/Moscow/CSKA", "expand": true, "icon": "../../css/delete-icon.png", "children": []}, {"title": "Lokomotiv", "tooltip": "/Soccer/countries/Russia/RFPL/Moscow/Lokomotiv", "key": "/Soccer/countries/Russia/RFPL/Moscow/Lokomotiv", "expand": true, "icon": "../../css/delete-icon.png", "children": []}, {"title": "Dinamo", "tooltip": "/Soccer/countries/Russia/RFPL/Moscow/Dinamo", "key": "/Soccer/countries/Russia/RFPL/Moscow/Dinamo", "expand": true, "icon": "../../css/delete-icon.png", "children": []}, {"title": "Spartak", "tooltip": "/Soccer/countries/Russia/RFPL/Moscow/Spartak", "key": "/Soccer/countries/Russia/RFPL/Moscow/Spartak", "expand": true, "icon": "../../css/delete-icon.png", "children": []}]}, {"title": "Saint-Petersburg", "tooltip": "/Soccer/countries/Russia/RFPL/Saint-Petersburg", "key": "/Soccer/countries/Russia/RFPL/Saint-Petersburg", "expand": true, "icon": "../../css/delete-icon.png", "children": [{"title": "Zenit", "tooltip": "/Soccer/countries/Russia/RFPL/Saint-Petersburg/Zenit", "key": "/Soccer/countries/Russia/RFPL/Saint-Petersburg/Zenit", "expand": true, "icon": "../../css/delete-icon.png", "children": []}]}, {"title": "Krasnodar", "tooltip": "/Soccer/countries/Russia/RFPL/Krasnodar", "key": "/Soccer/countries/Russia/RFPL/Krasnodar", "expand": true, "icon": "../../css/delete-icon.png", "children": [{"title": "Kuban", "tooltip": "/Soccer/countries/Russia/RFPL/Krasnodar/Kuban", "key": "/Soccer/countries/Russia/RFPL/Krasnodar/Kuban", "expand": true, "icon": "../../css/delete-icon.png", "children": []}, {"title": "Krasnodar", "tooltip": "/Soccer/countries/Russia/RFPL/Krasnodar/Krasnodar", "key": "/Soccer/countries/Russia/RFPL/Krasnodar/Krasnodar", "expand": true, "icon": "../../css/delete-icon.png", "children": []}]}, {"title": "Tomsk", "tooltip": "/Soccer/countries/Russia/RFPL/Tomsk", "key": "/Soccer/countries/Russia/RFPL/Tomsk", "expand": true, "icon": "../../css/delete-icon.png", "children": [{"title": "Tom", "tooltip": "/Soccer/countries/Russia/RFPL/Tomsk/Tom", "key": "/Soccer/countries/Russia/RFPL/Tomsk/Tom", "expand": true, "icon": "../../css/delete-icon.png", "children": []}]}, {"title": "others", "tooltip": "/Soccer/countries/Russia/RFPL/others", "key": "/Soccer/countries/Russia/RFPL/others", "expand": true, "icon": "../../css/delete-icon.png", "children": [{"title": "Rubin", "tooltip": "/Soccer/countries/Russia/RFPL/others/Rubin", "key": "/Soccer/countries/Russia/RFPL/others/Rubin", "expand": true, "icon": "../../css/delete-icon.png", "children": []}, {"title": "Ural", "tooltip": "/Soccer/countries/Russia/RFPL/others/Ural", "key": "/Soccer/countries/Russia/RFPL/others/Ural", "expand": true, "icon": "../../css/delete-icon.png", "children": []}, {"title": "Terek", "tooltip": "/Soccer/countries/Russia/RFPL/others/Terek", "key": "/Soccer/countries/Russia/RFPL/others/Terek", "expand": true, "icon": "../../css/delete-icon.png", "children": []}, {"title": "Amkar", "tooltip": "/Soccer/countries/Russia/RFPL/others/Amkar", "key": "/Soccer/countries/Russia/RFPL/others/Amkar", "expand": true, "icon": "../../css/delete-icon.png", "children": []}, {"title": "Krilya", "tooltip": "/Soccer/countries/Russia/RFPL/others/Krilya", "key": "/Soccer/countries/Russia/RFPL/others/Krilya", "expand": true, "icon": "../../css/delete-icon.png", "children": []}]}]}]}, {"title": "England", "tooltip": "/Soccer/countries/England", "key": "/Soccer/countries/England", "expand": true, "icon": null, "children": [{"title": "Manchester", "tooltip": "/Soccer/countries/England/Manchester", "key": "/Soccer/countries/England/Manchester", "expand": true, "icon": null, "children": [{"title": "MC", "tooltip": "/Soccer/countries/England/Manchester/MC", "key": "/Soccer/countries/England/Manchester/MC", "expand": true, "icon": null, "children": []}, {"title": "MU", "tooltip": "/Soccer/countries/England/Manchester/MU", "key": "/Soccer/countries/England/Manchester/MU", "expand": true, "icon": null, "children": []}]}, {"title": "London", "tooltip": "/Soccer/countries/England/London", "key": "/Soccer/countries/England/London", "expand": true, "icon": null, "children": [{"title": "Is_the_capital_of_Great_Britain", "tooltip": "/Soccer/countries/England/London/Is_the_capital_of_Great_Britain", "key": "/Soccer/countries/England/London/Is_the_capital_of_Great_Britain", "expand": true, "icon": null, "children": []}, {"title": "Arsenal", "tooltip": "/Soccer/countries/England/London/Arsenal", "key": "/Soccer/countries/England/London/Arsenal", "expand": true, "icon": null, "children": []}, {"title": "Chelsea", "tooltip": "/Soccer/countries/England/London/Chelsea", "key": "/Soccer/countries/England/London/Chelsea", "expand": true, "icon": null, "children": []}, {"title": "Totenham", "tooltip": "/Soccer/countries/England/London/Totenham", "key": "/Soccer/countries/England/London/Totenham", "expand": true, "icon": null, "children": []}, {"title": "Fulham", "tooltip": "/Soccer/countries/England/London/Fulham", "key": "/Soccer/countries/England/London/Fulham", "expand": true, "icon": null, "children": []}]}, {"title": "Liverpool", "tooltip": "/Soccer/countries/England/Liverpool", "key": "/Soccer/countries/England/Liverpool", "expand": true, "icon": null, "children": [{"title": "Liverpool", "tooltip": "/Soccer/countries/England/Liverpool/Liverpool", "key": "/Soccer/countries/England/Liverpool/Liverpool", "expand": true, "icon": null, "children": []}]}]}]}, {"title": "country", "tooltip": "/Soccer/country", "key": "/Soccer/country", "expand": true, "icon": null, "children": [{"title": "Russia", "tooltip": "/Soccer/country/Russia", "key": "/Soccer/country/Russia", "expand": true, "icon": null, "children": [{"title": "RFPL", "tooltip": "/Soccer/country/Russia/RFPL", "key": "/Soccer/country/Russia/RFPL", "expand": true, "icon": null, "children": [{"title": "others", "tooltip": "/Soccer/country/Russia/RFPL/others", "key": "/Soccer/country/Russia/RFPL/others", "expand": true, "icon": null, "children": [{"title": "Krilya", "tooltip": "/Soccer/country/Russia/RFPL/others/Krilya", "key": "/Soccer/country/Russia/RFPL/others/Krilya", "expand": true, "icon": "../../css/delete-icon.png", "children": []}, {"title": "Amkar", "tooltip": "/Soccer/country/Russia/RFPL/others/Amkar", "key": "/Soccer/country/Russia/RFPL/others/Amkar", "expand": true, "icon": null, "children": []}]}]}]}, {"title": "England", "tooltip": "/Soccer/country/England", "key": "/Soccer/country/England", "expand": true, "icon": null, "children": [{"title": "Manchester", "tooltip": "/Soccer/country/England/Manchester", "key": "/Soccer/country/England/Manchester", "expand": true, "icon": null, "children": [{"title": "MU", "tooltip": "/Soccer/country/England/Manchester/MU", "key": "/Soccer/country/England/Manchester/MU", "expand": true, "icon": null, "children": []}]}]}]}]}, {"title": "soccer", "tooltip": "/soccer", "key": "/soccer", "expand": true, "children": [{"title": "country", "tooltip": "/soccer/country", "key": "/soccer/country", "expand": true, "children": [{"title": "Russia", "tooltip": "/soccer/country/Russia", "key": "/soccer/country/Russia", "expand": true, "children": [{"title": "RFPL", "tooltip": "/soccer/country/Russia/RFPL", "key": "/soccer/country/Russia/RFPL", "expand": true, "children": [{"title": "others", "tooltip": "/soccer/country/Russia/RFPL/others", "key": "/soccer/country/Russia/RFPL/others", "expand": true, "children": [{"title": "Krilya", "tooltip": "/soccer/country/Russia/RFPL/others/Krilya", "key": "/soccer/country/Russia/RFPL/others/Krilya", "expand": true, "icon": "../../css/delete-icon.png", "children": []}, {"title": "Amkar", "tooltip": "/soccer/country/Russia/RFPL/others/Amkar", "key": "/soccer/country/Russia/RFPL/others/Amkar", "expand": true, "children": []}]}]}]}, {"title": "England", "tooltip": "/soccer/country/England", "key": "/soccer/country/England", "expand": true, "children": [{"title": "Manchester", "tooltip": "/soccer/country/England/Manchester", "key": "/soccer/country/England/Manchester", "expand": true, "children": [{"title": "MU", "tooltip": "/soccer/country/England/Manchester/MU", "key": "/soccer/country/England/Manchester/MU", "expand": true, "children": [{"title": "12", "tooltip": "/soccer/country/England/Manchester/MU/12", "key": "/soccer/country/England/Manchester/MU/12", "expand": true, "children": []}]}]}]}]}]}]', tree_json)
Esempio n. 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)
Esempio n. 4
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)
Esempio n. 5
0
def save_cache_changes(request):
    """
        Function simulates the save Cache Tree changes into DB Tree.
        INPUT POST parameters:
        1) [mandatory] cache_data -- current content of Cache Tree in JSON format;
        2) [mandatory] db_data -- current content of DB Tree in JSON format.

        :returns updated DB Tree in JSON format.
    """
    cache_data = get_str_param(request, 'cache_data')
    db_data = get_str_param(request, 'db_data')
    logger.debug("Save request received:\n Current DB data={};\nCurrent Cache data: {} ".format(db_data, cache_data))

    db_tree = DBTree("", db_data)
    cache_tree = CacheTree(cache_data)
    cache_tree.save_by_key(db_tree)
    logger.info("Cache Tree changes has been saved.")
    tree_json = db_tree.get_json()
    logger.debug("Response JSON has been built: {}".format(tree_json))
    return send_json(tree_json)
Esempio n. 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)
Esempio n. 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)
Esempio n. 8
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))
Esempio n. 9
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)