/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
1551.7.1 by Aaron Bentley
Implement --strict at commandline, fix up strict format
27
from bzrlib.testament import Testament, StrictTestament
1185.16.15 by Martin Pool
- test text form for testaments
28
from bzrlib.trace import mutter
1551.7.5 by Aaron Bentley
Make sure strict testaments indicate when an execute bit is true
29
from bzrlib.transform import TreeTransform
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
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
33
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.
34
1185.16.15 by Martin Pool
- test text form for testaments
35
    def setUp(self):
36
        super(TestamentTests, self).setUp()
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
37
        self.wt = self.make_branch_and_tree('.')
38
        b = self.b = self.wt.branch
1185.35.16 by Aaron Bentley
Fixed tests
39
        b.nick = "test branch"
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
40
        self.wt.commit(message='initial null commit',
1185.16.12 by Martin Pool
- basic testament class
41
                 committer='test@user',
42
                 timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
43
                 timezone=0,
44
                 rev_id='test@user-1')
1514 by Robert Collins
Unbreak self.build_tree_shape in tests.
45
        self.build_tree_contents([('hello', 'contents of hello file'),
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
46
                             ('src/', ),
1185.16.22 by Martin Pool
- more testament development
47
                             ('src/foo.c', 'int main()\n{\n}\n')])
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
48
        self.wt.add(['hello', 'src', 'src/foo.c'],
1508.1.5 by Robert Collins
Move add from Branch to WorkingTree.
49
                             ['hello-id', 'src-id', 'foo.c-id'])
1551.7.5 by Aaron Bentley
Make sure strict testaments indicate when an execute bit is true
50
        tt = TreeTransform(self.wt)
51
        trans_id = tt.trans_id_tree_path('hello')
52
        tt.set_executability(True, trans_id)
53
        tt.apply()
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
54
        self.wt.commit(message='add files and directories',
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
55
                 timestamp=1129025483,
56
                 timezone=36000,
57
                 rev_id='test@user-2',
58
                 committer='test@user')
1185.16.15 by Martin Pool
- test text form for testaments
59
60
    def test_null_testament(self):
61
        """Testament for a revision with no contents."""
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
62
        t = Testament.from_revision(self.b.repository, 'test@user-1')
1185.16.12 by Martin Pool
- basic testament class
63
        ass = self.assertTrue
64
        eq = self.assertEqual
65
        ass(isinstance(t, Testament))
66
        eq(t.revision_id, 'test@user-1')
67
        eq(t.committer, 'test@user')
68
        eq(t.timestamp, 1129025423)
69
        eq(t.timezone, 0)
70
1185.16.15 by Martin Pool
- test text form for testaments
71
    def test_testment_text_form(self):
72
        """Conversion of testament to canonical text form."""
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
73
        t = Testament.from_revision(self.b.repository, 'test@user-1')
1185.16.22 by Martin Pool
- more testament development
74
        text_form = t.as_text()
1185.16.15 by Martin Pool
- test text form for testaments
75
        self.log('testament text form:\n' + text_form)
1185.16.25 by Martin Pool
- testament symlink support
76
        self.assertEqual(text_form, REV_1_TESTAMENT)
1185.16.15 by Martin Pool
- test text form for testaments
77
1551.7.1 by Aaron Bentley
Implement --strict at commandline, fix up strict format
78
    def test_strict_testment_text_form(self):
79
        """Conversion of testament to canonical text form."""
80
        t = StrictTestament.from_revision(self.b.repository, 'test@user-1')
81
        text_form = t.as_text()
82
        self.log('testament text form:\n' + text_form)
83
        self.assertEqualDiff(text_form, REV_1_STRICT_TESTAMENT)
84
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
85
    def test_testament_with_contents(self):
86
        """Testament containing a file and a directory."""
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
87
        t = Testament.from_revision(self.b.repository, 'test@user-2')
1185.16.22 by Martin Pool
- more testament development
88
        text_form = t.as_text()
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
89
        self.log('testament text form:\n' + text_form)
1185.16.24 by Martin Pool
- add and test 'testament' builtin command
90
        self.assertEqualDiff(text_form, REV_2_TESTAMENT)
91
        actual_short = t.as_short_text()
1185.16.25 by Martin Pool
- testament symlink support
92
        self.assertEqualDiff(actual_short, REV_2_SHORT)
1185.16.24 by Martin Pool
- add and test 'testament' builtin command
93
1551.7.1 by Aaron Bentley
Implement --strict at commandline, fix up strict format
94
    def test_strict_testament_with_contents(self):
95
        """Testament containing a file and a directory."""
96
        t = StrictTestament.from_revision(self.b.repository, 'test@user-2')
97
        text_form = t.as_text()
98
        self.log('testament text form:\n' + text_form)
99
        self.assertEqualDiff(text_form, REV_2_STRICT_TESTAMENT)
