1185.16.12
by Martin Pool
- basic testament class |
1 |
# Copyright (C) 2005 by Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
"""Test testaments for gpg signing."""
|
|
18 |
||
1185.16.25
by Martin Pool
- testament symlink support |
19 |
# TODO: Testaments with x-bits
|
1185.16.23
by Martin Pool
- clean up imports |
20 |
|
1185.16.12
by Martin Pool
- basic testament class |
21 |
import os |
1185.16.22
by Martin Pool
- more testament development |
22 |
from sha import sha |
1185.16.12
by Martin Pool
- basic testament class |
23 |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
24 |
from bzrlib.tests import TestCaseWithTransport |
1551.7.1
by Aaron Bentley
Implement --strict at commandline, fix up strict format |
25 |
from bzrlib.testament import Testament, StrictTestament |
1551.7.5
by Aaron Bentley
Make sure strict testaments indicate when an execute bit is true |
26 |
from bzrlib.transform import TreeTransform |
1185.16.25
by Martin Pool
- testament symlink support |
27 |
from bzrlib.osutils import has_symlinks |
1185.16.12
by Martin Pool
- basic testament class |
28 |
|
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
29 |
|
1930.2.1
by John Arbash Meinel
Move out the blackbox testament tests into a real blackbox module |
30 |
class TestamentSetup(TestCaseWithTransport): |
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
31 |
|
1185.16.15
by Martin Pool
- test text form for testaments |
32 |
def setUp(self): |
1930.2.1
by John Arbash Meinel
Move out the blackbox testament tests into a real blackbox module |
33 |
super(TestamentSetup, self).setUp() |
1534.4.36
by Robert Collins
Finish deprecating Branch.working_tree() |
34 |
self.wt = self.make_branch_and_tree('.') |
35 |
b = self.b = self.wt.branch |
|
1185.35.16
by Aaron Bentley
Fixed tests |
36 |
b.nick = "test branch" |
1534.4.36
by Robert Collins
Finish deprecating Branch.working_tree() |
37 |
self.wt.commit(message='initial null commit', |
1185.16.12
by Martin Pool
- basic testament class |
38 |
committer='test@user', |
39 |
timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005' |
|
40 |
timezone=0, |
|
41 |
rev_id='test@user-1') |
|
1514
by Robert Collins
Unbreak self.build_tree_shape in tests. |
42 |
self.build_tree_contents([('hello', 'contents of hello file'), |
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
43 |
('src/', ), |
1185.16.22
by Martin Pool
- more testament development |
44 |
('src/foo.c', 'int main()\n{\n}\n')]) |
1534.4.36
by Robert Collins
Finish deprecating Branch.working_tree() |
45 |
self.wt.add(['hello', 'src', 'src/foo.c'], |
1508.1.5
by Robert Collins
Move add from Branch to WorkingTree. |
46 |
['hello-id', 'src-id', 'foo.c-id']) |
1551.7.5
by Aaron Bentley
Make sure strict testaments indicate when an execute bit is true |
47 |
tt = TreeTransform(self.wt) |
48 |
trans_id = tt.trans_id_tree_path('hello') |
|
49 |
tt.set_executability(True, trans_id) |
|
50 |
tt.apply() |
|
1534.4.36
by Robert Collins
Finish deprecating Branch.working_tree() |
51 |
self.wt.commit(message='add files and directories', |
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
52 |
timestamp=1129025483, |
53 |
timezone=36000, |
|
54 |
rev_id='test@user-2', |
|
55 |
committer='test@user') |
|
1185.16.15
by Martin Pool
- test text form for testaments |
56 |
|
1930.2.1
by John Arbash Meinel
Move out the blackbox testament tests into a real blackbox module |
57 |
|
58 |
class TestamentTests(TestamentSetup): |
|
59 |
||
1185.16.15
by Martin Pool
- test text form for testaments |
60 |
def test_null_testament(self): |
61 |
"""Testament for a revision with no contents."""
|
|
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
62 |
t = Testament.from_revision(self.b.repository, 'test@user-1') |
1185.16.12
by Martin Pool
- basic testament class |
63 |
ass = self.assertTrue |
64 |
eq = self.assertEqual |
|
65 |
ass(isinstance(t, Testament)) |
|
66 |
eq(t.revision_id, 'test@user-1') |
|
67 |
eq(t.committer, 'test@user') |
|
68 |
eq(t.timestamp, 1129025423) |
|
69 |
eq(t.timezone, 0) |
|
70 |
||
1185.16.15
by Martin Pool
- test text form for testaments |
71 |
def test_testment_text_form(self): |
72 |
"""Conversion of testament to canonical text form."""
|
|
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
73 |
t = Testament.from_revision(self.b.repository, 'test@user-1') |
1185.16.22
by Martin Pool
- more testament development |
74 |
text_form = t.as_text() |
1185.16.15
by Martin Pool
- test text form for testaments |
75 |
self.log('testament text form:\n' + text_form) |
1185.16.25
by Martin Pool
- testament symlink support |
76 |
self.assertEqual(text_form, REV_1_TESTAMENT) |
1185.16.15
by Martin Pool
- test text form for testaments |
77 |
|
1551.7.1
by Aaron Bentley
Implement --strict at commandline, fix up strict format |
78 |
def test_strict_testment_text_form(self): |
79 |
"""Conversion of testament to canonical text form."""
|
|
80 |
t = StrictTestament.from_revision(self.b.repository, 'test@user-1') |
|
81 |
text_form = t.as_text() |
|
82 |
self.log('testament text form:\n' + text_form) |
|
83 |
self.assertEqualDiff(text_form, REV_1_STRICT_TESTAMENT) |
|
84 |
||
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
85 |
def test_testament_with_contents(self): |
86 |
"""Testament containing a file and a directory."""
|
|
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
87 |
t = Testament.from_revision(self.b.repository, 'test@user-2') |
1185.16.22
by Martin Pool
- more testament development |
88 |
text_form = t.as_text() |
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
89 |
self.log('testament text form:\n' + text_form) |
1185.16.24
by Martin Pool
- add and test 'testament' builtin command |
90 |
self.assertEqualDiff(text_form, REV_2_TESTAMENT) |
91 |
actual_short = t.as_short_text() |
|
1185.16.25
by Martin Pool
- testament symlink support |
92 |
self.assertEqualDiff(actual_short, REV_2_SHORT) |
1185.16.24
by Martin Pool
- add and test 'testament' builtin command |
93 |
|
1551.7.1
by Aaron Bentley
Implement --strict at commandline, fix up strict format |
94 |
def test_strict_testament_with_contents(self): |
95 |
"""Testament containing a file and a directory."""
|
|
96 |
t = StrictTestament.from_revision(self.b.repository, 'test@user-2') |
|
97 |
text_form = t.as_text() |
|
98 |
self.log('testament text form:\n' + text_form) |
|
99 |
self.assertEqualDiff(text_form, REV_2_STRICT_TESTAMENT) |
|
100 |
actual_short = t.as_short_text() |
|
101 |
self.assertEqualDiff(actual_short, REV_2_SHORT_STRICT) |
|
102 |
||
1185.16.25
by Martin Pool
- testament symlink support |
103 |
def test_testament_symlinks(self): |
104 |
"""Testament containing symlink (where possible)"""
|
|
105 |
if not has_symlinks(): |
|
106 |
return
|
|
107 |
os.symlink('wibble/linktarget', 'link') |
|
1534.4.36
by Robert Collins
Finish deprecating Branch.working_tree() |
108 |
self.wt.add(['link'], ['link-id']) |
109 |
self.wt.commit(message='add symlink', |
|
1185.16.25
by Martin Pool
- testament symlink support |
110 |
timestamp=1129025493, |
111 |
timezone=36000, |
|
112 |
rev_id='test@user-3', |
|
113 |
committer='test@user') |
|
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
114 |
t = Testament.from_revision(self.b.repository, 'test@user-3') |
1185.16.25
by Martin Pool
- testament symlink support |
115 |
self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT) |
116 |
||
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
117 |
def test_testament_revprops(self): |
118 |
"""Testament to revision with extra properties"""
|
|
119 |
props = dict(flavor='sour cherry\ncream cheese', |
|
1886.1.5
by John Arbash Meinel
Assert that Testament can handle empty revprops as well |
120 |
size='medium', |
121 |
empty='', |
|
122 |
)
|
|
1534.4.36
by Robert Collins
Finish deprecating Branch.working_tree() |
123 |
self.wt.commit(message='revision with properties', |
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
124 |
timestamp=1129025493, |
125 |
timezone=36000, |
|
126 |
rev_id='test@user-3', |
|
127 |
committer='test@user', |
|
128 |
revprops=props) |
|
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
129 |
t = Testament.from_revision(self.b.repository, 'test@user-3') |
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
130 |
self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT) |
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
131 |
|
1553.3.1
by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this. |
132 |
def test_testament_unicode_commit_message(self): |
1558.1.3
by Aaron Bentley
Fixed deprecated op use in test suite |
133 |
self.wt.commit( |
1553.3.1
by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this. |
134 |
message=u'non-ascii commit \N{COPYRIGHT SIGN} me', |
135 |
timestamp=1129025493, |
|
136 |
timezone=36000, |
|
137 |
rev_id='test@user-3', |
|
1930.2.2
by John Arbash Meinel
Avoid needless encode/decode. Only encode at the boundary (as suggested by hpk) |
138 |
committer='Erik B\xe5gfors <test@user>', |
139 |
revprops={'uni':u'\xb5'} |
|
140 |
)
|
|
1553.3.1
by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this. |
141 |
t = Testament.from_revision(self.b.repository, 'test@user-3') |
1553.3.4
by Marien Zwart
Move the encoding step into the test to make it more obvious we are comparing bytestrings. |
142 |
self.assertEqualDiff( |
1185.50.79
by John Arbash Meinel
small cleanup of test |
143 |
SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text()) |
1553.3.1
by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this. |
144 |
|
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
145 |
def test___init__(self): |
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
146 |
revision = self.b.repository.get_revision('test@user-2') |
147 |
inventory = self.b.repository.get_inventory('test@user-2') |
|
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
148 |
testament_1 = Testament(revision, inventory).as_short_text() |
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
149 |
testament_2 = Testament.from_revision(self.b.repository, |
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
150 |
'test@user-2').as_short_text() |
151 |
self.assertEqual(testament_1, testament_2) |
|
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
152 |
|
1185.16.25
by Martin Pool
- testament symlink support |
153 |
|
154 |
REV_1_TESTAMENT = """\ |
|
155 |
bazaar-ng testament version 1
|
|
156 |
revision-id: test@user-1
|
|
157 |
committer: test@user
|
|
158 |
timestamp: 1129025423
|
|
159 |
timezone: 0
|
|
160 |
parents:
|
|
161 |
message:
|
|
162 |
initial null commit
|
|
163 |
inventory:
|
|
1185.35.16
by Aaron Bentley
Fixed tests |
164 |
properties:
|
165 |
branch-nick:
|
|
166 |
test branch
|
|
1185.16.25
by Martin Pool
- testament symlink support |
167 |
"""
|
168 |
||
1551.7.1
by Aaron Bentley
Implement --strict at commandline, fix up strict format |
169 |
REV_1_STRICT_TESTAMENT = """\ |
170 |
bazaar-ng testament version 2.1
|
|
171 |
revision-id: test@user-1
|
|
172 |
committer: test@user
|
|
173 |
timestamp: 1129025423
|
|
174 |
timezone: 0
|
|
175 |
parents:
|
|
176 |
message:
|
|
177 |
initial null commit
|
|
178 |
inventory:
|
|
179 |
properties:
|
|
180 |
branch-nick:
|
|
181 |
test branch
|
|
182 |
"""
|
|
183 |
||
184 |
||
1185.16.25
by Martin Pool
- testament symlink support |
185 |
REV_1_SHORT = """\ |
186 |
bazaar-ng testament short form 1
|
|
187 |
revision-id: test@user-1
|
|
188 |
sha1: %s |
|
189 |
""" % sha(REV_1_TESTAMENT).hexdigest() |
|
190 |
||
1185.16.24
by Martin Pool
- add and test 'testament' builtin command |
191 |
|
1551.7.1
by Aaron Bentley
Implement --strict at commandline, fix up strict format |
192 |
REV_1_SHORT_STRICT = """\ |
193 |
bazaar-ng testament short form 2.1
|
|
194 |
revision-id: test@user-1
|
|
195 |
sha1: %s |
|
196 |
""" % sha(REV_1_STRICT_TESTAMENT).hexdigest() |
|
197 |
||
198 |
||
1185.16.24
by Martin Pool
- add and test 'testament' builtin command |
199 |
REV_2_TESTAMENT = """\ |
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
200 |
bazaar-ng testament version 1
|
201 |
revision-id: test@user-2
|
|
202 |
committer: test@user
|
|
1185.16.22
by Martin Pool
- more testament development |
203 |
timestamp: 1129025483
|
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
204 |
timezone: 36000
|
205 |
parents:
|
|
206 |
test@user-1
|
|
207 |
message:
|
|
208 |
add files and directories
|
|
209 |
inventory:
|
|
1185.16.22
by Martin Pool
- more testament development |
210 |
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
|
211 |
directory src src-id
|
|
212 |
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
|
|
1185.35.16
by Aaron Bentley
Fixed tests |
213 |
properties:
|
214 |
branch-nick:
|
|
215 |
test branch
|
|
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
216 |
"""
|
1185.16.25
by Martin Pool
- testament symlink support |
217 |
|
218 |
||
1551.7.1
by Aaron Bentley
Implement --strict at commandline, fix up strict format |
219 |
REV_2_STRICT_TESTAMENT = """\ |
220 |
bazaar-ng testament version 2.1
|
|
221 |
revision-id: test@user-2
|
|
222 |
committer: test@user
|
|
223 |
timestamp: 1129025483
|
|
224 |
timezone: 36000
|
|
225 |
parents:
|
|
226 |
test@user-1
|
|
227 |
message:
|
|
228 |
add files and directories
|
|
229 |
inventory:
|
|
1551.7.5
by Aaron Bentley
Make sure strict testaments indicate when an execute bit is true |
230 |
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
|
1551.7.1
by Aaron Bentley
Implement --strict at commandline, fix up strict format |
231 |
directory src src-id test@user-2 no
|
232 |
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
|
|
233 |
properties:
|
|
234 |
branch-nick:
|
|
235 |
test branch
|
|
236 |
"""
|
|
237 |
||
238 |
||
1185.16.25
by Martin Pool
- testament symlink support |
239 |
REV_2_SHORT = """\ |
240 |
bazaar-ng testament short form 1
|
|
241 |
revision-id: test@user-2
|
|
242 |
sha1: %s |
|
243 |
""" % sha(REV_2_TESTAMENT).hexdigest() |
|
244 |
||
245 |
||
1551.7.1
by Aaron Bentley
Implement --strict at commandline, fix up strict format |
246 |
REV_2_SHORT_STRICT = """\ |
247 |
bazaar-ng testament short form 2.1
|
|
248 |
revision-id: test@user-2
|
|
249 |
sha1: %s |
|
250 |
""" % sha(REV_2_STRICT_TESTAMENT).hexdigest() |
|
251 |
||
252 |
||
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
253 |
REV_PROPS_TESTAMENT = """\ |
254 |
bazaar-ng testament version 1
|
|
255 |
revision-id: test@user-3
|
|
256 |
committer: test@user
|
|
257 |
timestamp: 1129025493
|
|
258 |
timezone: 36000
|
|
259 |
parents:
|
|
260 |
test@user-2
|
|
261 |
message:
|
|
262 |
revision with properties
|
|
263 |
inventory:
|
|
264 |
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
|
|
265 |
directory src src-id
|
|
266 |
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
|
|
267 |
properties:
|
|
1185.35.16
by Aaron Bentley
Fixed tests |
268 |
branch-nick:
|
269 |
test branch
|
|
1886.1.5
by John Arbash Meinel
Assert that Testament can handle empty revprops as well |
270 |
empty:
|
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
271 |
flavor:
|
272 |
sour cherry
|
|
273 |
cream cheese
|
|
274 |
size:
|
|
275 |
medium
|
|
276 |
"""
|
|
277 |
||
278 |
||
1185.16.25
by Martin Pool
- testament symlink support |
279 |
REV_3_TESTAMENT = """\ |
280 |
bazaar-ng testament version 1
|
|
281 |
revision-id: test@user-3
|
|
282 |
committer: test@user
|
|
283 |
timestamp: 1129025493
|
|
284 |
timezone: 36000
|
|
285 |
parents:
|
|
286 |
test@user-2
|
|
287 |
message:
|
|
288 |
add symlink
|
|
289 |
inventory:
|
|
290 |
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
|
|
291 |
symlink link link-id wibble/linktarget
|
|
292 |
directory src src-id
|
|
293 |
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
|
|
1185.35.16
by Aaron Bentley
Fixed tests |
294 |
properties:
|
295 |
branch-nick:
|
|
296 |
test branch
|
|
1185.16.25
by Martin Pool
- testament symlink support |
297 |
"""
|
1553.3.1
by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this. |
298 |
|
1553.3.3
by Marien Zwart
Whitespace cleanup (pep 3) |
299 |
|
1553.3.4
by Marien Zwart
Move the encoding step into the test to make it more obvious we are comparing bytestrings. |
300 |
SAMPLE_UNICODE_TESTAMENT = u"""\ |
1553.3.1
by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this. |
301 |
bazaar-ng testament version 1
|
302 |
revision-id: test@user-3
|
|
1930.2.2
by John Arbash Meinel
Avoid needless encode/decode. Only encode at the boundary (as suggested by hpk) |
303 |
committer: Erik B\xe5gfors <test@user> |
1553.3.1
by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this. |
304 |
timestamp: 1129025493
|
305 |
timezone: 36000
|
|
306 |
parents:
|
|
307 |
test@user-2
|
|
308 |
message:
|
|
309 |
non-ascii commit \N{COPYRIGHT SIGN} me |
|
310 |
inventory:
|
|
311 |
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
|
|
312 |
directory src src-id
|
|
313 |
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
|
|
314 |
properties:
|
|
315 |
branch-nick:
|
|
316 |
test branch
|
|
1930.2.2
by John Arbash Meinel
Avoid needless encode/decode. Only encode at the boundary (as suggested by hpk) |
317 |
uni:
|
318 |
\xb5 |
|
1553.3.4
by Marien Zwart
Move the encoding step into the test to make it more obvious we are comparing bytestrings. |
319 |
"""
|