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
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_testament_with_contents(self):
74
"""Testament containing a file and a directory."""
75
t = Testament.from_revision(self.b.repository, 'test@user-2')
76
text_form = t.as_text()
77
self.log('testament text form:\n' + text_form)
78
self.assertEqualDiff(text_form, REV_2_TESTAMENT)
79
actual_short = t.as_short_text()
80
self.assertEqualDiff(actual_short, REV_2_SHORT)
82
def test_testament_command(self):
83
"""Testament containing a file and a directory."""
84
out, err = self.run_bzr_captured(['testament', '--long'])
85
self.assertEqualDiff(err, '')
86
self.assertEqualDiff(out, REV_2_TESTAMENT)
88
def test_testament_command_2(self):
89
"""Command getting short testament of previous version."""
90
out, err = self.run_bzr_captured(['testament', '-r1'])
91
self.assertEqualDiff(err, '')
92
self.assertEqualDiff(out, REV_1_SHORT)
94
def test_testament_symlinks(self):
95
"""Testament containing symlink (where possible)"""
96
if not has_symlinks():
98
os.symlink('wibble/linktarget', 'link')
99
self.wt.add(['link'], ['link-id'])
100
self.wt.commit(message='add symlink',
101
timestamp=1129025493,
103
rev_id='test@user-3',
104
committer='test@user')
105
t = Testament.from_revision(self.b.repository, 'test@user-3')
106
self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
108
def test_testament_revprops(self):
109
"""Testament to revision with extra properties"""
110
props = dict(flavor='sour cherry\ncream cheese',
112
self.wt.commit(message='revision with properties',
113
timestamp=1129025493,
115
rev_id='test@user-3',
116
committer='test@user',
118
t = Testament.from_revision(self.b.repository, 'test@user-3')
119
self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
121
def test_testament_unicode_commit_message(self):
123
message=u'non-ascii commit \N{COPYRIGHT SIGN} me',
124
timestamp=1129025493,
126
rev_id='test@user-3',
127
committer='test@user')
128
t = Testament.from_revision(self.b.repository, 'test@user-3')
129
self.assertEqualDiff(
130
SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text())
132
def test___init__(self):
133
revision = self.b.repository.get_revision('test@user-2')
134
inventory = self.b.repository.get_inventory('test@user-2')
135
testament_1 = Testament(revision, inventory).as_short_text()
136
testament_2 = Testament.from_revision(self.b.repository,
137
'test@user-2').as_short_text()
138
self.assertEqual(testament_1, testament_2)
141
REV_1_TESTAMENT = """\
142
bazaar-ng testament version 1
143
revision-id: test@user-1
145
timestamp: 1129025423
157
bazaar-ng testament short form 1
158
revision-id: test@user-1
160
""" % sha(REV_1_TESTAMENT).hexdigest()
163
REV_2_TESTAMENT = """\
164
bazaar-ng testament version 1
165
revision-id: test@user-2
167
timestamp: 1129025483
172
add files and directories
174
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
176
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
184
bazaar-ng testament short form 1
185
revision-id: test@user-2
187
""" % sha(REV_2_TESTAMENT).hexdigest()
190
REV_PROPS_TESTAMENT = """\
191
bazaar-ng testament version 1
192
revision-id: test@user-3
194
timestamp: 1129025493
199
revision with properties
201
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
203
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
215
REV_3_TESTAMENT = """\
216
bazaar-ng testament version 1
217
revision-id: test@user-3
219
timestamp: 1129025493
226
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
227
symlink link link-id wibble/linktarget
229
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
236
SAMPLE_UNICODE_TESTAMENT = u"""\
237
bazaar-ng testament version 1
238
revision-id: test@user-3
240
timestamp: 1129025493
245
non-ascii commit \N{COPYRIGHT SIGN} me
247
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
249
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24