100
        actual_short = t.as_short_text()
101
        self.assertEqualDiff(actual_short, REV_2_SHORT_STRICT)
102
1185.16.24 by Martin Pool
- add and test 'testament' builtin command
103
    def test_testament_command(self):
104
        """Testament containing a file and a directory."""
105
        out, err = self.run_bzr_captured(['testament', '--long'])
106
        self.assertEqualDiff(err, '')
107
        self.assertEqualDiff(out, REV_2_TESTAMENT)
108
1185.16.25 by Martin Pool
- testament symlink support
109
    def test_testament_command_2(self):
110
        """Command getting short testament of previous version."""
111
        out, err = self.run_bzr_captured(['testament', '-r1'])
112
        self.assertEqualDiff(err, '')
113
        self.assertEqualDiff(out, REV_1_SHORT)
114
1551.7.1 by Aaron Bentley
Implement --strict at commandline, fix up strict format
115
    def test_testament_command_3(self):
116
        """Command getting short testament of previous version."""
117
        out, err = self.run_bzr_captured(['testament', '-r1', '--strict'])
118
        self.assertEqualDiff(err, '')
119
        self.assertEqualDiff(out, REV_1_SHORT_STRICT)
120
1185.16.25 by Martin Pool
- testament symlink support
121
    def test_testament_symlinks(self):
122
        """Testament containing symlink (where possible)"""
123
        if not has_symlinks():
124
            return
125
        os.symlink('wibble/linktarget', 'link')
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
126
        self.wt.add(['link'], ['link-id'])
127
        self.wt.commit(message='add symlink',
1185.16.25 by Martin Pool
- testament symlink support
128
                 timestamp=1129025493,
129
                 timezone=36000,
130
                 rev_id='test@user-3',
131
                 committer='test@user')
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
132
        t = Testament.from_revision(self.b.repository, 'test@user-3')
1185.16.25 by Martin Pool
- testament symlink support
133
        self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
134
1185.16.59 by mbp at sourcefrog
- store revprops in testaments
135
    def test_testament_revprops(self):
136
        """Testament to revision with extra properties"""
137
        props = dict(flavor='sour cherry\ncream cheese',
1886.1.5 by John Arbash Meinel
Assert that Testament can handle empty revprops as well
138
                     size='medium',
139
                     empty='',
140
                    )
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
141
        self.wt.commit(message='revision with properties',
1185.16.59 by mbp at sourcefrog
- store revprops in testaments
142
                      timestamp=1129025493,
143
                      timezone=36000,
144
                      rev_id='test@user-3',
145
                      committer='test@user',
146
                      revprops=props)
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
147
        t = Testament.from_revision(self.b.repository, 'test@user-3')
1185.16.59 by mbp at sourcefrog
- store revprops in testaments
148
        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.
149
1553.3.1 by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this.
150
    def test_testament_unicode_commit_message(self):
1558.1.3 by Aaron Bentley
Fixed deprecated op use in test suite
151
        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.
152
            message=u'non-ascii commit \N{COPYRIGHT SIGN} me',
153
            timestamp=1129025493,
154
            timezone=36000,
155
            rev_id='test@user-3',
156
            committer='test@user')
157
        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.
158
        self.assertEqualDiff(
1185.50.79 by John Arbash Meinel
small cleanup of test
159
            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.
160
1442.1.62 by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions.
161
    def test___init__(self):
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
162
        revision = self.b.repository.get_revision('test@user-2')
163
        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.
164
        testament_1 = Testament(revision, inventory).as_short_text()
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
165
        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.
166
                                              'test@user-2').as_short_text()
167
        self.assertEqual(testament_1, testament_2)
1185.16.59 by mbp at sourcefrog
- store revprops in testaments
168
                    
