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))
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)