def test_find(self): # init catalog = Catalog('fake', force=True, debug=False) top = catalog._restore_json(get_fakecatalog()) noder = Noder() # create fake args args = { '<term>': '7544G', '--script': True, '--verbose': True, '--parent': False, '--directory': False, '--path': None, '--format': 'native' } # try to find something found = cmd_find(args, noder, top) self.assertTrue(len(found) > 0) # try to find something that does not exist args['<term>'] = 'verynotfoundnote' found = cmd_find(args, noder, top) self.assertTrue(len(found) == 0)
def test_rm(self): # init path = 'fake' self.addCleanup(clean, path) catalog = Catalog(path, force=True, debug=False) top = catalog._restore_json(get_fakecatalog()) noder = Noder() # create fake args dict args = {'<path>': '', '--recursive': False, '--verbose': True} # list files and make sure there are children args['<path>'] = '' found = cmd_ls(args, noder, top) self.assertTrue(len(found) > 0) self.assertTrue(len(top.children) == 1) # rm a not existing storage args['<storage>'] = 'abc' top = cmd_rm(args, noder, catalog, top) # rm a storage args['<storage>'] = 'tmpdir' top = cmd_rm(args, noder, catalog, top) # ensure there no children anymore self.assertTrue(len(top.children) == 0)
def test_ls(self): # init path = 'fake' self.addCleanup(clean, path) catalog = Catalog(path, force=True, debug=False) top = catalog._restore_json(get_fakecatalog()) noder = Noder() # create fake args args = {'<path>': '', '--recursive': False, '--verbose': True} # list root args['<path>'] = '' found = cmd_ls(args, noder, top) self.assertTrue(len(found) > 0) # list tmpdir that should have 5 children args['<path>'] = '/tmpdir' found = cmd_ls(args, noder, top) self.assertTrue(len(found) == 5) # list folder that should have 2 children args['<path>'] = '/tmpdir/P4C' found = cmd_ls(args, noder, top) self.assertTrue(len(found) == 2) # list folder that should have 1 children args['<path>'] = '/tmpdir/VNN' found = cmd_ls(args, noder, top) self.assertTrue(len(found) == 1) # test not existing path args['<path>'] = 'itdoesnotexist' found = cmd_ls(args, noder, top) self.assertTrue(len(found) == 0)
def test_tree(self): # init path = 'fake' self.addCleanup(clean, path) catalog = Catalog(path, force=True, verbose=False) top = catalog._restore_json(get_fakecatalog()) noder = Noder() # create fake args dict args = {'<path>': path, '--verbose': True} # print tree and wait for any errors cmd_tree(args, noder, top)
def test_graph(self): # init path = 'fake' gpath = tempfile.gettempdir() + os.sep + 'graph.dot' self.addCleanup(clean, path) self.addCleanup(clean, gpath) catalog = Catalog(path, force=True, verbose=False) top = catalog._restore_json(get_fakecatalog()) noder = Noder() # create fake args dict args = {'<path>': gpath, '--verbose': True} # create the graph cmd_graph(args, noder, top) # ensure file exists self.assertTrue(os.path.exists(gpath))