|
|
@ -12,7 +12,7 @@ from catcli.catcli import cmd_index, cmd_update
|
|
|
|
from catcli.noder import Noder
|
|
|
|
from catcli.noder import Noder
|
|
|
|
from catcli.catalog import Catalog
|
|
|
|
from catcli.catalog import Catalog
|
|
|
|
from tests.helpers import create_dir, create_rnd_file, get_tempdir, \
|
|
|
|
from tests.helpers import create_dir, create_rnd_file, get_tempdir, \
|
|
|
|
clean, unix_tree, edit_file, read_from_file
|
|
|
|
clean, unix_tree, edit_file, read_from_file, md5sum
|
|
|
|
import anytree
|
|
|
|
import anytree
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -31,6 +31,7 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
f1 = create_rnd_file(dirpath, 'file1')
|
|
|
|
f1 = create_rnd_file(dirpath, 'file1')
|
|
|
|
f2 = create_rnd_file(dirpath, 'file2')
|
|
|
|
f2 = create_rnd_file(dirpath, 'file2')
|
|
|
|
f3 = create_rnd_file(dirpath, 'file3')
|
|
|
|
f3 = create_rnd_file(dirpath, 'file3')
|
|
|
|
|
|
|
|
f4 = create_rnd_file(dirpath, 'file4')
|
|
|
|
|
|
|
|
|
|
|
|
# create 2 directories
|
|
|
|
# create 2 directories
|
|
|
|
d1 = create_dir(dirpath, 'dir1')
|
|
|
|
d1 = create_dir(dirpath, 'dir1')
|
|
|
@ -45,6 +46,12 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
top = noder.new_top_node()
|
|
|
|
top = noder.new_top_node()
|
|
|
|
catalog = Catalog(catalogpath, force=True, verbose=False)
|
|
|
|
catalog = Catalog(catalogpath, force=True, verbose=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# get checksums
|
|
|
|
|
|
|
|
f4_md5 = md5sum(f4)
|
|
|
|
|
|
|
|
self.assertTrue(f4_md5)
|
|
|
|
|
|
|
|
d1f1_md5 = md5sum(d1f1)
|
|
|
|
|
|
|
|
self.assertTrue(d1f1_md5)
|
|
|
|
|
|
|
|
|
|
|
|
# create fake args
|
|
|
|
# create fake args
|
|
|
|
tmpdirname = 'tmpdir'
|
|
|
|
tmpdirname = 'tmpdir'
|
|
|
|
args = {'<path>': dirpath, '<name>': tmpdirname,
|
|
|
|
args = {'<path>': dirpath, '<name>': tmpdirname,
|
|
|
@ -56,6 +63,13 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
cmd_index(args, noder, catalog, top, debug=True)
|
|
|
|
cmd_index(args, noder, catalog, top, debug=True)
|
|
|
|
self.assertTrue(os.stat(catalogpath).st_size != 0)
|
|
|
|
self.assertTrue(os.stat(catalogpath).st_size != 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ensure md5 sum are in
|
|
|
|
|
|
|
|
nods = noder.find_name(top, os.path.basename(f4))
|
|
|
|
|
|
|
|
self.assertTrue(len(nods) == 1)
|
|
|
|
|
|
|
|
nod = nods[0]
|
|
|
|
|
|
|
|
self.assertTrue(nod)
|
|
|
|
|
|
|
|
self.assertTrue(nod.md5 == f4_md5)
|
|
|
|
|
|
|
|
|
|
|
|
# print catalog
|
|
|
|
# print catalog
|
|
|
|
noder.print_tree(top)
|
|
|
|
noder.print_tree(top)
|
|
|
|
|
|
|
|
|
|
|
@ -70,6 +84,19 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
# modify files
|
|
|
|
# modify files
|
|
|
|
EDIT = 'edited'
|
|
|
|
EDIT = 'edited'
|
|
|
|
edit_file(d1f1, EDIT)
|
|
|
|
edit_file(d1f1, EDIT)
|
|
|
|
|
|
|
|
d1f1_md5_new = md5sum(d1f1)
|
|
|
|
|
|
|
|
self.assertTrue(d1f1_md5_new)
|
|
|
|
|
|
|
|
self.assertTrue(d1f1_md5_new != d1f1_md5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# change file without mtime
|
|
|
|
|
|
|
|
maccess = os.path.getmtime(f4)
|
|
|
|
|
|
|
|
EDIT = 'edited'
|
|
|
|
|
|
|
|
edit_file(f4, EDIT)
|
|
|
|
|
|
|
|
# reset edit time
|
|
|
|
|
|
|
|
os.utime(f4, (maccess, maccess))
|
|
|
|
|
|
|
|
f4_md5_new = md5sum(d1f1)
|
|
|
|
|
|
|
|
self.assertTrue(f4_md5_new)
|
|
|
|
|
|
|
|
self.assertTrue(f4_md5_new != f4_md5)
|
|
|
|
|
|
|
|
|
|
|
|
# update storage
|
|
|
|
# update storage
|
|
|
|
cmd_update(args, noder, catalog, top, debug=True)
|
|
|
|
cmd_update(args, noder, catalog, top, debug=True)
|
|
|
@ -81,7 +108,23 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
# explore the top node to find all nodes
|
|
|
|
# explore the top node to find all nodes
|
|
|
|
self.assertTrue(len(top.children) == 1)
|
|
|
|
self.assertTrue(len(top.children) == 1)
|
|
|
|
storage = top.children[0]
|
|
|
|
storage = top.children[0]
|
|
|
|
self.assertTrue(len(storage.children) == 7)
|
|
|
|
self.assertTrue(len(storage.children) == 8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ensure d1f1 md5 sum has changed in catalog
|
|
|
|
|
|
|
|
nods = noder.find_name(top, os.path.basename(d1f1))
|
|
|
|
|
|
|
|
self.assertTrue(len(nods) == 1)
|
|
|
|
|
|
|
|
nod = nods[0]
|
|
|
|
|
|
|
|
self.assertTrue(nod)
|
|
|
|
|
|
|
|
self.assertTrue(nod.md5 != d1f1_md5)
|
|
|
|
|
|
|
|
self.assertTrue(nod.md5 == d1f1_md5_new)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ensure f4 md5 sum has changed in catalog
|
|
|
|
|
|
|
|
nods = noder.find_name(top, os.path.basename(f4))
|
|
|
|
|
|
|
|
self.assertTrue(len(nods) == 1)
|
|
|
|
|
|
|
|
nod = nods[0]
|
|
|
|
|
|
|
|
self.assertTrue(nod)
|
|
|
|
|
|
|
|
self.assertTrue(nod.md5 != f4_md5)
|
|
|
|
|
|
|
|
self.assertTrue(nod.md5 == f4_md5_new)
|
|
|
|
|
|
|
|
|
|
|
|
# ensures files and directories are in
|
|
|
|
# ensures files and directories are in
|
|
|
|
names = [node.name for node in anytree.PreOrderIter(storage)]
|
|
|
|
names = [node.name for node in anytree.PreOrderIter(storage)]
|
|
|
@ -89,6 +132,7 @@ class TestIndexing(unittest.TestCase):
|
|
|
|
self.assertTrue(os.path.basename(f1) in names)
|
|
|
|
self.assertTrue(os.path.basename(f1) in names)
|
|
|
|
self.assertTrue(os.path.basename(f2) in names)
|
|
|
|
self.assertTrue(os.path.basename(f2) in names)
|
|
|
|
self.assertTrue(os.path.basename(f3) in names)
|
|
|
|
self.assertTrue(os.path.basename(f3) in names)
|
|
|
|
|
|
|
|
self.assertTrue(os.path.basename(f4) in names)
|
|
|
|
self.assertTrue(os.path.basename(d1) in names)
|
|
|
|
self.assertTrue(os.path.basename(d1) in names)
|
|
|
|
self.assertTrue(os.path.basename(d1f1) in names)
|
|
|
|
self.assertTrue(os.path.basename(d1f1) in names)
|
|
|
|
self.assertTrue(os.path.basename(d1f2) in names)
|
|
|
|
self.assertTrue(os.path.basename(d1f2) in names)
|
|
|
|