def test_two_nested_dirs_one_file(self): mkdir(os.path.join(self.root, 'foo')) mkdir(os.path.join(self.root, 'foo', 'bar')) mkfile(os.path.join(self.root, 'foo', 'bar', 'spam')) expected = { 'data': ROOT_NAME, 'attr': {'href': '/'}, 'children': [ { 'data': 'foo', 'attr': {'href': '/foo'}, 'children': [ { 'data': 'bar', 'attr': {'href': '/foo/bar'}, 'children': [ { 'data': 'spam', 'attr': {'href': '/foo/bar/spam'}, } ], }, ] } ], } result = jstree.generate_tree(self.root) self.assertEquals(result, expected)
def test_empty_directory(self): expected = { 'data': ROOT_NAME, 'attr': {'href': '/'}, 'children': [], } result = jstree.generate_tree(self.root) self.assertEquals(result, expected)
def test_one_file(self): mkfile(os.path.join(self.root, 'foo')) expected = { 'data': ROOT_NAME, 'attr': {'href': '/'}, 'children': [{ 'data': 'foo', 'attr': {'href': '/foo'}, }], } result = jstree.generate_tree(self.root) self.assertEquals(result, expected)
def jstree(): tree = generate_tree(app.config['TEST_ROOT']) return (json.dumps(tree), 200)