1185.16.12
by Martin Pool
- basic testament class |
1 |
# Copyright (C) 2005 by Canonical Ltd
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
17 |
"""Test testaments for gpg signing."""
|
|
18 |
||
1185.16.25
by Martin Pool
- testament symlink support |
19 |
# TODO: Testaments with x-bits
|
1185.16.23
by Martin Pool
- clean up imports |
20 |
|
1185.16.12
by Martin Pool
- basic testament class |
21 |
import os |
1185.16.22
by Martin Pool
- more testament development |
22 |
from sha import sha |
1185.16.12
by Martin Pool
- basic testament class |
23 |
import sys |
24 |
||
25 |
from bzrlib.selftest import TestCaseInTempDir |
|
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
26 |
from bzrlib.selftest.treeshape import build_tree_contents |
1185.16.12
by Martin Pool
- basic testament class |
27 |
from bzrlib.branch import Branch |
28 |
from bzrlib.testament import Testament |
|
1185.16.15
by Martin Pool
- test text form for testaments |
29 |
from bzrlib.trace import mutter |
1185.16.25
by Martin Pool
- testament symlink support |
30 |
from bzrlib.osutils import has_symlinks |
1185.16.12
by Martin Pool
- basic testament class |
31 |
|
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
32 |
|
1185.16.12
by Martin Pool
- basic testament class |
33 |
class TestamentTests(TestCaseInTempDir): |
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
34 |
|
1185.16.15
by Martin Pool
- test text form for testaments |
35 |
def setUp(self): |
36 |
super(TestamentTests, self).setUp() |
|
37 |
b = self.b = Branch.initialize('.') |
|
1185.35.16
by Aaron Bentley
Fixed tests |
38 |
b.nick = "test branch" |
1457.1.17
by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins) |
39 |
b.working_tree().commit(message='initial null commit', |
1185.16.12
by Martin Pool
- basic testament class |
40 |
committer='test@user', |
41 |
timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005' |
|
42 |
timezone=0, |
|
43 |
rev_id='test@user-1') |
|
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
44 |
build_tree_contents([('hello', 'contents of hello file'), |
45 |
('src/', ), |
|
1185.16.22
by Martin Pool
- more testament development |
46 |
('src/foo.c', 'int main()\n{\n}\n')]) |
47 |
b.add(['hello', 'src', 'src/foo.c'], |
|
48 |
['hello-id', 'src-id', 'foo.c-id']) |
|
1457.1.17
by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins) |
49 |
b.working_tree().commit(message='add files and directories', |
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
50 |
timestamp=1129025483, |
51 |
timezone=36000, |
|
52 |
rev_id='test@user-2', |
|
53 |
committer='test@user') |
|
1185.16.15
by Martin Pool
- test text form for testaments |
54 |
|
55 |
def test_null_testament(self): |
|
56 |
"""Testament for a revision with no contents."""
|
|
57 |
t = Testament.from_revision(self.b, 'test@user-1') |
|
1185.16.12
by Martin Pool
- basic testament class |
58 |
ass = self.assertTrue |
59 |
eq = self.assertEqual |
|
60 |
ass(isinstance(t, Testament)) |
|
61 |
eq(t.revision_id, 'test@user-1') |
|
62 |
eq(t.committer, 'test@user') |
|
63 |
eq(t.timestamp, 1129025423) |
|
64 |
eq(t.timezone, 0) |
|
65 |
||
1185.16.15
by Martin Pool
- test text form for testaments |
66 |
def test_testment_text_form(self): |
67 |
"""Conversion of testament to canonical text form."""
|
|
68 |
t = Testament.from_revision(self.b, 'test@user-1') |
|
1185.16.22
by Martin Pool
- more testament development |
69 |
text_form = t.as_text() |
1185.16.15
by Martin Pool
- test text form for testaments |
70 |
self.log('testament text form:\n' + text_form) |
1185.16.25
by Martin Pool
- testament symlink support |
71 |
self.assertEqual(text_form, REV_1_TESTAMENT) |
1185.16.15
by Martin Pool
- test text form for testaments |
72 |
|
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
73 |
def test_testament_with_contents(self): |
74 |
"""Testament containing a file and a directory."""
|
|
75 |
t = Testament.from_revision(self.b, 'test@user-2') |
|
1185.16.22
by Martin Pool
- more testament development |
76 |
text_form = t.as_text() |
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
77 |
self.log('testament text form:\n' + text_form) |
1185.16.24
by Martin Pool
- add and test 'testament' builtin command |
78 |
self.assertEqualDiff(text_form, REV_2_TESTAMENT) |
79 |
actual_short = t.as_short_text() |
|
1185.16.25
by Martin Pool
- testament symlink support |
80 |
self.assertEqualDiff(actual_short, REV_2_SHORT) |
1185.16.24
by Martin Pool
- add and test 'testament' builtin command |
81 |
|
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) |
|
87 |
||
1185.16.25
by Martin Pool
- testament symlink support |
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) |
|
93 |
||
94 |
def test_testament_symlinks(self): |
|
95 |
"""Testament containing symlink (where possible)"""
|
|
96 |
if not has_symlinks(): |
|
97 |
return
|
|
98 |
os.symlink('wibble/linktarget', 'link') |
|
99 |
self.b.add(['link'], ['link-id']) |
|
1457.1.17
by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins) |
100 |
self.b.working_tree().commit(message='add symlink', |
1185.16.25
by Martin Pool
- testament symlink support |
101 |
timestamp=1129025493, |
102 |
timezone=36000, |
|
103 |
rev_id='test@user-3', |
|
104 |
committer='test@user') |
|
105 |
t = Testament.from_revision(self.b, 'test@user-3') |
|
106 |
self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT) |
|
107 |
||
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
108 |
def test_testament_revprops(self): |
109 |
"""Testament to revision with extra properties"""
|
|
110 |
props = dict(flavor='sour cherry\ncream cheese', |
|
111 |
size='medium') |
|
1457.1.17
by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins) |
112 |
self.b.working_tree().commit(message='revision with properties', |
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
113 |
timestamp=1129025493, |
114 |
timezone=36000, |
|
115 |
rev_id='test@user-3', |
|
116 |
committer='test@user', |
|
117 |
revprops=props) |
|
118 |
t = Testament.from_revision(self.b, 'test@user-3') |
|
119 |
self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT) |
|
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
120 |
|
121 |
def test___init__(self): |
|
122 |
revision = self.b.get_revision('test@user-2') |
|
123 |
inventory = self.b.get_inventory('test@user-2') |
|
124 |
testament_1 = Testament(revision, inventory).as_short_text() |
|
125 |
testament_2 = Testament.from_revision(self.b, |
|
126 |
'test@user-2').as_short_text() |
|
127 |
self.assertEqual(testament_1, testament_2) |
|
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
128 |
|
1185.16.25
by Martin Pool
- testament symlink support |
129 |
|
130 |
REV_1_TESTAMENT = """\ |
|
131 |
bazaar-ng testament version 1
|
|
132 |
revision-id: test@user-1
|
|
133 |
committer: test@user
|
|
134 |
timestamp: 1129025423
|
|
135 |
timezone: 0
|
|
136 |
parents:
|
|
137 |
message:
|
|
138 |
initial null commit
|
|
139 |
inventory:
|
|
1185.35.16
by Aaron Bentley
Fixed tests |
140 |
properties:
|
141 |
branch-nick:
|
|
142 |
test branch
|
|
1185.16.25
by Martin Pool
- testament symlink support |
143 |
"""
|
144 |
||
145 |
REV_1_SHORT = """\ |
|
146 |
bazaar-ng testament short form 1
|
|
147 |
revision-id: test@user-1
|
|
148 |
sha1: %s |
|
149 |
""" % sha(REV_1_TESTAMENT).hexdigest() |
|
150 |
||
1185.16.24
by Martin Pool
- add and test 'testament' builtin command |
151 |
|
152 |
REV_2_TESTAMENT = """\ |
|
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
153 |
bazaar-ng testament version 1
|
154 |
revision-id: test@user-2
|
|
155 |
committer: test@user
|
|
1185.16.22
by Martin Pool
- more testament development |
156 |
timestamp: 1129025483
|
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
157 |
timezone: 36000
|
158 |
parents:
|
|
159 |
test@user-1
|
|
160 |
message:
|
|
161 |
add files and directories
|
|
162 |
inventory:
|
|
1185.16.22
by Martin Pool
- more testament development |
163 |
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
|
164 |
directory src src-id
|
|
165 |
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
|
|
1185.35.16
by Aaron Bentley
Fixed tests |
166 |
properties:
|
167 |
branch-nick:
|
|
168 |
test branch
|
|
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
169 |
"""
|
1185.16.25
by Martin Pool
- testament symlink support |
170 |
|
171 |
||
172 |
REV_2_SHORT = """\ |
|
173 |
bazaar-ng testament short form 1
|
|
174 |
revision-id: test@user-2
|
|
175 |
sha1: %s |
|
176 |
""" % sha(REV_2_TESTAMENT).hexdigest() |
|
177 |
||
178 |
||
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
179 |
REV_PROPS_TESTAMENT = """\ |
180 |
bazaar-ng testament version 1
|
|
181 |
revision-id: test@user-3
|
|
182 |
committer: test@user
|
|
183 |
timestamp: 1129025493
|
|
184 |
timezone: 36000
|
|
185 |
parents:
|
|
186 |
test@user-2
|
|
187 |
message:
|
|
188 |
revision with properties
|
|
189 |
inventory:
|
|
190 |
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
|
|
191 |
directory src src-id
|
|
192 |
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
|
|
193 |
properties:
|
|
1185.35.16
by Aaron Bentley
Fixed tests |
194 |
branch-nick:
|
195 |
test branch
|
|
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
196 |
flavor:
|
197 |
sour cherry
|
|
198 |
cream cheese
|
|
199 |
size:
|
|
200 |
medium
|
|
201 |
"""
|
|
202 |
||
203 |
||
1185.16.25
by Martin Pool
- testament symlink support |
204 |
REV_3_TESTAMENT = """\ |
205 |
bazaar-ng testament version 1
|
|
206 |
revision-id: test@user-3
|
|
207 |
committer: test@user
|
|
208 |
timestamp: 1129025493
|
|
209 |
timezone: 36000
|
|
210 |
parents:
|
|
211 |
test@user-2
|
|
212 |
message:
|
|
213 |
add symlink
|
|
214 |
inventory:
|
|
215 |
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
|
|
216 |
symlink link link-id wibble/linktarget
|
|
217 |
directory src src-id
|
|
218 |
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
|
|
1185.35.16
by Aaron Bentley
Fixed tests |
219 |
properties:
|
220 |
branch-nick:
|
|
221 |
test branch
|
|
1185.16.25
by Martin Pool
- testament symlink support |
222 |
"""
|