fix when there is no gallery dir
[redakcja.git] / lib / vstorage / tests.py
index 23375f0..3ef8c4d 100644 (file)
@@ -8,12 +8,9 @@
 import os
 import tempfile
 from nose.tools import *
 import os
 import tempfile
 from nose.tools import *
-from nose.core import runmodule
 
 import vstorage
 
 
 import vstorage
 
-NULL_PARENT = -1
-
 
 def clear_directory(top):
     for root, dirs, files in os.walk(top, topdown=False):
 
 def clear_directory(top):
     for root, dirs, files in os.walk(top, topdown=False):
@@ -46,11 +43,12 @@ class TestVersionedStorage(object):
             text=text,
             author=author,
             comment=comment,
             text=text,
             author=author,
             comment=comment,
-            parent=NULL_PARENT,
+            parent=None,
         )
 
         )
 
-        saved = self.repo.open_page(title).read()
-        assert_equal(saved, text)
+        saved_text, rev = self.repo.page_text(title)
+        assert_equal(saved_text, text)
+        assert_equal(rev, 0)
 
     def test_save_text_noparent(self):
         text = u"test text"
 
     def test_save_text_noparent(self):
         text = u"test text"
@@ -58,26 +56,23 @@ class TestVersionedStorage(object):
         author = u"test author"
         comment = u"test comment"
 
         author = u"test author"
         comment = u"test comment"
 
-        self.repo.save_text(title=title,
-                    text=text, author=author,
-                    comment=comment, parent=None)
+        self.repo.save_text(title=title, text=text, author=author, comment=comment, parent=None)
 
 
-        saved = self.repo.open_page(title).read()
-        assert_equal(saved, text)
+        saved_text, rev = self.repo.page_text(title)
+        assert_equal(saved_text, text)
+        assert_equal(rev, 0)
 
     def test_save_merge_no_conflict(self):
         text = u"test\ntext"
         title = u"test title"
         author = u"test author"
         comment = u"test comment"
 
     def test_save_merge_no_conflict(self):
         text = u"test\ntext"
         title = u"test title"
         author = u"test author"
         comment = u"test comment"
-        self.repo.save_text(title=title,
-                    text=text, author=author,
-                    comment=comment, parent=NULL_PARENT)
-        self.repo.save_text(title=title,
-                    text=text, author=author,
-                    comment=comment, parent=NULL_PARENT)
-        saved = self.repo.open_page(title).read()
-        assert_equal(saved, text)
+        self.repo.save_text(title=title, text=text, author=author, comment=comment, parent=None)
+        self.repo.save_text(title=title, text=text, author=author, comment=comment, parent=None)
+
+        saved_text, rev = self.repo.page_text(title)
+        assert_equal(saved_text, text)
+        assert_equal(rev, 0)
 
     def test_save_merge_line_conflict(self):
         text = u"test\ntest\n"
 
     def test_save_merge_line_conflict(self):
         text = u"test\ntest\n"
@@ -87,22 +82,23 @@ class TestVersionedStorage(object):
         author = u"test author"
         comment = u"test comment"
 
         author = u"test author"
         comment = u"test comment"
 
-        self.repo.save_text(title=title,
-                    text=text, author=author,
-                    comment=comment, parent=NULL_PARENT)
+        self.repo.save_text(title=title, text=text, author=author, comment=comment, parent=None)
 
 
-        self.repo.save_text(title=title,
-                    text=text1, author=author,
-                    comment=comment, parent=0)
+        saved_text, rev = self.repo.page_text(title)
+        assert_equal(saved_text, text)
+        assert_equal(rev, 0)
 
 
-        self.repo.save_text(title=title,
-                    text=text2, author=author,
-                    comment=comment, parent=0)
+        self.repo.save_text(title=title, text=text1, author=author, comment=comment, parent=0)
 
 
-        saved = self.repo.open_page(title).read()
+        saved_text, rev = self.repo.page_text(title)
+        assert_equal(saved_text, text1)
+        assert_equal(rev, 1)
 
 
+        self.repo.save_text(title=title, text=text2, author=author, comment=comment, parent=0)
+
+        saved_text, rev = self.repo.page_text(title)
         # Other conflict markers placement can also be correct
         # Other conflict markers placement can also be correct
