~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testtestament.py

  • Committer: John Arbash Meinel
  • Date: 2005-11-19 04:22:51 UTC
  • mto: (1185.82.108 w-changeset)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: john@arbash-meinel.com-20051119042251-aaa8514b7d68c29f
Working on creating a factor for serializing changesets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
19
# TODO: Testaments with x-bits
 
20
 
 
21
import os
 
22
from sha import sha
 
23
import sys
 
24
 
 
25
from bzrlib.selftest import TestCaseInTempDir
 
26
from bzrlib.selftest.treeshape import build_tree_contents
 
27
from bzrlib.branch import Branch
 
28
from bzrlib.testament import Testament
 
29
from bzrlib.trace import mutter
 
30
from bzrlib.osutils import has_symlinks
 
31
 
 
32
 
 
33
class TestamentTests(TestCaseInTempDir):
 
34
 
 
35
    def setUp(self):
 
36
        super(TestamentTests, self).setUp()
 
37
        b = self.b = Branch.initialize('.')
 
38
        b.nick = "test branch"
 
39
        b.working_tree().commit(message='initial null commit',
 
40
                 committer='test@user',
 
41
                 timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
 
42
                 timezone=0,
 
43
                 rev_id='test@user-1')
 
44
        build_tree_contents([('hello', 'contents of hello file'),
 
45
                             ('src/', ),
 
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'])
 
49
        b.working_tree().commit(message='add files and directories',
 
50
                 timestamp=1129025483,
 
51
                 timezone=36000,
 
52
                 rev_id='test@user-2',
 
53
                 committer='test@user')
 
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')
 
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
 
 
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')
 
69
        text_form = t.as_text()
 
70
        self.log('testament text form:\n' + text_form)
 
71
        self.assertEqual(text_form, REV_1_TESTAMENT)
 
72
 
 
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')
 
76
        text_form = t.as_text()
 
77
        self.log('testament text form:\n' + text_form)
 
78
        self.assertEqualDiff(text_form, REV_2_TESTAMENT)
 
79
        actual_short = t.as_short_text()
 
80
        self.assertEqualDiff(actual_short, REV_2_SHORT)
 
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
 
 
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'])
 
100
        self.b.working_tree().commit(message='add symlink',
 
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
 
 
108
    def test_testament_revprops(self):
 
109
        """Testament to revision with extra properties"""
 
110
        props = dict(flavor='sour cherry\ncream cheese',
 
111
                     size='medium')
 
112
        self.b.working_tree().commit(message='revision with properties',
 
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)
 
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)
 
128
                    
 
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:
 
140
properties:
 
141
  branch-nick:
 
142
    test branch
 
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
 
 
151
 
 
152
REV_2_TESTAMENT = """\
 
153
bazaar-ng testament version 1
 
154
revision-id: test@user-2
 
155
committer: test@user
 
156
timestamp: 1129025483
 
157
timezone: 36000
 
158
parents:
 
159
  test@user-1
 
160
message:
 
161
  add files and directories
 
162
inventory:
 
163
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
 
164
  directory src src-id
 
165
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
 
166
properties:
 
167
  branch-nick:
 
168
    test branch
 
169
"""
 
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
 
 
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:
 
194
  branch-nick:
 
195
    test branch
 
196
  flavor:
 
197
    sour cherry
 
198
    cream cheese
 
199
  size:
 
200
    medium
 
201
"""
 
202
 
 
203
 
 
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
 
219
properties:
 
220
  branch-nick:
 
221
    test branch
 
222
"""