X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/ee01d50d05b7d72dd372e8f3a0c78b9da6c23b38..f499ee9347f539c36f3846fdc41020f2320bae77:/lib/test_vstorage.py diff --git a/lib/test_vstorage.py b/lib/test_vstorage.py index 00df2f69..eaea46f4 100644 --- a/lib/test_vstorage.py +++ b/lib/test_vstorage.py @@ -44,7 +44,7 @@ class TestVersionedStorage(object): comment = comment, parent=-1) saved = self.repo.open_page(title).read() - assert saved == text + assert_equal(saved, text) def test_save_text_noparent(self): text = u"test text" @@ -57,7 +57,7 @@ class TestVersionedStorage(object): comment = comment, parent=None) saved = self.repo.open_page(title).read() - assert saved == text + assert_equal(saved, text) def test_save_merge_no_conflict(self): text = u"test\ntext" @@ -71,7 +71,7 @@ class TestVersionedStorage(object): text = text, author = author, comment = comment, parent=-1) saved = self.repo.open_page(title).read() - assert saved == text + assert_equal(saved, text) def test_save_merge_line_conflict(self): text = u"test\ntest\n" @@ -129,7 +129,86 @@ text 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 same_repo.repo_revision() == current_repo_revision + assert_equal(same_repo.repo_revision(), current_repo_revision) + + + 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"}, # anonymous + {"author": "welma", "text":"4", "comment": "Fourth"}, + ] + + for commit in COMMITS: + 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["description"], COMMITS[n]["comment"]) + assert_equal(entry["tag"], []) + + +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"}, # anonymous + {"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) + + # 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): + 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): + 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"] ] + assert_equal(set(entry["tag"]), set(expected)) if __name__ == '__main__':