summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSiddharth Ravikumar <sravik@bgsu.edu>2015-01-20 23:10:13 -0500
committerSiddharth Ravikumar <sravik@bgsu.edu>2015-01-20 23:11:23 -0500
commit4321e9dcadf929b81b6528b7cb3174c80772b5aa (patch)
treee4cf2327ee08238e5eac016dccfdc33469cf3f4e /tests
parent94596f0913cfdc33ffc85aac1005ea745d6559f8 (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')
-rw-r--r--tests/events_test.py36
-rw-r--r--tests/files/ipsum.txt40
-rw-r--r--tests/files/lorem.txt15
3 files changed, 90 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()
diff --git a/tests/files/ipsum.txt b/tests/files/ipsum.txt
new file mode 100644
index 0000000..1ce990e
--- /dev/null
+++ b/tests/files/ipsum.txt
@@ -0,0 +1,40 @@
+Vivamus fermentum semper porta. Nunc diam velit, adipiscing ut
+tristique vitae, sagittis vel odio. Maecenas convallis ullamcorper
+ultricies. Curabitur ornare, ligula semper consectetur sagittis, nisi
+diam iaculis velit, id fringilla sem nunc vel mi. Nam dictum, odio nec
+pretium volutpat, arcu ante placerat erat, non tristique elit urna et
+turpis. Quisque mi metus, ornare sit amet fermentum et, tincidunt et
+orci. Fusce eget orci a orci congue vestibulum. Ut dolor diam,
+elementum et vestibulum eu, porttitor vel elit. Curabitur venenatis
+pulvinar tellus gravida ornare. Sed et erat faucibus nunc euismod
+ultricies ut id justo. Nullam cursus suscipit nisi, et ultrices justo
+sodales nec. Fusce venenatis facilisis lectus ac semper. Aliquam at
+massa ipsum. Quisque bibendum purus convallis nulla ultrices
+ultricies. Nullam aliquam, mi eu aliquam tincidunt, purus velit
+laoreet tortor, viverra pretium nisi quam vitae mi. Fusce vel volutpat
+elit. Nam sagittis nisi dui.
+
+- Suspendisse lectus leo, consectetur in tempor sit amet, placerat
+ quis neque. Etiam luctus porttitor lorem, sed suscipit est rutrum
+ non. Curabitur lobortis nisl a enim congue semper. Aenean commodo
+ ultrices imperdiet. Vestibulum ut justo vel sapien venenatis
+ tincidunt. Phasellus eget dolor sit amet ipsum dapibus condimentum
+ vitae quis lectus. Aliquam ut massa in turpis dapibus
+ convallis. Praesent elit lacus, vestibulum at malesuada et, ornare
+ et est. Ut augue nunc, sodales ut euismod non, adipiscing vitae
+ orci. Mauris ut placerat justo. Mauris in ultricies enim. Quisque
+ nec est eleifend nulla ultrices egestas quis ut quam. Donec
+ sollicitudin lectus a mauris pulvinar id aliquam urna cursus. Cras
+ quis ligula sem, vel elementum mi. Phasellus non ullamcorper urna.
+
+- Class aptent taciti sociosqu ad litora torquent per conubia nostra,
+ per inceptos himenaeos. In euismod ultrices facilisis. Vestibulum
+ porta sapien adipiscing augue congue id pretium lectus
+ molestie. Proin quis dictum nisl. Morbi id quam sapien, sed
+ vestibulum sem. Duis elementum rutrum mauris sed convallis. Proin
+ vestibulum magna mi. Aenean tristique hendrerit magna, ac facilisis
+ nulla hendrerit ut. Sed non tortor sodales quam auctor
+ elementum. Donec hendrerit nunc eget elit pharetra
+ pulvinar. Suspendisse id tempus tortor. Aenean luctus, elit commodo
+ laoreet commodo, justo nisi consequat massa, sed vulputate quam urna
+ quis eros. Donec vel.
diff --git a/tests/files/lorem.txt b/tests/files/lorem.txt
new file mode 100644
index 0000000..6d2ed7b
--- /dev/null
+++ b/tests/files/lorem.txt
@@ -0,0 +1,15 @@
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam
+lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam
+viverra nec consectetur ante hendrerit. Donec et mollis
+dolor. Praesent et diam eget libero egestas mattis sit amet vitae
+augue. Nam tincidunt congue enim, ut porta lorem lacinia
+consectetur. Donec ut libero sed arcu vehicula ultricies a non
+tortor. Lorem ipsum dolor sit amet, consectetur adipiscing
+elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed,
+adipiscing id dolor. Pellentesque auctor nisi id magna consequat
+sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt
+feugiat nisl imperdiet. Ut convallis libero in urna ultrices
+accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at
+malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis
+parturient montes, nascetur ridiculus mus. In rutrum accumsan
+ultricies. Mauris vitae nisi at sem facilisis semper ac in est.