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',
139
self.wt.commit(message='revision with properties',
140
timestamp=1129025493,
142
rev_id='test@user-3',
143
committer='test@user',
145
t = Testament.from_revision(self.b.repository, 'test@user-3')
146
self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
148
def test_testament_unicode_commit_message(self):
150
message=u'non-ascii commit \N{COPYRIGHT SIGN} me',
151
timestamp=1129025493,
153
rev_id='test@user-3',
154
committer='test@user')
155
t = Testament.from_revision(self.b.repository, 'test@user-3')
156
self.assertEqualDiff(
157
SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text())
159
def test___init__(self):
160
revision = self.b.repository.get_revision('test@user-2')
161
inventory = self.b.repository.get_inventory('test@user-2')
162
testament_1 = Testament(revision, inventory).as_short_text()
163
testament_2 = Testament.from_revision(self.b.repository,
164
'test@user-2').as_short_text()
165
self.assertEqual(testament_1, testament_2)
168
REV_1_TESTAMENT = """\
169
bazaar-ng testament version 1
170
revision-id: test@user-1
172
timestamp: 1129025423
183
REV_1_STRICT_TESTAMENT = """\
184
bazaar-ng testament version 2.1
185
revision-id: test@user-1
187
timestamp: 1129025423
200
bazaar-ng testament short form 1
201
revision-id: test@user-1
203
""" % sha(REV_1_TESTAMENT).hexdigest()
206
REV_1_SHORT_STRICT = """\
207
bazaar-ng testament short form 2.1
208
revision-id: test@user-1
210
""" % sha(REV_1_STRICT_TESTAMENT).hexdigest()
213
REV_2_TESTAMENT = """\
214
bazaar-ng testament version 1
215
revision-id: test@user-2
217
timestamp: 1129025483
222
add files and directories
224
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
226
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
233
REV_2_STRICT_TESTAMENT = """\
234
bazaar-ng testament version 2.1
235
revision-id: test@user-2
237
timestamp: 1129025483
242
add files and directories
244
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
245
directory src src-id test@user-2 no
246
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
254
bazaar-ng testament short form 1
255
revision-id: test@user-2
257
""" % sha(REV_2_TESTAMENT).hexdigest()
260
REV_2_SHORT_STRICT = """\
261
bazaar-ng testament short form 2.1
262
revision-id: test@user-2
264
""" % sha(REV_2_STRICT_TESTAMENT).hexdigest()
267
REV_PROPS_TESTAMENT = """\
268
bazaar-ng testament version 1
269
revision-id: test@user-3
271
timestamp: 1129025493
276
revision with properties
278
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
280
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
292
REV_3_TESTAMENT = """\
293
bazaar-ng testament version 1
294
revision-id: test@user-3
296
timestamp: 1129025493
303
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
304
symlink link link-id wibble/linktarget
306
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
313
SAMPLE_UNICODE_TESTAMENT = u"""\
314
bazaar-ng testament version 1
315
revision-id: test@user-3
317
timestamp: 1129025493
322
non-ascii commit \N{COPYRIGHT SIGN} me
324
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
326
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24