From cba72d5cf6b7a1a2c96a0512929ba8d1cfda02e8 Mon Sep 17 00:00:00 2001 From: Siddharth Ravikumar Date: Fri, 16 Jan 2015 09:26:55 -0500 Subject: tests/events_test.py: wrote test for file/directory rename under combox directory. --- tests/events_test.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/events_test.py') diff --git a/tests/events_test.py b/tests/events_test.py index f143c9e..8dce21c 100644 --- a/tests/events_test.py +++ b/tests/events_test.py @@ -65,6 +65,34 @@ def dirp(d): directory = path.join(node, rel_path) assert path.isdir(directory) +def renamedp(old_p, new_p): + """ + Checks if the file shards or directory were/was renamed in the under the node directories. + + old_p: old path to directory or file under combox directory. + new_p: new (present) path to the directory or file under combox directory. + """ + + nodes = get_nodedirs(config) + + is_dir = True if path.isdir(new_p) else False + i = 0 + + for node in nodes: + old_rel_path = relative_path(old_p, config) + new_rel_path = relative_path(new_p, config) + + if is_dir: + old_path = path.join(node, old_rel_path) + new_path = path.join(node, new_rel_path) + else: + old_path = "%s.shard%s" % (path.join(node, old_rel_path), i) + new_path = "%s.shard%s" % (path.join(node, new_rel_path), i) + i += 1 + + assert not path.exists(old_path) + assert path.exists(new_path) + def path_deletedp(p): """ @@ -133,6 +161,15 @@ def test_CEH(): time.sleep(1) shardedp(TEST_FILE_COPY_1) + # Test - dir rename + TEST_DIR_1_NEW = path.join(path.dirname(TEST_DIR_1), + 'snafu') + TEST_FILE_COPY_1_NEW = path.join(TEST_DIR_1_NEW, path.basename(TEST_FILE)) + os.rename(TEST_DIR_1, TEST_DIR_1_NEW) + time.sleep(1) + renamedp(TEST_DIR_1, TEST_DIR_1_NEW) + renamedp(TEST_FILE_COPY_1, TEST_FILE_COPY_1_NEW) + # Test directory & file deletion purge_dir(TEST_DIR_0) # remove the directory itself. -- cgit v1.2.3