/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
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
32
class TestamentTests(TestCaseInTempDir):
1185.16.15 by Martin Pool
- test text form for testaments
33
    def setUp(self):
34
        super(TestamentTests, self).setUp()
35
        b = self.b = Branch.initialize('.')
1185.16.12 by Martin Pool
- basic testament class
36
        b.commit(message='initial null commit',
37
                 committer='test@user',
38
                 timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
39
                 timezone=0,
40
                 rev_id='test@user-1')
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
41
        build_tree_contents([('hello', 'contents of hello file'),
42
                             ('src/', ),
1185.16.22 by Martin Pool
- more testament development
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'])
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
46
        b.commit(message='add files and directories',
47
                 timestamp=1129025483,
48
                 timezone=36000,
49
                 rev_id='test@user-2',
50
                 committer='test@user')
1185.16.15 by Martin Pool
- test text form for testaments
51
52
    def test_null_testament(self):
53
        """Testament for a revision with no contents."""
54
        t = Testament.from_revision(self.b, 'test@user-1')
1185.16.12 by Martin Pool
- basic testament class
55
        ass = self.assertTrue
56
        eq = self.assertEqual
57
        ass(isinstance(t, Testament))
58
        eq(t.revision_id, 'test@user-1')
59
        eq(t.committer, 'test@user')
60
        eq(t.timestamp, 1129025423)
61
        eq(t.timezone, 0)
62
1185.16.15 by Martin Pool
- test text form for testaments
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')
1185.16.22 by Martin Pool
- more testament development
66
        text_form = t.as_text()
1185.16.15 by Martin Pool
- test text form for testaments
67
        self.log('testament text form:\n' + text_form)
1185.16.25 by Martin Pool
- testament symlink support
68
        self.assertEqual(text_form, REV_1_TESTAMENT)
1185.16.15 by Martin Pool
- test text form for testaments
69
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
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')
1185.16.22 by Martin Pool
- more testament development
73
        text_form = t.as_text()
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
74
        self.log('testament text form:\n' + text_form)
1185.16.24 by Martin Pool
- add and test 'testament' builtin command
75
        self.assertEqualDiff(text_form, REV_2_TESTAMENT)
76
        actual_short = t.as_short_text()
1185.16.25 by Martin Pool
- testament symlink support
77
        self.assertEqualDiff(actual_short, REV_2_SHORT)
1185.16.24 by Martin Pool
- add and test 'testament' builtin command
78
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)
84
1185.16.25 by Martin Pool
- testament symlink support
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)
90
91
    def test_testament_symlinks(self):
92
        """Testament containing symlink (where possible)"""
93
        if not has_symlinks():
94
            return
95
        os.symlink('wibble/linktarget', 'link')
96
        self.b.add(['link'], ['link-id'])
97
        self.b.commit(message='add symlink',
98
                 timestamp=1129025493,
99
                 timezone=36000,
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)
104
1185.16.59 by mbp at sourcefrog
- store revprops in testaments
105
    def test_testament_revprops(self):
106
        """Testament to revision with extra properties"""
107
        props = dict(flavor='sour cherry\ncream cheese',
108
                     size='medium')
109
        self.b.commit(message='revision with properties',
110
                      timestamp=1129025493,
111
                      timezone=36000,
112
                      rev_id='test@user-3',
113
                      committer='test@user',
114
                      revprops=props)
115
        t = Testament.from_revision(self.b, 'test@user-3')
116
        self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
117
                    
1185.16.25 by Martin Pool
- testament symlink support
118
119
REV_1_TESTAMENT = """\
120
bazaar-ng testament version 1
121
revision-id: test@user-1
122
committer: test@user
123
timestamp: 1129025423
124
timezone: 0
125
parents:
126
message:
127
  initial null commit
128
inventory:
129
"""
130
131
REV_1_SHORT = """\
132
bazaar-ng testament short form 1
133
revision-id: test@user-1
134
sha1: %s
135
""" % sha(REV_1_TESTAMENT).hexdigest()
136
1185.16.24 by Martin Pool
- add and test 'testament' builtin command
137
138
REV_2_TESTAMENT = """\
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
139
bazaar-ng testament version 1
140
revision-id: test@user-2
141
committer: test@user
1185.16.22 by Martin Pool
- more testament development
142
timestamp: 1129025483
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
143
timezone: 36000
144
parents:
145
  test@user-1
146
message:
147
  add files and directories
148
inventory:
1185.16.22 by Martin Pool
- more testament development
149
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
150
  directory src src-id
151
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
152
"""
1185.16.25 by Martin Pool
- testament symlink support
153
154
155
REV_2_SHORT = """\
156
bazaar-ng testament short form 1
157
revision-id: test@user-2
158
sha1: %s
159
""" % sha(REV_2_TESTAMENT).hexdigest()
160
161
1185.16.59 by mbp at sourcefrog
- store revprops in testaments
162
REV_PROPS_TESTAMENT = """\
163
bazaar-ng testament version 1
164
revision-id: test@user-3
165
committer: test@user
166
timestamp: 1129025493
167
timezone: 36000
168
parents:
169
  test@user-2
170
message:
171
  revision with properties
172
inventory:
173
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
174
  directory src src-id
175
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
176
properties:
177
  flavor:
178
    sour cherry
179
    cream cheese
180
  size:
181
    medium
182
"""
183
184
1185.16.25 by Martin Pool
- testament symlink support
185
REV_3_TESTAMENT = """\
186
bazaar-ng testament version 1
187
revision-id: test@user-3
188
committer: test@user
189
timestamp: 1129025493
190
timezone: 36000
191
parents:
192
  test@user-2
193
message:
194
  add symlink
195
inventory:
196
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
197
  symlink link link-id wibble/linktarget
198
  directory src src-id
199
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
200
"""