1
# Copyright (C) 2005 by Canonical Ltd
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.
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.
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
17
"""Test testaments for gpg signing."""
19
# TODO: Testaments with x-bits
25
from bzrlib.tests import TestCaseWithTransport
26
from bzrlib.branch import Branch
27
from bzrlib.testament import Testament, StrictTestament
28
from bzrlib.trace import mutter
29
from bzrlib.transform import TreeTransform
30
from bzrlib.osutils import has_symlinks
33
class TestamentTests(TestCaseWithTransport):
36
super(TestamentTests, self).setUp()
37
self.wt = self.make_branch_and_tree('.')
38
b = self.b = self.wt.branch
39
b.nick = "test branch"
40
self.wt.commit(message='initial null commit',
41
committer='test@user',
42
timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
45
self.build_tree_contents([('hello', 'contents of hello file'),
47
('src/foo.c', 'int main()\n{\n}\n')])
48
self.wt.add(['hello', 'src', 'src/foo.c'],
49
['hello-id', 'src-id', 'foo.c-id'])
50
tt = TreeTransform(self.wt)
51
trans_id = tt.trans_id_tree_path('hello')
52
tt.set_executability(True, trans_id)
54
self.wt.commit(message='add files and directories',
58
committer='test@user')
60
def test_null_testament(self):
61
"""Testament for a revision with no contents."""
62
t = Testament.from_revision(self.b.repository, 'test@user-1')
65
ass(isinstance(t, Testament))
66
eq(t.revision_id, 'test@user-1')
67
eq(t.committer, 'test@user')
68
eq(t.timestamp, 1129025423)
71
def test_testment_text_form(self):
72
"""Conversion of testament to canonical text form."""
73
t = Testament.from_revision(self.b.repository, 'test@user-1')
74
text_form = t.as_text()
75
self.log('testament text form:\n' + text_form)
76
self.assertEqual(text_form, REV_1_TESTAMENT)
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)
85
def test_testament_with_contents(self):
86
"""Testament containing a file and a directory."""
87
t = Testament.from_revision(self.b.repository, 'test@user-2')
88
text_form = t.as_text()
89
self.log('testament text form:\n' + text_form)
90
self.assertEqualDiff(text_form, REV_2_TESTAMENT)
91
actual_short = t.as_short_text()
92
self.assertEqualDiff(actual_short, REV_2_SHORT)
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)
103
def test_testament_command(self):
104
"""Testament containing a file and a directory."""
105
out, err = self.run_bzr_captured(['testament', '--long'])
106
self.assertEqualDiff(err, '')
107
self.assertEqualDiff(out, REV_2_TESTAMENT)
109
def test_testament_command_2(self):
110
"""Command getting short testament of previous version."""
111
out, err = self.run_bzr_captured(['testament', '-r1'])
112
self.assertEqualDiff(err, '')
113
self.assertEqualDiff(out, REV_1_SHORT)
115
def test_testament_command_3(self):
116
"""Command getting short testament of previous version."""
117
out, err = self.run_bzr_captured(['testament', '-r1', '--strict'])
118
self.assertEqualDiff(err, '')
119
self.assertEqualDiff(out, REV_1_SHORT_STRICT)
121
def test_testament_symlinks(self):
122
"""Testament containing symlink (where possible)"""
123
if not has_symlinks():
125
os.symlink('wibble/linktarget', 'link')
126
self.wt.add(['link'], ['link-id'])
127
self.wt.commit(message='add symlink',
128
timestamp=1129025493,
130
rev_id='test@user-3',
131
committer='test@user')
132
t = Testament.from_revision(self.b.repository, 'test@user-3')
133
self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
135
def test_testament_revprops(self):
136
"""Testament to revision with extra properties"""
137
props = dict(flavor='sour cherry\ncream cheese',
141
self.wt.commit(message='revision with properties',
142
timestamp=1129025493,
144
rev_id='test@user-3',
145
committer='test@user',
147
t = Testament.from_revision(self.b.repository, 'test@user-3')
148
self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
150
def test_testament_unicode_commit_message(self):
152
message=u'non-ascii commit \N{COPYRIGHT SIGN} me',
153
timestamp=1129025493,
155
rev_id='test@user-3',
156
committer='test@user')
157
t = Testament.from_revision(self.b.repository, 'test@user-3')
158
self.assertEqualDiff(
159
SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text())
161
def test___init__(self):
162
revision = self.b.repository.get_revision('test@user-2')
163
inventory = self.b.repository.get_inventory('test@user-2')
164
testament_1 = Testament(revision, inventory).as_short_text()
165
testament_2 = Testament.from_revision(self.b.repository,
166
'test@user-2').as_short_text()
167
self.assertEqual(testament_1, testament_2)
170
REV_1_TESTAMENT = """\
171
bazaar-ng testament version 1
172
revision-id: test@user-1
174
timestamp: 1129025423
185
REV_1_STRICT_TESTAMENT = """\
186
bazaar-ng testament version 2.1
187
revision-id: test@user-1
189
timestamp: 1129025423
202
bazaar-ng testament short form 1
203
revision-id: test@user-1
205
""" % sha(REV_1_TESTAMENT).hexdigest()
208
REV_1_SHORT_STRICT = """\
209
bazaar-ng testament short form 2.1
210
revision-id: test@user-1
212
""" % sha(REV_1_STRICT_TESTAMENT).hexdigest()
215
REV_2_TESTAMENT = """\
216
bazaar-ng testament version 1
217
revision-id: test@user-2
219
timestamp: 1129025483
224
add files and directories
226
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
228
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
235
REV_2_STRICT_TESTAMENT = """\
236
bazaar-ng testament version 2.1
237
revision-id: test@user-2
239
timestamp: 1129025483
244
add files and directories
246
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
247
directory src src-id test@user-2 no
248
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
256
bazaar-ng testament short form 1
257
revision-id: test@user-2
259
""" % sha(REV_2_TESTAMENT).hexdigest()
262
REV_2_SHORT_STRICT = """\
263
bazaar-ng testament short form 2.1
264
revision-id: test@user-2
266
""" % sha(REV_2_STRICT_TESTAMENT).hexdigest()
269
REV_PROPS_TESTAMENT = """\
270
bazaar-ng testament version 1
271
revision-id: test@user-3
273
timestamp: 1129025493
278
revision with properties
280
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
282
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
295
REV_3_TESTAMENT = """\
296
bazaar-ng testament version 1
297
revision-id: test@user-3
299
timestamp: 1129025493
306
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
307
symlink link link-id wibble/linktarget
309
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
316
SAMPLE_UNICODE_TESTAMENT = u"""\
317
bazaar-ng testament version 1
318
revision-id: test@user-3
320
timestamp: 1129025493
325
non-ascii commit \N{COPYRIGHT SIGN} me
327
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
329
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24