2 # -*- coding: utf-8 -*-
6 from nose.tools import *
7 from nose.core import runmodule
12 def clear_directory(top):
13 for root, dirs, files in os.walk(top, topdown=False):
15 os.remove(os.path.join(root, name))
17 os.rmdir(os.path.join(root, name))
24 class TestVersionedStorage(object):
26 self.repo_path = tempfile.mkdtemp()
27 self.repo = vstorage.VersionedStorage(self.repo_path)
30 clear_directory(self.repo_path)
32 def test_save_text(self):
35 author = u"test author"
36 comment = u"test comment"
38 self.repo.save_text(title = title,
39 text = text, author = author,
40 comment = comment, parent=-1)
42 saved = self.repo.open_page(title).read()
45 def test_save_text_noparent(self):
48 author = u"test author"
49 comment = u"test comment"
51 self.repo.save_text(title = title,
52 text = text, author = author,
53 comment = comment, parent=None)
55 saved = self.repo.open_page(title).read()
58 def test_save_merge_no_conflict(self):
61 author = u"test author"
62 comment = u"test comment"
63 self.repo.save_text(title = title,
64 text = text, author = author,
65 comment = comment, parent=-1)
66 self.repo.save_text(title = title,
67 text = text, author = author,
68 comment = comment, parent=-1)
69 saved = self.repo.open_page(title).read()
72 def test_save_merge_line_conflict(self):
73 text = u"test\ntest\n"
74 text1 = u"test\ntext\n"
75 text2 = u"text\ntest\n"
77 author = u"test author"
78 comment = u"test comment"
80 self.repo.save_text(title = title,
81 text = text, author = author,
82 comment = comment, parent=-1)
84 self.repo.save_text(title = title,
85 text = text1, author = author,
86 comment = comment, parent=0)
88 self.repo.save_text(title = title,
89 text = text2, author = author,
90 comment = comment, parent=0)
92 saved = self.repo.open_page(title).read()
94 # Other conflict markers placement can also be correct
95 assert_equal(saved, u'''\
105 def test_delete(self):
107 title = u"test title"
108 author = u"test author"
109 comment = u"test comment"
110 self.repo.save_text(title = title,
111 text = text, author = author,
112 comment = comment, parent=-1)
114 assert title in self.repo
116 self.repo.delete_page(title, author, comment)
118 assert title not in self.repo
120 @raises(vstorage.DocumentNotFound)
121 def test_document_not_found(self):
122 self.repo.open_page(u'unknown entity')
124 def test_open_existing_repository(self):
125 self.repo.save_text(title = u'Python!', text = u'ham and spam')
126 current_repo_revision = self.repo.repo_revision()
127 same_repo = vstorage.VersionedStorage(self.repo_path)
128 assert same_repo.repo_revision() == current_repo_revision
131 if __name__ == '__main__':