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.osutils import has_symlinks
32
class TestamentTests(TestCaseWithTransport):
35
super(TestamentTests, self).setUp()
36
self.wt = self.make_branch_and_tree('.')
37
b = self.b = self.wt.branch
38
b.nick = "test branch"
39
self.wt.commit(message='initial null commit',
40
committer='test@user',
41
timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
44
self.build_tree_contents([('hello', 'contents of hello file'),
46
('src/foo.c', 'int main()\n{\n}\n')])
47
self.wt.add(['hello', 'src', 'src/foo.c'],
48
['hello-id', 'src-id', 'foo.c-id'])
49
self.wt.commit(message='add files and directories',
53
committer='test@user')
55
def test_null_testament(self):
56
"""Testament for a revision with no contents."""
57
t = Testament.from_revision(self.b.repository, 'test@user-1')
60
ass(isinstance(t, Testament))
61
eq(t.revision_id, 'test@user-1')
62
eq(t.committer, 'test@user')
63
eq(t.timestamp, 1129025423)
66
def test_testment_text_form(self):
67
"""Conversion of testament to canonical text form."""
68
t = Testament.from_revision(self.b.repository, 'test@user-1')
69
text_form = t.as_text()
70
self.log('testament text form:\n' + text_form)
71
self.assertEqual(text_form, REV_1_TESTAMENT)
73
def test_strict_testment_text_form(self):
74
"""Conversion of testament to canonical text form."""
75
t = StrictTestament.from_revision(self.b.repository, 'test@user-1')
76
text_form = t.as_text()
77
self.log('testament text form:\n' + text_form)
78
self.assertEqualDiff(text_form, REV_1_STRICT_TESTAMENT)
80
def test_testament_with_contents(self):
81
"""Testament containing a file and a directory."""
82
t = Testament.from_revision(self.b.repository, 'test@user-2')
83
text_form = t.as_text()
84
self.log('testament text form:\n' + text_form)
85
self.assertEqualDiff(text_form, REV_2_TESTAMENT)
86
actual_short = t.as_short_text()
87
self.assertEqualDiff(actual_short, REV_2_SHORT)
89
def test_strict_testament_with_contents(self):
90
"""Testament containing a file and a directory."""
91
t = StrictTestament.from_revision(self.b.repository, 'test@user-2')
92
text_form = t.as_text()
93
self.log('testament text form:\n' + text_form)
94
self.assertEqualDiff(text_form, REV_2_STRICT_TESTAMENT)
95
actual_short = t.as_short_text()
96
self.assertEqualDiff(actual_short, REV_2_SHORT_STRICT)
98
def test_testament_command(self):
99
"""Testament containing a file and a directory."""
100
out, err = self.run_bzr_captured(['testament', '--long'])
101
self.assertEqualDiff(err, '')
102
self.assertEqualDiff(out, REV_2_TESTAMENT)
104
def test_testament_command_2(self):
105
"""Command getting short testament of previous version."""
106
out, err = self.run_bzr_captured(['testament', '-r1'])
107
self.assertEqualDiff(err, '')
108
self.assertEqualDiff(out, REV_1_SHORT)
110
def test_testament_command_3(self):
111
"""Command getting short testament of previous version."""
112
out, err = self.run_bzr_captured(['testament', '-r1', '--strict'])
113
self.assertEqualDiff(err, '')
114
self.assertEqualDiff(out, REV_1_SHORT_STRICT)
116
def test_testament_symlinks(self):
117
"""Testament containing symlink (where possible)"""
118
if not has_symlinks():
120
os.symlink('wibble/linktarget', 'link')
121
self.wt.add(['link'], ['link-id'])
122
self.wt.commit(message='add symlink',
123
timestamp=1129025493,
125
rev_id='test@user-3',
126
committer='test@user')
127
t = Testament.from_revision(self.b.repository, 'test@user-3')
128
self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
130
def test_testament_revprops(self):
131
"""Testament to revision with extra properties"""
132
props = dict(flavor='sour cherry\ncream cheese',
134
self.wt.commit(message='revision with properties',
135
timestamp=1129025493,
137
rev_id='test@user-3',
138
committer='test@user',
140
t = Testament.from_revision(self.b.repository, 'test@user-3')
141
self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
143
def test_testament_unicode_commit_message(self):
145
message=u'non-ascii commit \N{COPYRIGHT SIGN} me',
146
timestamp=1129025493,
148
rev_id='test@user-3',
149
committer='test@user')
150
t = Testament.from_revision(self.b.repository, 'test@user-3')
151
self.assertEqualDiff(
152
SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text())
154
def test___init__(self):
155
revision = self.b.repository.get_revision('test@user-2')
156
inventory = self.b.repository.get_inventory('test@user-2')
157
testament_1 = Testament(revision, inventory).as_short_text()
158
testament_2 = Testament.from_revision(self.b.repository,
159
'test@user-2').as_short_text()
160
self.assertEqual(testament_1, testament_2)
163
REV_1_TESTAMENT = """\
164
bazaar-ng testament version 1
165
revision-id: test@user-1
167
timestamp: 1129025423
178
REV_1_STRICT_TESTAMENT = """\
179
bazaar-ng testament version 2.1
180
revision-id: test@user-1
182
timestamp: 1129025423
195
bazaar-ng testament short form 1
196
revision-id: test@user-1
198
""" % sha(REV_1_TESTAMENT).hexdigest()
201
REV_1_SHORT_STRICT = """\
202
bazaar-ng testament short form 2.1
203
revision-id: test@user-1
205
""" % sha(REV_1_STRICT_TESTAMENT).hexdigest()
208
REV_2_TESTAMENT = """\
209
bazaar-ng testament version 1
210
revision-id: test@user-2
212
timestamp: 1129025483
217
add files and directories
219
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
221
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
228
REV_2_STRICT_TESTAMENT = """\
229
bazaar-ng testament version 2.1
230
revision-id: test@user-2
232
timestamp: 1129025483
237
add files and directories
239
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 no
240
directory src src-id test@user-2 no
241
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
249
bazaar-ng testament short form 1
250
revision-id: test@user-2
252
""" % sha(REV_2_TESTAMENT).hexdigest()
255
REV_2_SHORT_STRICT = """\
256
bazaar-ng testament short form 2.1
257
revision-id: test@user-2
259
""" % sha(REV_2_STRICT_TESTAMENT).hexdigest()
262
REV_PROPS_TESTAMENT = """\
263
bazaar-ng testament version 1
264
revision-id: test@user-3
266
timestamp: 1129025493
271
revision with properties
273
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
275
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
287
REV_3_TESTAMENT = """\
288
bazaar-ng testament version 1
289
revision-id: test@user-3
291
timestamp: 1129025493
298
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
299
symlink link link-id wibble/linktarget
301
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
308
SAMPLE_UNICODE_TESTAMENT = u"""\
309
bazaar-ng testament version 1
310
revision-id: test@user-3
312
timestamp: 1129025493
317
non-ascii commit \N{COPYRIGHT SIGN} me
319
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
321
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24