~bzr-pqm/bzr/bzr.dev

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