1185.16.25 by Martin Pool
- testament symlink support
169
170
REV_1_TESTAMENT = """\
171
bazaar-ng testament version 1
172
revision-id: test@user-1
173
committer: test@user
174
timestamp: 1129025423
175
timezone: 0
176
parents:
177
message:
178
  initial null commit
179
inventory:
1185.35.16 by Aaron Bentley
Fixed tests
180
properties:
181
  branch-nick:
182
    test branch
1185.16.25 by Martin Pool
- testament symlink support
183
"""
184
1551.7.1 by Aaron Bentley
Implement --strict at commandline, fix up strict format
185
REV_1_STRICT_TESTAMENT = """\
186
bazaar-ng testament version 2.1
187
revision-id: test@user-1
188
committer: test@user
189
timestamp: 1129025423
190
timezone: 0
191
parents:
192
message:
193
  initial null commit
194
inventory:
195
properties:
196
  branch-nick:
197
    test branch
198
"""
199
200
1185.16.25 by Martin Pool
- testament symlink support
201
REV_1_SHORT = """\
202
bazaar-ng testament short form 1
203
revision-id: test@user-1
204
sha1: %s
205
""" % sha(REV_1_TESTAMENT).hexdigest()
206
1185.16.24 by Martin Pool
- add and test 'testament' builtin command
207
1551.7.1 by Aaron Bentley
Implement --strict at commandline, fix up strict format
208
REV_1_SHORT_STRICT = """\
209
bazaar-ng testament short form 2.1
210
revision-id: test@user-1
211
sha1: %s
212
""" % sha(REV_1_STRICT_TESTAMENT).hexdigest()
213
214
1185.16.24 by Martin Pool
- add and test 'testament' builtin command
215
REV_2_TESTAMENT = """\
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
216
bazaar-ng testament version 1
217
revision-id: test@user-2
218
committer: test@user
1185.16.22 by Martin Pool
- more testament development
219
timestamp: 1129025483
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
220
timezone: 36000
221
parents:
222
  test@user-1
223
message:
224
  add files and directories
225
inventory:
1185.16.22 by Martin Pool
- more testament development
226
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
227
  directory src src-id
228
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
1185.35.16 by Aaron Bentley
Fixed tests
229
properties:
230
  branch-nick:
231
    test branch
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
232
"""
1185.16.25 by Martin Pool
- testament symlink support
233
234
1551.7.1 by Aaron Bentley
Implement --strict at commandline, fix up strict format
235
REV_2_STRICT_TESTAMENT = """\
236
bazaar-ng testament version 2.1
237
revision-id: test@user-2
238
committer: test@user
239
timestamp: 1129025483
240
timezone: 36000
241
parents:
242
  test@user-1
243
message:
244
  add files and directories
245
inventory:
1551.7.5 by Aaron Bentley
Make sure strict testaments indicate when an execute bit is true
246
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
1551.7.1 by Aaron Bentley
Implement --strict at commandline, fix up strict format
247
  directory src src-id test@user-2 no
248
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
249
properties:
250
  branch-nick:
251
    test branch
252
"""
253
254
1185.16.25 by Martin Pool
- testament symlink support
255
REV_2_SHORT = """\
256
bazaar-ng testament short form 1
257
revision-id: test@user-2
258
sha1: %s
259
""" % sha(REV_2_TESTAMENT).hexdigest()
260
261
1551.7.1 by Aaron Bentley
Implement --strict at commandline, fix up strict format
262
REV_2_SHORT_STRICT = """\
263
bazaar-ng testament short form 2.1
264
revision-id: test@user-2
265
sha1: %s
266
""" % sha(REV_2_STRICT_TESTAMENT).hexdigest()
267
268
1185.16.59 by mbp at sourcefrog
- store revprops in testaments
269
REV_PROPS_TESTAMENT = """\
270
bazaar-ng testament version 1
271
revision-id: test@user-3
272
committer: test@user
273
timestamp: 1129025493
274
timezone: 36000
275
parents:
276
  test@user-2
277
message:
278
  revision with properties
279
inventory:
280
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
281
  directory src src-id
282
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
283
properties:
1185.35.16 by Aaron Bentley
Fixed tests
284
  branch-nick:
285
    test branch
1886.1.5 by John Arbash Meinel
Assert that Testament can handle empty revprops as well
286
  empty:
1185.16.59 by mbp at sourcefrog
- store revprops in testaments
287
  flavor:
288
    sour cherry
289
    cream cheese
290
  size:
291
    medium
292
"""
293
294
1185.16.25 by Martin Pool
- testament symlink support
295
REV_3_TESTAMENT = """\
296
bazaar-ng testament version 1
297
revision-id: test@user-3
298
committer: test@user
299
timestamp: 1129025493
300
timezone: 36000
301
parents:
302
  test@user-2
303
message:
304
  add symlink
305
inventory:
306
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
307
  symlink link link-id wibble/linktarget
308
  directory src src-id
309
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
1185.35.16 by Aaron Bentley
Fixed tests
310
properties:
311
  branch-nick:
312
    test branch
1185.16.25 by Martin Pool
- testament symlink support
313
"""
1553.3.1 by Marien Zwart
Make Testament.as_text_lines return utf-8 instead of unicode objects and add a test for this.
314
1553.3.3 by Marien Zwart
Whitespace cleanup (pep 3)
315
1553.3.4 by Marien Zwart
Move the encoding step into the test to make it more obvious we are comparing bytestrings.
316
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.
317
bazaar-ng testament version 1
318
revision-id: test@user-3
319
committer: test@user
320
timestamp: 1129025493
321
timezone: 36000
322
parents:
323
  test@user-2
324
message:
325
  non-ascii commit \N{COPYRIGHT SIGN} me
326
inventory:
327
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
328
  directory src src-id
329
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
330
properties:
331
  branch-nick:
332
    test branch
1553.3.4 by Marien Zwart
Move the encoding step into the test to make it more obvious we are comparing bytestrings.
333
"""