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.selftest import TestCaseInTempDir
26
from bzrlib.selftest.treeshape import build_tree_contents
27
from bzrlib.branch import Branch
28
from bzrlib.testament import Testament
29
from bzrlib.trace import mutter
30
from bzrlib.osutils import has_symlinks
32
class TestamentTests(TestCaseInTempDir):
34
super(TestamentTests, self).setUp()
35
b = self.b = Branch.initialize('.')
36
b.commit(message='initial null commit',
37
committer='test@user',
38
timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
41
build_tree_contents([('hello', 'contents of hello file'),
43
('src/foo.c', 'int main()\n{\n}\n')])
44
b.add(['hello', 'src', 'src/foo.c'],
45
['hello-id', 'src-id', 'foo.c-id'])
46
b.commit(message='add files and directories',
50
committer='test@user')
52
def test_null_testament(self):
53
"""Testament for a revision with no contents."""
54
t = Testament.from_revision(self.b, 'test@user-1')
57
ass(isinstance(t, Testament))
58
eq(t.revision_id, 'test@user-1')
59
eq(t.committer, 'test@user')
60
eq(t.timestamp, 1129025423)
63
def test_testment_text_form(self):
64
"""Conversion of testament to canonical text form."""
65
t = Testament.from_revision(self.b, 'test@user-1')
66
text_form = t.as_text()
67
self.log('testament text form:\n' + text_form)
68
self.assertEqual(text_form, REV_1_TESTAMENT)
70
def test_testament_with_contents(self):
71
"""Testament containing a file and a directory."""
72
t = Testament.from_revision(self.b, 'test@user-2')
73
text_form = t.as_text()
74
self.log('testament text form:\n' + text_form)
75
self.assertEqualDiff(text_form, REV_2_TESTAMENT)
76
actual_short = t.as_short_text()
77
self.assertEqualDiff(actual_short, REV_2_SHORT)
79
def test_testament_command(self):
80
"""Testament containing a file and a directory."""
81
out, err = self.run_bzr_captured(['testament', '--long'])
82
self.assertEqualDiff(err, '')
83
self.assertEqualDiff(out, REV_2_TESTAMENT)
85
def test_testament_command_2(self):
86
"""Command getting short testament of previous version."""
87
out, err = self.run_bzr_captured(['testament', '-r1'])
88
self.assertEqualDiff(err, '')
89
self.assertEqualDiff(out, REV_1_SHORT)
91
def test_testament_symlinks(self):
92
"""Testament containing symlink (where possible)"""
93
if not has_symlinks():
95
os.symlink('wibble/linktarget', 'link')
96
self.b.add(['link'], ['link-id'])
97
self.b.commit(message='add symlink',
100
rev_id='test@user-3',
101
committer='test@user')
102
t = Testament.from_revision(self.b, 'test@user-3')
103
self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
105
def test_testament_revprops(self):
106
"""Testament to revision with extra properties"""
107
props = dict(flavor='sour cherry\ncream cheese',
109
self.b.commit(message='revision with properties',
110
timestamp=1129025493,
112
rev_id='test@user-3',
113
committer='test@user',
115
t = Testament.from_revision(self.b, 'test@user-3')
116
self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
119
REV_1_TESTAMENT = """\
120
bazaar-ng testament version 1
121
revision-id: test@user-1
123
timestamp: 1129025423
132
bazaar-ng testament short form 1
133
revision-id: test@user-1
135
""" % sha(REV_1_TESTAMENT).hexdigest()
138
REV_2_TESTAMENT = """\
139
bazaar-ng testament version 1
140
revision-id: test@user-2
142
timestamp: 1129025483
147
add files and directories
149
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
151
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
156
bazaar-ng testament short form 1
157
revision-id: test@user-2
159
""" % sha(REV_2_TESTAMENT).hexdigest()
162
REV_PROPS_TESTAMENT = """\
163
bazaar-ng testament version 1
164
revision-id: test@user-3
166
timestamp: 1129025493
171
revision with properties
173
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
175
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
185
REV_3_TESTAMENT = """\
186
bazaar-ng testament version 1
187
revision-id: test@user-3
189
timestamp: 1129025493
196
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
197
symlink link link-id wibble/linktarget
199
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24