2 # -*- coding: utf-8 -*-
4 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
5 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
10 from nose.tools import *
11 from nose.core import runmodule
16 def clear_directory(top):
17 for root, dirs, files in os.walk(top, topdown=False):
19 os.remove(os.path.join(root, name))
21 os.rmdir(os.path.join(root, name))
28 class TestVersionedStorage(object):
30 self.repo_path = tempfile.mkdtemp()
31 self.repo = vstorage.VersionedStorage(self.repo_path)
34 clear_directory(self.repo_path)
36 def test_save_text(self):
39 author = u"test author"
40 comment = u"test comment"
42 self.repo.save_text(title = title,
43 text = text, author = author,
44 comment = comment, parent=-1)
46 saved = self.repo.open_page(title).read()
49 def test_save_text_noparent(self):
52 author = u"test author"
53 comment = u"test comment"
55 self.repo.save_text(title = title,
56 text = text, author = author,
57 comment = comment, parent=None)
59 saved = self.repo.open_page(title).read()
62 def test_save_merge_no_conflict(self):
65 author = u"test author"
66 comment = u"test comment"
67 self.repo.save_text(title = title,
68 text = text, author = author,
69 comment = comment, parent=-1)
70 self.repo.save_text(title = title,
71 text = text, author = author,
72 comment = comment, parent=-1)
73 saved = self.repo.open_page(title).read()
76 def test_save_merge_line_conflict(self):
77 text = u"test\ntest\n"
78 text1 = u"test\ntext\n"
79 text2 = u"text\ntest\n"
81 author = u"test author"
82 comment = u"test comment"
84 self.repo.save_text(title = title,
85 text = text, author = author,
86 comment = comment, parent=-1)
88 self.repo.save_text(title = title,
89 text = text1, author = author,
90 comment = comment, parent=0)
92 self.repo.save_text(title = title,
93 text = text2, author = author,
94 comment = comment, parent=0)
96 saved = self.repo.open_page(title).read()
98 # Other conflict markers placement can also be correct
99 assert_equal(saved, u'''\
109 def test_delete(self):
111 title = u"test title"
112 author = u"test author"
113 comment = u"test comment"
114 self.repo.save_text(title = title,
115 text = text, author = author,
116 comment = comment, parent=-1)
118 assert title in self.repo
120 self.repo.delete_page(title, author, comment)
122 assert title not in self.repo
124 @raises(vstorage.DocumentNotFound)
125 def test_document_not_found(self):
126 self.repo.open_page(u'unknown entity')
128 def test_open_existing_repository(self):
129 self.repo.save_text(title = u'Python!', text = u'ham and spam')
130 current_repo_revision = self.repo.repo_revision()
131 same_repo = vstorage.VersionedStorage(self.repo_path)
132 assert same_repo.repo_revision() == current_repo_revision
135 if __name__ == '__main__':