17
17
"""Test testaments for gpg signing."""
19
# TODO: Testaments with x-bits
23
from bzrlib import osutils
24
from bzrlib.tests import SymlinkFeature, TestCaseWithTransport
25
from bzrlib.testament import Testament, StrictTestament, StrictTestament3
26
from bzrlib.transform import TreeTransform
29
class TestamentSetup(TestCaseWithTransport):
23
from bzrlib.selftest import TestCaseInTempDir
24
from bzrlib.selftest.treeshape import build_tree_contents
25
from bzrlib.branch import Branch
26
from bzrlib.testament import Testament
27
from bzrlib.trace import mutter
29
class TestamentTests(TestCaseInTempDir):
32
super(TestamentSetup, self).setUp()
33
self.wt = self.make_branch_and_tree('.', format='dirstate-with-subtree')
34
self.wt.set_root_id('TREE_ROT')
35
b = self.b = self.wt.branch
36
b.nick = "test branch"
37
self.wt.commit(message='initial null commit',
31
super(TestamentTests, self).setUp()
32
b = self.b = Branch.initialize('.')
33
b.commit(message='initial null commit',
38
34
committer='test@user',
39
35
timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
41
37
rev_id='test@user-1')
42
self.build_tree_contents([('hello', 'contents of hello file'),
38
build_tree_contents([('hello', 'contents of hello file'),
44
('src/foo.c', 'int main()\n{\n}\n')])
45
self.wt.add(['hello', 'src', 'src/foo.c'],
46
['hello-id', 'src-id', 'foo.c-id'])
47
tt = TreeTransform(self.wt)
48
trans_id = tt.trans_id_tree_path('hello')
49
tt.set_executability(True, trans_id)
51
self.wt.commit(message='add files and directories',
40
('src/foo.c', 'int main()\n{\n}')])
41
b.add(['hello', 'src', 'src/foo.c'])
42
b.commit(message='add files and directories',
52
43
timestamp=1129025483,
54
45
rev_id='test@user-2',
55
46
committer='test@user')
58
class TestamentTests(TestamentSetup):
60
def testament_class(self):
63
def expected(self, key):
64
return texts[self.testament_class()][key]
66
def from_revision(self, repository, revision_id):
67
return self.testament_class().from_revision(repository, revision_id)
69
48
def test_null_testament(self):
70
49
"""Testament for a revision with no contents."""
71
t = self.from_revision(self.b.repository, 'test@user-1')
50
t = Testament.from_revision(self.b, 'test@user-1')
72
51
ass = self.assertTrue
73
52
eq = self.assertEqual
74
53
ass(isinstance(t, Testament))
80
59
def test_testment_text_form(self):
81
60
"""Conversion of testament to canonical text form."""
82
t = self.from_revision(self.b.repository, 'test@user-1')
83
text_form = t.as_text()
61
t = Testament.from_revision(self.b, 'test@user-1')
62
text_form = t.to_text_form_1()
84
63
self.log('testament text form:\n' + text_form)
85
self.assertEqualDiff(text_form, self.expected('rev_1'))
86
short_text_form = t.as_short_text()
87
self.assertEqualDiff(short_text_form, self.expected('rev_1_short'))
65
bazaar-ng testament version 1
66
revision-id: test@user-1
68
timestamp: 1129025423.0
76
self.assertEqual(text_form, expect)
89
78
def test_testament_with_contents(self):
90
79
"""Testament containing a file and a directory."""
91
t = self.from_revision(self.b.repository, 'test@user-2')
92
text_form = t.as_text()
80
t = Testament.from_revision(self.b, 'test@user-2')
81
text_form = t.to_text_form_1()
93
82
self.log('testament text form:\n' + text_form)
94
self.assertEqualDiff(text_form, self.expected('rev_2'))
84
bazaar-ng testament version 1
85
revision-id: test@user-2
87
timestamp: 1129025483.0
93
add files and directories
99
self.assertEqualDiff(text_form, expect)
95
100
actual_short = t.as_short_text()
96
self.assertEqualDiff(actual_short, self.expected('rev_2_short'))
98
def test_testament_symlinks(self):
99
"""Testament containing symlink (where possible)"""
100
self.requireFeature(SymlinkFeature)
101
os.symlink('wibble/linktarget', 'link')
102
self.wt.add(['link'], ['link-id'])
103
self.wt.commit(message='add symlink',
104
timestamp=1129025493,
106
rev_id='test@user-3',
107
committer='test@user')
108
t = self.from_revision(self.b.repository, 'test@user-3')
109
self.assertEqualDiff(t.as_text(), self.expected('rev_3'))
111
def test_testament_revprops(self):
112
"""Testament to revision with extra properties"""
113
props = dict(flavor='sour cherry\ncream cheese',
117
self.wt.commit(message='revision with properties',
118
timestamp=1129025493,
120
rev_id='test@user-3',
121
committer='test@user',
123
t = self.from_revision(self.b.repository, 'test@user-3')
124
self.assertEqualDiff(t.as_text(), self.expected('rev_props'))
126
def test_testament_unicode_commit_message(self):
128
message=u'non-ascii commit \N{COPYRIGHT SIGN} me',
129
timestamp=1129025493,
131
rev_id='test@user-3',
132
committer='Erik B\xe5gfors <test@user>',
133
revprops={'uni':u'\xb5'}
135
t = self.from_revision(self.b.repository, 'test@user-3')
136
self.assertEqualDiff(
137
self.expected('sample_unicode').encode('utf-8'), t.as_text())
139
def test___init__(self):
140
revision = self.b.repository.get_revision('test@user-2')
141
inventory = self.b.repository.get_inventory('test@user-2')
142
testament_1 = self.testament_class()(revision, inventory)
143
text_1 = testament_1.as_short_text()
144
text_2 = self.from_revision(self.b.repository,
145
'test@user-2').as_short_text()
146
self.assertEqual(text_1, text_2)
149
class TestamentTestsStrict(TestamentTests):
151
def testament_class(self):
152
return StrictTestament
155
class TestamentTestsStrict2(TestamentTests):
157
def testament_class(self):
158
return StrictTestament3
161
REV_1_TESTAMENT = """\
162
bazaar-ng testament version 1
163
revision-id: test@user-1
165
timestamp: 1129025423
177
REV_1_STRICT_TESTAMENT = """\
178
bazaar-ng testament version 2.1
179
revision-id: test@user-1
181
timestamp: 1129025423
193
REV_1_STRICT_TESTAMENT3 = """\
194
bazaar testament version 3 strict
195
revision-id: test@user-1
197
timestamp: 1129025423
203
directory . TREE_ROT test@user-1 no
211
bazaar-ng testament short form 1
212
revision-id: test@user-1
214
""" % osutils.sha(REV_1_TESTAMENT).hexdigest()
217
REV_1_SHORT_STRICT = """\
218
bazaar-ng testament short form 2.1
219
revision-id: test@user-1
221
""" % osutils.sha(REV_1_STRICT_TESTAMENT).hexdigest()
224
REV_1_SHORT_STRICT3 = """\
225
bazaar testament short form 3 strict
226
revision-id: test@user-1
228
""" % osutils.sha(REV_1_STRICT_TESTAMENT3).hexdigest()
231
REV_2_TESTAMENT = """\
232
bazaar-ng testament version 1
233
revision-id: test@user-2
235
timestamp: 1129025483
240
add files and directories
242
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
244
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
251
REV_2_STRICT_TESTAMENT = """\
252
bazaar-ng testament version 2.1
253
revision-id: test@user-2
255
timestamp: 1129025483
260
add files and directories
262
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
263
directory src src-id test@user-2 no
264
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
271
REV_2_STRICT_TESTAMENT3 = """\
272
bazaar testament version 3 strict
273
revision-id: test@user-2
275
timestamp: 1129025483
280
add files and directories
282
directory . TREE_ROT test@user-1 no
283
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
284
directory src src-id test@user-2 no
285
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
293
bazaar-ng testament short form 1
294
revision-id: test@user-2
296
""" % osutils.sha(REV_2_TESTAMENT).hexdigest()
299
REV_2_SHORT_STRICT = """\
300
bazaar-ng testament short form 2.1
301
revision-id: test@user-2
303
""" % osutils.sha(REV_2_STRICT_TESTAMENT).hexdigest()
306
REV_2_SHORT_STRICT3 = """\
307
bazaar testament short form 3 strict
308
revision-id: test@user-2
310
""" % osutils.sha(REV_2_STRICT_TESTAMENT3).hexdigest()
313
REV_PROPS_TESTAMENT = """\
314
bazaar-ng testament version 1
315
revision-id: test@user-3
317
timestamp: 1129025493
322
revision with properties
324
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
326
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
339
REV_PROPS_TESTAMENT_STRICT = """\
340
bazaar-ng testament version 2.1
341
revision-id: test@user-3
343
timestamp: 1129025493
348
revision with properties
350
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
351
directory src src-id test@user-2 no
352
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
365
REV_PROPS_TESTAMENT_STRICT3 = """\
366
bazaar testament version 3 strict
367
revision-id: test@user-3
369
timestamp: 1129025493
374
revision with properties
376
directory . TREE_ROT test@user-1 no
377
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
378
directory src src-id test@user-2 no
379
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
392
REV_3_TESTAMENT = """\
393
bazaar-ng testament version 1
394
revision-id: test@user-3
396
timestamp: 1129025493
403
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
404
symlink link link-id wibble/linktarget
406
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
413
REV_3_TESTAMENT_STRICT = """\
414
bazaar-ng testament version 2.1
415
revision-id: test@user-3
417
timestamp: 1129025493
424
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
425
symlink link link-id wibble/linktarget test@user-3 no
426
directory src src-id test@user-2 no
427
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
434
REV_3_TESTAMENT_STRICT3 = """\
435
bazaar testament version 3 strict
436
revision-id: test@user-3
438
timestamp: 1129025493
445
directory . TREE_ROT test@user-1 no
446
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
447
symlink link link-id wibble/linktarget test@user-3 no
448
directory src src-id test@user-2 no
449
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
456
SAMPLE_UNICODE_TESTAMENT = u"""\
457
bazaar-ng testament version 1
458
revision-id: test@user-3
459
committer: Erik B\xe5gfors <test@user>
460
timestamp: 1129025493
465
non-ascii commit \N{COPYRIGHT SIGN} me
467
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
469
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
478
SAMPLE_UNICODE_TESTAMENT_STRICT = u"""\
479
bazaar-ng testament version 2.1
480
revision-id: test@user-3
481
committer: Erik B\xe5gfors <test@user>
482
timestamp: 1129025493
487
non-ascii commit \N{COPYRIGHT SIGN} me
489
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
490
directory src src-id test@user-2 no
491
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
500
SAMPLE_UNICODE_TESTAMENT_STRICT3 = u"""\
501
bazaar testament version 3 strict
502
revision-id: test@user-3
503
committer: Erik B\xe5gfors <test@user>
504
timestamp: 1129025493
509
non-ascii commit \N{COPYRIGHT SIGN} me
511
directory . TREE_ROT test@user-1 no
512
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
513
directory src src-id test@user-2 no
514
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
524
Testament: { 'rev_1': REV_1_TESTAMENT,
525
'rev_1_short': REV_1_SHORT,
526
'rev_2': REV_2_TESTAMENT,
527
'rev_2_short': REV_2_SHORT,
528
'rev_3': REV_3_TESTAMENT,
529
'rev_props': REV_PROPS_TESTAMENT,
530
'sample_unicode': SAMPLE_UNICODE_TESTAMENT,
532
StrictTestament: {'rev_1': REV_1_STRICT_TESTAMENT,
533
'rev_1_short': REV_1_SHORT_STRICT,
534
'rev_2': REV_2_STRICT_TESTAMENT,
535
'rev_2_short': REV_2_SHORT_STRICT,
536
'rev_3': REV_3_TESTAMENT_STRICT,
537
'rev_props': REV_PROPS_TESTAMENT_STRICT,
538
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT,
540
StrictTestament3: {'rev_1': REV_1_STRICT_TESTAMENT3,
541
'rev_1_short': REV_1_SHORT_STRICT3,
542
'rev_2': REV_2_STRICT_TESTAMENT3,
543
'rev_2_short': REV_2_SHORT_STRICT3,
544
'rev_3': REV_3_TESTAMENT_STRICT3,
545
'rev_props': REV_PROPS_TESTAMENT_STRICT3,
546
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT3,
101
self.assertEqualDiff(actual_short, """\
102
bazaar-ng testament short form 1
104
sha1 e64f0a98937f8b0d2602ea5f521938752b90a430