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
24
from bzrlib.tests import TestCaseWithTransport
25
from bzrlib.testament import Testament, StrictTestament
26
from bzrlib.transform import TreeTransform
27
from bzrlib.osutils import has_symlinks
30
class TestamentSetup(TestCaseWithTransport):
33
super(TestamentSetup, self).setUp()
34
self.wt = self.make_branch_and_tree('.')
35
b = self.b = self.wt.branch
36
b.nick = "test branch"
37
self.wt.commit(message='initial null commit',
38
committer='test@user',
39
timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
42
self.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',
55
committer='test@user')
58
class TestamentTests(TestamentSetup):
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_symlinks(self):
104
"""Testament containing symlink (where possible)"""
105
if not has_symlinks():
107
os.symlink('wibble/linktarget', 'link')
108
self.wt.add(['link'], ['link-id'])
109
self.wt.commit(message='add symlink',
110
timestamp=1129025493,
112
rev_id='test@user-3',
113
committer='test@user')
114
t = Testament.from_revision(self.b.repository, 'test@user-3')
115
self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
117
def test_testament_revprops(self):
118
"""Testament to revision with extra properties"""
119
props = dict(flavor='sour cherry\ncream cheese',
123
self.wt.commit(message='revision with properties',
124
timestamp=1129025493,
126
rev_id='test@user-3',
127
committer='test@user',
129
t = Testament.from_revision(self.b.repository, 'test@user-3')
130
self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
132
def test_testament_unicode_commit_message(self):
134
message=u'non-ascii commit \N{COPYRIGHT SIGN} me',
135
timestamp=1129025493,
137
rev_id='test@user-3',
138
committer='Erik B\xe5gfors <test@user>',
139
revprops={'uni':u'\xb5'}
141
t = Testament.from_revision(self.b.repository, 'test@user-3')
142
self.assertEqualDiff(
143
SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text())
145
def test___init__(self):
146
revision = self.b.repository.get_revision('test@user-2')
147
inventory = self.b.repository.get_inventory('test@user-2')
148
testament_1 = Testament(revision, inventory).as_short_text()
149
testament_2 = Testament.from_revision(self.b.repository,
150
'test@user-2').as_short_text()
151
self.assertEqual(testament_1, testament_2)
154
REV_1_TESTAMENT = """\
155
bazaar-ng testament version 1
156
revision-id: test@user-1
158
timestamp: 1129025423
169
REV_1_STRICT_TESTAMENT = """\
170
bazaar-ng testament version 2.1
171
revision-id: test@user-1
173
timestamp: 1129025423
186
bazaar-ng testament short form 1
187
revision-id: test@user-1
189
""" % sha(REV_1_TESTAMENT).hexdigest()
192
REV_1_SHORT_STRICT = """\
193
bazaar-ng testament short form 2.1
194
revision-id: test@user-1
196
""" % sha(REV_1_STRICT_TESTAMENT).hexdigest()
199
REV_2_TESTAMENT = """\
200
bazaar-ng testament version 1
201
revision-id: test@user-2
203
timestamp: 1129025483
208
add files and directories
210
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
212
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
219
REV_2_STRICT_TESTAMENT = """\
220
bazaar-ng testament version 2.1
221
revision-id: test@user-2
223
timestamp: 1129025483
228
add files and directories
230
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
231
directory src src-id test@user-2 no
232
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
240
bazaar-ng testament short form 1
241
revision-id: test@user-2
243
""" % sha(REV_2_TESTAMENT).hexdigest()
246
REV_2_SHORT_STRICT = """\
247
bazaar-ng testament short form 2.1
248
revision-id: test@user-2
250
""" % sha(REV_2_STRICT_TESTAMENT).hexdigest()
253
REV_PROPS_TESTAMENT = """\
254
bazaar-ng testament version 1
255
revision-id: test@user-3
257
timestamp: 1129025493
262
revision with properties
264
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
266
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
279
REV_3_TESTAMENT = """\
280
bazaar-ng testament version 1
281
revision-id: test@user-3
283
timestamp: 1129025493
290
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
291
symlink link link-id wibble/linktarget
293
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
300
SAMPLE_UNICODE_TESTAMENT = u"""\
301
bazaar-ng testament version 1
302
revision-id: test@user-3
303
committer: Erik B\xe5gfors <test@user>
304
timestamp: 1129025493
309
non-ascii commit \N{COPYRIGHT SIGN} me
311
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
313
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24