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___init__(self):
122
revision = self.b.repository.get_revision('test@user-2')
123
inventory = self.b.repository.get_inventory('test@user-2')
124
testament_1 = Testament(revision, inventory).as_short_text()
125
testament_2 = Testament.from_revision(self.b.repository,
126
'test@user-2').as_short_text()
127
self.assertEqual(testament_1, testament_2)
130
REV_1_TESTAMENT = """\
131
bazaar-ng testament version 1
132
revision-id: test@user-1
134
timestamp: 1129025423
146
bazaar-ng testament short form 1
147
revision-id: test@user-1
149
""" % sha(REV_1_TESTAMENT).hexdigest()
152
REV_2_TESTAMENT = """\
153
bazaar-ng testament version 1
154
revision-id: test@user-2
156
timestamp: 1129025483
161
add files and directories
163
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
165
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
173
bazaar-ng testament short form 1
174
revision-id: test@user-2
176
""" % sha(REV_2_TESTAMENT).hexdigest()
179
REV_PROPS_TESTAMENT = """\
180
bazaar-ng testament version 1
181
revision-id: test@user-3
183
timestamp: 1129025493
188
revision with properties
190
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
192
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
204
REV_3_TESTAMENT = """\
205
bazaar-ng testament version 1
206
revision-id: test@user-3
208
timestamp: 1129025493
215
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
216
symlink link link-id wibble/linktarget
218
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24