예제 #1
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)
예제 #2
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)