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 |
||
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
25 |
from bzrlib.tests import TestCaseWithTransport |
1185.16.12
by Martin Pool
- basic testament class |
26 |
from bzrlib.branch import Branch |
27 |
from bzrlib.testament import Testament |
|
1185.16.15
by Martin Pool
- test text form for testaments |
28 |
from bzrlib.trace import mutter |
1185.16.25
by Martin Pool
- testament symlink support |
29 |
from bzrlib.osutils import has_symlinks |
1185.16.12
by Martin Pool
- basic testament class |
30 |
|
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
31 |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
32 |
class TestamentTests(TestCaseWithTransport): |
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
33 |
|
1185.16.15
by Martin Pool
- test text form for testaments |
34 |
def setUp(self): |
35 |
super(TestamentTests, self).setUp() |
|
1534.4.36
by Robert Collins
Finish deprecating Branch.working_tree() |
36 |
self.wt = self.make_branch_and_tree('.') |
37 |
b = self.b = self.wt.branch |
|
1185.35.16
by Aaron Bentley
Fixed tests |
38 |
b.nick = "test branch" |
1534.4.36
by Robert Collins
Finish deprecating Branch.working_tree() |
39 |
self.wt.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') |
|
1514
by Robert Collins
Unbreak self.build_tree_shape in tests. |
44 |
self.build_tree_contents([('hello', 'contents of hello file'), |
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
45 |
('src/', ), |
1185.16.22
by Martin Pool
- more testament development |
46 |
('src/foo.c', 'int main()\n{\n}\n')]) |
1534.4.36
by Robert Collins
Finish deprecating Branch.working_tree() |
47 |
self.wt.add(['hello', 'src', 'src/foo.c'], |
1508.1.5
by Robert Collins
Move add from Branch to WorkingTree. |
48 |
['hello-id', 'src-id', 'foo.c-id']) |
1534.4.36
by Robert Collins
Finish deprecating Branch.working_tree() |
49 |
self.wt.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."""
|
|
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
57 |
t = Testament.from_revision(self.b.repository, '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."""
|
|
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
68 |
t = Testament.from_revision(self.b.repository, '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."""
|
|
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
75 |
t = Testament.from_revision(self.b.repository, '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') |
|
1534.4.36
by Robert Collins
Finish deprecating Branch.working_tree() |
99 |
self.wt.add(['link'], ['link-id']) |
100 |
self.wt.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') |
|
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
105 |
t = Testament.from_revision(self.b.repository, 'test@user-3') |
1185.16.25
by Martin Pool
- testament symlink support |
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') |
|
1534.4.36
by Robert Collins
Finish deprecating Branch.working_tree() |
112 |
self.wt.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) |
|
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
118 |
t = Testament.from_revision(self.b.repository, 'test@user-3') |
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
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 |
|
1553.3.1
by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this. |
121 |
def test_testament_unicode_commit_message(self): |
1558.1.3
by Aaron Bentley
Fixed deprecated op use in test suite |
122 |
self.wt.commit( |
1553.3.1
by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this. |
123 |
message=u'non-ascii commit \N{COPYRIGHT SIGN} me', |
124 |
timestamp=1129025493, |
|
125 |
timezone=36000, |
|
126 |
rev_id='test@user-3', |
|
127 |
committer='test@user') |
|
128 |
t = Testament.from_revision(self.b.repository, 'test@user-3') |
|
1553.3.4
by Marien Zwart
Move the encoding step into the test to make it more obvious we are comparing bytestrings. |
129 |
self.assertEqualDiff( |
1185.50.79
by John Arbash Meinel
small cleanup of test |
130 |
SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text()) |
1553.3.1
by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this. |
131 |
|
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
132 |
def test___init__(self): |
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
133 |
revision = self.b.repository.get_revision('test@user-2') |
134 |
inventory = self.b.repository.get_inventory('test@user-2') |
|
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
135 |
testament_1 = Testament(revision, inventory).as_short_text() |
1185.67.2
by Aaron Bentley
Renamed Branch.storage to Branch.repository |
136 |
testament_2 = Testament.from_revision(self.b.repository, |
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
137 |
'test@user-2').as_short_text() |
138 |
self.assertEqual(testament_1, testament_2) |
|
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
139 |
|
1185.16.25
by Martin Pool
- testament symlink support |
140 |
|
141 |
REV_1_TESTAMENT = """\ |
|
142 |
bazaar-ng testament version 1
|
|
143 |
revision-id: test@user-1
|
|
144 |
committer: test@user
|
|
145 |
timestamp: 1129025423
|
|
146 |
timezone: 0
|
|
147 |
parents:
|
|
148 |
message:
|
|
149 |
initial null commit
|
|
150 |
inventory:
|
|
1185.35.16
by Aaron Bentley
Fixed tests |
151 |
properties:
|
152 |
branch-nick:
|
|
153 |
test branch
|
|
1185.16.25
by Martin Pool
- testament symlink support |
154 |
"""
|
155 |
||
156 |
REV_1_SHORT = """\ |
|
157 |
bazaar-ng testament short form 1
|
|
158 |
revision-id: test@user-1
|
|
159 |
sha1: %s |
|
160 |
""" % sha(REV_1_TESTAMENT).hexdigest() |
|
161 |
||
1185.16.24
by Martin Pool
- add and test 'testament' builtin command |
162 |
|
163 |
REV_2_TESTAMENT = """\ |
|
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
164 |
bazaar-ng testament version 1
|
165 |
revision-id: test@user-2
|
|
166 |
committer: test@user
|
|
1185.16.22
by Martin Pool
- more testament development |
167 |
timestamp: 1129025483
|
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
168 |
timezone: 36000
|
169 |
parents:
|
|
170 |
test@user-1
|
|
171 |
message:
|
|
172 |
add files and directories
|
|
173 |
inventory:
|
|
1185.16.22
by Martin Pool
- more testament development |
174 |
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
|
175 |
directory src src-id
|
|
176 |
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
|
|
1185.35.16
by Aaron Bentley
Fixed tests |
177 |
properties:
|
178 |
branch-nick:
|
|
179 |
test branch
|
|
1185.16.19
by Martin Pool
- testament now contains summary of parents and inventory |
180 |
"""
|
1185.16.25
by Martin Pool
- testament symlink support |
181 |
|
182 |
||
183 |
REV_2_SHORT = """\ |
|
184 |
bazaar-ng testament short form 1
|
|
185 |
revision-id: test@user-2
|
|
186 |
sha1: %s |
|
187 |
""" % sha(REV_2_TESTAMENT).hexdigest() |
|
188 |
||
189 |
||
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
190 |
REV_PROPS_TESTAMENT = """\ |
191 |
bazaar-ng testament version 1
|
|
192 |
revision-id: test@user-3
|
|
193 |
committer: test@user
|
|
194 |
timestamp: 1129025493
|
|
195 |
timezone: 36000
|
|
196 |
parents:
|
|
197 |
test@user-2
|
|
198 |
message:
|
|
199 |
revision with properties
|
|
200 |
inventory:
|
|
201 |
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
|
|
202 |
directory src src-id
|
|
203 |
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
|
|
204 |
properties:
|
|
1185.35.16
by Aaron Bentley
Fixed tests |
205 |
branch-nick:
|
206 |
test branch
|
|
1185.16.59
by mbp at sourcefrog
- store revprops in testaments |
207 |
flavor:
|
208 |
sour cherry
|
|
209 |
cream cheese
|
|
210 |
size:
|
|
211 |
medium
|
|
212 |
"""
|
|
213 |
||
214 |
||
1185.16.25
by Martin Pool
- testament symlink support |
215 |
REV_3_TESTAMENT = """\ |
216 |
bazaar-ng testament version 1
|
|
217 |
revision-id: test@user-3
|
|
218 |
committer: test@user
|
|
219 |
timestamp: 1129025493
|
|
220 |
timezone: 36000
|
|
221 |
parents:
|
|
222 |
test@user-2
|
|
223 |
message:
|
|
224 |
add symlink
|
|
225 |
inventory:
|
|
226 |
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
|
|
227 |
symlink link link-id wibble/linktarget
|
|
228 |
directory src src-id
|
|
229 |
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
|
|
1185.35.16
by Aaron Bentley
Fixed tests |
230 |
properties:
|
231 |
branch-nick:
|
|
232 |
test branch
|
|
1185.16.25
by Martin Pool
- testament symlink support |
233 |
"""
|
1553.3.1
by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this. |
234 |
|
1553.3.3
by Marien Zwart
Whitespace cleanup (pep 3) |
235 |
|
1553.3.4
by Marien Zwart
Move the encoding step into the test to make it more obvious we are comparing bytestrings. |
236 |
SAMPLE_UNICODE_TESTAMENT = u"""\ |
1553.3.1
by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this. |
237 |
bazaar-ng testament version 1
|
238 |
revision-id: test@user-3
|
|
239 |
committer: test@user
|
|
240 |
timestamp: 1129025493
|
|
241 |
timezone: 36000
|
|
242 |
parents:
|
|
243 |
test@user-2
|
|
244 |
message:
|
|
245 |
non-ascii commit \N{COPYRIGHT SIGN} me |
|
246 |
inventory:
|
|
247 |
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
|
|
248 |
directory src src-id
|
|
249 |
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
|
|
250 |
properties:
|
|
251 |
branch-nick:
|
|
252 |
test branch
|
|
1553.3.4
by Marien Zwart
Move the encoding step into the test to make it more obvious we are comparing bytestrings. |
253 |
"""
|