X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/f499ee9347f539c36f3846fdc41020f2320bae77..85758488fc4c0f60e4b958df9c4c7cd67a732000:/lib/test_vstorage.py diff --git a/lib/test_vstorage.py b/lib/test_vstorage.py index eaea46f4..23375f06 100644 --- a/lib/test_vstorage.py +++ b/lib/test_vstorage.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # import os @@ -12,6 +12,8 @@ from nose.core import runmodule import vstorage +NULL_PARENT = -1 + def clear_directory(top): for root, dirs, files in os.walk(top, topdown=False): @@ -29,20 +31,24 @@ class TestVersionedStorage(object): def setUp(self): self.repo_path = tempfile.mkdtemp() self.repo = vstorage.VersionedStorage(self.repo_path) - + def tearDown(self): clear_directory(self.repo_path) - + def test_save_text(self): text = u"test text" 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=-1) - + + 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) @@ -51,11 +57,11 @@ class TestVersionedStorage(object): 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=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) @@ -64,15 +70,15 @@ class TestVersionedStorage(object): 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=-1) - self.repo.save_text(title = title, - text = text, author = author, - comment = comment, parent=-1) + 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) - + def test_save_merge_line_conflict(self): text = u"test\ntest\n" text1 = u"test\ntext\n" @@ -80,21 +86,21 @@ class TestVersionedStorage(object): 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=-1) - - self.repo.save_text(title = title, - text = text1, author = author, - comment = comment, parent=0) - - self.repo.save_text(title = title, - text = text2, author = author, - comment = comment, parent=0) - + + self.repo.save_text(title=title, + text=text, author=author, + comment=comment, parent=NULL_PARENT) + + self.repo.save_text(title=title, + text=text1, author=author, + comment=comment, parent=0) + + self.repo.save_text(title=title, + text=text2, author=author, + comment=comment, parent=0) + saved = self.repo.open_page(title).read() - + # Other conflict markers placement can also be correct assert_equal(saved, u'''\ text @@ -105,20 +111,19 @@ text >>>>>>> other ''') - def test_delete(self): text = u"text test" 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=-1) - + self.repo.save_text(title=title, + text=text, author=author, + comment=comment, parent=NULL_PARENT) + assert title in self.repo - + self.repo.delete_page(title, author, comment) - + assert title not in self.repo @raises(vstorage.DocumentNotFound) @@ -126,90 +131,88 @@ text self.repo.open_page(u'unknown entity') def test_open_existing_repository(self): - self.repo.save_text(title = u'Python!', text = u'ham and spam') + self.repo.save_text(title=u'Python!', text=u'ham and spam') current_repo_revision = self.repo.repo_revision() same_repo = vstorage.VersionedStorage(self.repo_path) assert_equal(same_repo.repo_revision(), current_repo_revision) - - + def test_history(self): COMMITS = [ - {"author": "bunny", "text":"1", "comment": "Oh yeah!"}, + {"author": "bunny", "text":"1", "comment": "Oh yeah!"}, {"author": "frank", "text":"2", "comment": "Second is the best!"}, - {"text":"3", "comment": "Third"}, # anonymous - {"author": "welma", "text":"4", "comment": "Fourth"}, + {"text":"3", "comment": "Third"}, + {"author": "welma", "text":"4", "comment": "Fourth"}, ] - + for commit in COMMITS: - self.repo.save_text(title = u"Sample", **commit) - + self.repo.save_text(title=u"Sample", **commit) + for n, entry in enumerate(reversed(list(self.repo.page_history(u"Sample")))): assert_equal(entry["version"], n) - assert_equal(entry["author"], COMMITS[n].get("author", "anonymous") ) + assert_equal(entry["author"], COMMITS[n].get("author", "anonymous")) assert_equal(entry["description"], COMMITS[n]["comment"]) - assert_equal(entry["tag"], []) - - + assert_equal(entry["tag"], []) + + class TestVSTags(object): - + TITLE_1 = "Sample" - + COMMITS = [ - {"author": "bunny", "text":"1", "comment": "Oh yeah!"}, + {"author": "bunny", "text":"1", "comment": "Oh yeah!"}, {"author": "frank", "text":"2", "comment": "Second is the best!"}, - {"text":"3", "comment": "Third"}, # anonymous - {"author": "welma", "text":"4", "comment": "Fourth"}, - ] - + {"text":"3", "comment": "Third"}, + {"author": "welma", "text":"4", "comment": "Fourth"}, + ] + def setUp(self): self.repo_path = tempfile.mkdtemp() self.repo = vstorage.VersionedStorage(self.repo_path) - + # generate some history for commit in self.COMMITS: - self.repo.save_text(title = u"Sample", **commit) - + self.repo.save_text(title=u"Sample", **commit) + # verify for n, entry in enumerate(reversed(list(self.repo.page_history(self.TITLE_1)))): assert_equal(entry["tag"], []) - + def tearDown(self): clear_directory(self.repo_path) - - def test_add_tag(self): + + def test_add_tag(self): TAG_USER = "mike_the_tagger" TAG_NAME = "production" TAG_VERSION = 2 - + # Add tag self.repo.add_page_tag(self.TITLE_1, TAG_VERSION, TAG_NAME, TAG_USER) - + # check history again history = list(self.repo.page_history(self.TITLE_1)) for entry in reversed(history): if entry["version"] == TAG_VERSION: assert_equal(entry["tag"], [TAG_NAME]) else: - 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"), (0, "original", "jeremy"), ] - - + for rev, name, user in tags: self.repo.add_page_tag(self.TITLE_1, rev, name, user) - + # check history again history = list(self.repo.page_history(self.TITLE_1)) for entry in reversed(history): - expected = [ tag[1] for tag in tags if tag[0] == entry["version"] ] + expected = [tag[1] for tag in tags if tag[0] == entry["version"]] assert_equal(set(entry["tag"]), set(expected)) if __name__ == '__main__': - runmodule() \ No newline at end of file + runmodule()