2017-12-14 18:37:31 +00:00
|
|
|
"""
|
|
|
|
author: deadc0de6 (https://github.com/deadc0de6)
|
|
|
|
Copyright (c) 2017, deadc0de6
|
|
|
|
|
|
|
|
Basic unittest for rm
|
|
|
|
"""
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2019-02-16 12:54:00 +00:00
|
|
|
from catcli.catcli import cmd_rm, cmd_ls
|
2017-12-14 18:37:31 +00:00
|
|
|
from catcli.noder import Noder
|
|
|
|
from catcli.catalog import Catalog
|
2019-02-16 12:54:00 +00:00
|
|
|
from tests.helpers import clean, get_fakecatalog
|
2017-12-14 18:37:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestRm(unittest.TestCase):
|
2022-10-20 20:01:37 +00:00
|
|
|
"""test rm"""
|
2017-12-14 18:37:31 +00:00
|
|
|
|
|
|
|
def test_rm(self):
|
2022-10-20 20:01:37 +00:00
|
|
|
"""test rm"""
|
2017-12-14 18:37:31 +00:00
|
|
|
# init
|
|
|
|
path = 'fake'
|
|
|
|
self.addCleanup(clean, path)
|
2020-03-27 13:33:06 +00:00
|
|
|
catalog = Catalog(path, force=True, debug=False)
|
2017-12-14 18:37:31 +00:00
|
|
|
top = catalog._restore_json(get_fakecatalog())
|
|
|
|
noder = Noder()
|
|
|
|
|
|
|
|
# create fake args dict
|
2017-12-14 19:02:24 +00:00
|
|
|
args = {'<path>': '', '--recursive': False,
|
2022-01-15 13:41:45 +00:00
|
|
|
'--verbose': True,
|
2022-08-16 12:17:30 +00:00
|
|
|
'--format': 'native',
|
|
|
|
'--raw-size': False}
|
2017-12-14 18:37:31 +00:00
|
|
|
|
|
|
|
# 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 main():
|
2022-10-20 20:01:37 +00:00
|
|
|
"""entry point"""
|
2017-12-14 18:37:31 +00:00
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|