Dodanie stylów dla widoku HTMLVIew.
[redakcja.git] / lib / wlrepo / tests / test_mercurial.py
1 # -*- encoding: utf-8 -*-
2
3 __author__= "Łukasz Rekucki"
4 __date__ = "$2009-09-18 14:43:27$"
5 __doc__ = "Tests for RAL mercurial backend."
6
7 from nose.tools import *
8
9 from wlrepo import MercurialLibrary
10
11 import os, os.path, tempfile
12 import shutil
13
14 REPO_TEMPLATES = os.path.join( os.path.dirname(__file__), 'data')
15
16 def temprepo(name):
17
18     from functools import wraps
19
20     def decorator(func):               
21         def decorated(*args, **kwargs):
22             clean = False
23             try:
24                 temp = tempfile.mkdtemp("", "testdir_" )
25                 path = os.path.join(temp, 'repo')
26                 shutil.copytree(os.path.join(REPO_TEMPLATES, name), path, False)
27                 kwargs['library'] = MercurialLibrary(path)
28                 func(*args, **kwargs)
29                 clean = True
30             finally:
31                 #if not clean and self.response:
32                 #    print "RESULT", func.__name__, ">>>"
33                 #    print self.response
34                 #    print "<<<"
35                 shutil.rmtree(temp, True)
36
37         decorated = make_decorator(func)(decorated)
38         return decorated   
39     
40     return decorator
41
42 @temprepo('clean')
43 def test_opening(library):
44     pass
45
46 @temprepo('simple')
47 def test_read_document(library):
48     doc = library.document('sample')
49     assert_equal(doc.data('xml'), 'Ala ma kota\n')
50
51 @temprepo('simple')
52 def test_read_UTF8_document(library):
53     doc = library.document('sample_pl')
54     assert_equal(doc.data('xml'), u'Gżegżółka\n'.encode('utf-8'))
55
56 @temprepo('simple')
57 def test_change_document(library):
58     doc = library.document('sample')
59     STRING = u'Gąski lubią pływać!\n'.encode('utf-8')
60     
61     def write_action(library, resolve):
62         f = library._fileopen(resolve('xml'), 'r+')        
63         assert_equal(f.read(), 'Ala ma kota\n')
64         f.seek(0)
65         f.write(STRING)
66         f.flush()
67         f.seek(0)
68         assert_equal(f.read(), STRING)
69
70     def commit_info(document):
71         return ("Document rewrite", "library")
72     
73     ndoc = doc.invoke_and_commit(write_action, commit_info)
74     assert_equal(ndoc.data('xml'), STRING)
75     
76
77 @temprepo('simple')
78 def test_create_document(library):
79     assert_equal(sorted(library.documents()), sorted(['sample', 'sample_pl']))
80
81     doc = library.document_create("creation")
82     doc.quickwrite("xml", "<ala />", "Quick write", user="library")
83     
84     assert_equal(sorted(library.documents()), sorted(['sample', 'sample_pl', 'creation']))
85         
86 #
87 #@temprepo('branched')
88 #def test_switch_branch(library):
89 #    tester_cab = library.cabinet("valid_file", "tester", create=False)
90 #    assert_equal( list(tester_cab.parts()), ['valid_file'])
91 #
92 #@raises(wlrepo.CabinetNotFound)
93 #@temprepo('branched')
94 #def test_branch_not_found(library):
95 #    tester_cab = library.cabinet("ugh", "tester", create=False)
96 #
97 #@temprepo('branched')
98 #def test_no_branches(library):
99 #    n4 = library.shelf(4)
100 #    n3 = library.shelf(3)
101 #    n2 = library.shelf(2)
102 #    n1 = library.shelf(1)
103 #    n0 = library.shelf(0)
104 #
105 #    assert_true( n3.parentof(n4) )
106 #    assert_false( n4.parentof(n3) )
107 #    assert_true( n0.parentof(n1) )
108 #    assert_false( n1.parentof(n0) )
109 #    assert_false( n0.parentof(n4) )
110 #
111 ## def test_ancestor_of_simple(self):
112 #    assert_true( n3.ancestorof(n4) )
113 #    assert_true( n2.ancestorof(n4) )
114 #    assert_true( n1.ancestorof(n4) )
115 #    assert_true( n0.ancestorof(n4) )
116 #
117 #    assert_true( n2.ancestorof(n3) )
118 #    assert_true( n1.ancestorof(n3) )
119 #    assert_true( n0.ancestorof(n3) )
120 #
121 #    assert_false( n4.ancestorof(n4) )
122 #    assert_false( n4.ancestorof(n3) )
123 #    assert_false( n3.ancestorof(n2) )
124 #    assert_false( n3.ancestorof(n1) )
125 #    assert_false( n3.ancestorof(n0) )
126 #
127 ## def test_common_ancestor_simple(self):
128 #    assert_true( n3.has_common_ancestor(n4) )
129 #    assert_true( n3.has_common_ancestor(n3) )
130 #    assert_true( n3.has_common_ancestor(n3) )
131 #
132 #
133 #@temprepo('branched2')
134 #def test_once_branched(library):
135 #    n7 = library.shelf(7)
136 #    n6 = library.shelf(6)
137 #    n5 = library.shelf(5)
138 #    n4 = library.shelf(4)
139 #    n3 = library.shelf(3)
140 #    n2 = library.shelf(2)
141 #
142 #    assert_true( n2.parentof(n3) )
143 #    assert_false( n3.parentof(n2) )
144 #
145 #    assert_true( n2.parentof(n5) )
146 #    assert_false( n5.parentof(n2) )
147 #
148 #    assert_false( n2.parentof(n4) )
149 #    assert_false( n2.parentof(n6) )
150 #    assert_false( n3.parentof(n5) )
151 #    assert_false( n5.parentof(n3) )
152 #
153 ## def test_ancestorof_branched(self):
154 #    assert_true( n2.ancestorof(n7) )
155 #    assert_false( n7.ancestorof(n2) )
156 #    assert_true( n2.ancestorof(n6) )
157 #    assert_false( n6.ancestorof(n2) )
158 #    assert_true( n2.ancestorof(n5) )
159 #    assert_false( n5.ancestorof(n2) )
160 #
161 #    assert_false( n3.ancestorof(n5) )
162 #    assert_false( n5.ancestorof(n3) )
163 #    assert_false( n4.ancestorof(n5) )
164 #    assert_false( n5.ancestorof(n4) )
165 #    assert_false( n3.ancestorof(n7) )
166 #    assert_false( n7.ancestorof(n3) )
167 #    assert_false( n4.ancestorof(n6) )
168 #    assert_false( n6.ancestorof(n4) )
169 #
170 ## def test_common_ancestor_branched(self):
171 #    assert_true( n2.has_common_ancestor(n4) )
172 #    assert_true( n2.has_common_ancestor(n7) )
173 #    assert_true( n2.has_common_ancestor(n6) )
174 #
175 #    # cause it's not in the right branch
176 #    assert_false( n5.has_common_ancestor(n3) )
177 #    assert_false( n7.has_common_ancestor(n4) )
178 #
179 #@temprepo('merged')
180 #def test_after_merge(library):
181 #    n8 = library.shelf(8)
182 #    n7 = library.shelf(7)
183 #    n6 = library.shelf(6)
184 #
185 #    assert_true( n7.parentof(n8) )
186 #    assert_false( n8.parentof(n7) )
187 #
188 #    assert_true( n7.ancestorof(n8) )
189 #    assert_true( n6.ancestorof(n8) )
190 #
191 #
192 #    assert_true( n7.has_common_ancestor(n8) )
193 #    # cause it's not in the right branch
194 #    assert_false( n8.has_common_ancestor(n7) )
195 #
196 #@temprepo('merged_with_local_commit')
197 #def test_after_merge_and_local_commit(library):
198 #    n9 = library.shelf(9)
199 #    n8 = library.shelf(8)
200 #    n7 = library.shelf(7)
201 #    n6 = library.shelf(6)
202 #
203 #    assert_true( n7.parentof(n8) )
204 #    assert_false( n8.parentof(n7) )
205 #
206 #    assert_true( n9.has_common_ancestor(n8) )
207 #    # cause it's not in the right branch
208 #    assert_false( n8.has_common_ancestor(n9) )
209 #
210 #
211 #@temprepo('branched2')
212 #def test_merge_personal_to_default(library):
213 #    main = library.shelf(2)
214 #    print main
215 #
216 #    local = library.shelf(7)
217 #    print local
218 #
219 #    document = library.document("ala", "admin")
220 #    shared = document.shared()
221 #    assert_true( shared is None )
222 #    document.share("Here is my copy!")
223 #
224 #    assert_equal( document.shelf(), local) # local didn't change
225 #
226 #    shared = document.shared()
227 #    assert_true( shared is not None )
228 #
229 #    print library.shelf()
230 #
231 #    new_main = shared.shelf()
232 #    assert_not_equal( new_main, main) # main has new revision
233 #
234 #    # check for parents
235 #    assert_true( main.parentof(new_main) )
236 #    assert_true( local.parentof(new_main) )
237 #
238 #@temprepo('clean')
239 #def test_create_branch(library):
240 #    tester_cab = library.cabinet("anotherone", "tester", create=True)
241 #    assert_equal( list(tester_cab.parts()), ['anotherone'])
242