-        assert_equal(saved, u'''\
+        assert_equal(saved_text, u'''\
 text
 test
 <<<<<<< local
 text
 test
 <<<<<<< local
@@ -116,19 +112,17 @@ text
         title = u"test title"
         author = u"test author"
         comment = u"test comment"
         title = u"test title"
         author = u"test author"
         comment = u"test comment"
-        self.repo.save_text(title=title,
-                    text=text, author=author,
-                    comment=comment, parent=NULL_PARENT)
+        self.repo.save_text(title=title, text=text, author=author, comment=comment, parent=None)
 
 
-        assert title in self.repo
+        ok_(title in self.repo, "Document not in repository.")
 
         self.repo.delete_page(title, author, comment)
 
 
         self.repo.delete_page(title, author, comment)
 
-        assert title not in self.repo
+        ok_(title not in self.repo, "Document in repository after delete")
 
     @raises(vstorage.DocumentNotFound)
     def test_document_not_found(self):
 
     @raises(vstorage.DocumentNotFound)
     def test_document_not_found(self):
-        self.repo.open_page(u'unknown entity')
+        self.repo.page_text(u'unknown entity')
 
     def test_open_existing_repository(self):
         self.repo.save_text(title=u'Python!', text=u'ham and spam')
 
     def test_open_existing_repository(self):
         self.repo.save_text(title=u'Python!', text=u'ham and spam')
@@ -138,10 +132,10 @@ text
 
     def test_history(self):
         COMMITS = [
 
     def test_history(self):
         COMMITS = [
-            {"author": "bunny", "text":"1", "comment": "Oh yeah!"},
-            {"author": "frank", "text":"2", "comment": "Second is the best!"},
-            {"text":"3", "comment": "Third"},
-            {"author": "welma", "text":"4", "comment": "Fourth"},
+            {"author": "bunny", "text": "1", "comment": "Oh yeah!"},
+            {"author": "frank", "text": "2", "comment": "Second is the best!"},
+            {"text": "3", "comment": "Third"},
+            {"author": "welma", "text": "4", "comment": "Fourth"},
         ]
 
         for commit in COMMITS:
         ]
 
         for commit in COMMITS:
@@ -153,16 +147,35 @@ text
             assert_equal(entry["description"], COMMITS[n]["comment"])
             assert_equal(entry["tag"], [])
 
             assert_equal(entry["description"], COMMITS[n]["comment"])
             assert_equal(entry["tag"], [])
 
+    def test_data_revert(self):
+        COMMITS = [
+            {u"title": u"one", "author": "bunny", "text": "1.1", "comment": "1"},
+            {u"title": u"one", "author": "frank", "text": "1.2", "comment": "2"},
+            {u"title": u"two", "author": "bunny", "text": "2.1", "comment": "3"},
+            {u"title": u"one", "author": "frank", "text": "1.3", "comment": "4"},
+        ]
+
+        for commit in COMMITS:
+            self.repo.save_text(**commit)
+
+        # now revert last change on one
+        self.repo.revert(u"one", 0)
+        assert_equal(self.repo.page_text(u"one"), (u"1.1", 3))
+        assert_equal(self.repo.page_text(u"two"), (u"2.1", 0))
+
+        self.repo.revert(u"one", 2)
+        assert_equal(self.repo.page_text(u"one"), (u"1.3", 4))
+
 
 class TestVSTags(object):
 
     TITLE_1 = "Sample"
 
     COMMITS = [
 
 class TestVSTags(object):
 
     TITLE_1 = "Sample"
 
     COMMITS = [
-        {"author": "bunny", "text":"1", "comment": "Oh yeah!"},
-        {"author": "frank", "text":"2", "comment": "Second is the best!"},
-        {"text":"3", "comment": "Third"},
-        {"author": "welma", "text":"4", "comment": "Fourth"},
+        {"author": "bunny", "text": "1", "comment": "Oh yeah!"},
+        {"author": "frank", "text": "2", "comment": "Second is the best!"},
+        {"text": "3", "comment": "Third"},
+        {"author": "welma", "text": "4", "comment": "Fourth"},
     ]
 
     def setUp(self):
     ]
 
     def setUp(self):
@@ -197,7 +210,6 @@ class TestVSTags(object):
                 assert_equal(entry["tag"], [])
 
     def test_add_many_tags(self):
                 assert_equal(entry["tag"], [])
 
     def test_add_many_tags(self):
-        TAG_USER = "mike_the_tagger"
         tags = [
             (2, "production", "mike"),
             (2, "finished", "jeremy"),
         tags = [
             (2, "production", "mike"),
             (2, "finished", "jeremy"),
@@ -212,7 +224,3 @@ class TestVSTags(object):
         for entry in reversed(history):
             expected = [tag[1] for tag in tags if tag[0] == entry["version"]]
             assert_equal(set(entry["tag"]), set(expected))
         for entry in reversed(history):
             expected = [tag[1] for tag in tags if tag[0] == entry["version"]]
             assert_equal(set(entry["tag"]), set(expected))
-
-
-if __name__ == '__main__':
-    runmodule()