diff options
author | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-01-20 23:10:13 -0500 |
---|---|---|
committer | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-01-20 23:11:23 -0500 |
commit | 4321e9dcadf929b81b6528b7cb3174c80772b5aa (patch) | |
tree | e4cf2327ee08238e5eac016dccfdc33469cf3f4e /tests/events_test.py | |
parent | 94596f0913cfdc33ffc85aac1005ea745d6559f8 (diff) |
fleshed out the on_modified function in the ComboxEventHandler class + wrote tests for it.
modified: combox/events.py
modified: tests/events_test.py
new file: tests/files/ipsum.txt
new file: tests/files/lorem.txt
Diffstat (limited to 'tests/events_test.py')
-rw-r--r-- | tests/events_test.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/events_test.py b/tests/events_test.py index 37615a9..c53ce1d 100644 --- a/tests/events_test.py +++ b/tests/events_test.py @@ -29,7 +29,9 @@ from watchdog.observers import Observer from combox.events import ComboxEventHandler from combox.config import get_nodedirs -from combox.file import relative_path, purge_dir +from combox.crypto import decrypt_and_glue +from combox.file import (relative_path, purge_dir, + read_file, write_file) CONFIG_DIR = path.join('tests', 'test-config') @@ -178,5 +180,37 @@ def test_CEH(): path_deletedp(TEST_DIR_1, True) path_deletedp(TEST_DIR_0, True) + + # Test - file modification + lorem_file = path.join(FILES_DIR, 'lorem.txt') + lorem_file_copy = "%s.copy" % lorem_file + # this will shard lorem.txt.copy in the node directories. + copyfile(lorem_file, lorem_file_copy) + time.sleep(1) + shardedp(lorem_file_copy) + + ipsum_file = path.join(FILES_DIR, 'ipsum.txt') + ipsum_content = read_file(ipsum_file) + lorem_content = read_file(lorem_file_copy) + lorem_content = "%s\n%s" % (lorem_content, ipsum_content) + + # write lorem's new content to lorem_file_copy + write_file(lorem_file_copy, lorem_content) + time.sleep(1) + + # decrypt_and_glue will decrypt the file shards, glues them and + # writes it to the respective file + decrypt_and_glue(lorem_file_copy, config) + time.sleep(1) + + lorem_content_from_disk = read_file(lorem_file_copy) + assert lorem_content == lorem_content_from_disk + + # remove lorem_file_copy and confirm that its shards are deleted + # in the node directories. + remove(lorem_file_copy) + time.sleep(1) + path_deletedp(lorem_file_copy) + observer.stop() observer.join() |