~ubuntu-branches/ubuntu/hardy/bzr/hardy-updates

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testtestament.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeff Bailey
  • Date: 2005-11-07 13:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20051107131753-qsy145z1rfug5i27
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

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.commit(message='initial null commit',
 
39
                 committer='test@user',
 
40
                 timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
 
41
                 timezone=0,
 
42
                 rev_id='test@user-1')
 
43
        build_tree_contents([('hello', 'contents of hello file'),
 
44
                             ('src/', ),
 
45
                             ('src/foo.c', 'int main()\n{\n}\n')])
 
46
        b.add(['hello', 'src', 'src/foo.c'],
 
47
              ['hello-id', 'src-id', 'foo.c-id'])
 
48
        b.commit(message='add files and directories',
 
49
                 timestamp=1129025483,
 
50
                 timezone=36000,
 
51
                 rev_id='test@user-2',
 
52
                 committer='test@user')
 
53
 
 
54
    def test_null_testament(self):
 
55
        """Testament for a revision with no contents."""
 
56
        t = Testament.from_revision(self.b, 'test@user-1')
 
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
 
 
65
    def test_testment_text_form(self):
 
66
        """Conversion of testament to canonical text form."""
 
67
        t = Testament.from_revision(self.b, 'test@user-1')
 
68
        text_form = t.as_text()
 
69
        self.log('testament text form:\n' + text_form)
 
70
        self.assertEqual(text_form, REV_1_TESTAMENT)
 
71
 
 
72
    def test_testament_with_contents(self):
 
73
        """Testament containing a file and a directory."""
 
74
        t = Testament.from_revision(self.b, 'test@user-2')
 
75
        text_form = t.as_text()
 
76
        self.log('testament text form:\n' + text_form)
 
77
        self.assertEqualDiff(text_form, REV_2_TESTAMENT)
 
78
        actual_short = t.as_short_text()
 
79
        self.assertEqualDiff(actual_short, REV_2_SHORT)
 
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
 
 
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')
 
98
        self.b.add(['link'], ['link-id'])
 
99
        self.b.commit(message='add symlink',
 
100
                 timestamp=1129025493,
 
101
                 timezone=36000,
 
102
                 rev_id='test@user-3',
 
103
                 committer='test@user')
 
104
        t = Testament.from_revision(self.b, 'test@user-3')
 
105
        self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
 
106
 
 
107
    def test_testament_revprops(self):
 
108
        """Testament to revision with extra properties"""
 
109
        props = dict(flavor='sour cherry\ncream cheese',
 
110
                     size='medium')
 
111
        self.b.commit(message='revision with properties',
 
112
                      timestamp=1129025493,
 
113
                      timezone=36000,
 
114
                      rev_id='test@user-3',
 
115
                      committer='test@user',
 
116
                      revprops=props)
 
117
        t = Testament.from_revision(self.b, 'test@user-3')
 
118
        self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
 
119
 
 
120
    def test___init__(self):
 
121
        revision = self.b.get_revision('test@user-2')
 
122
        inventory = self.b.get_inventory('test@user-2')
 
123
        testament_1 = Testament(revision, inventory).as_short_text()
 
124
        testament_2 = Testament.from_revision(self.b, 
 
125
                                              'test@user-2').as_short_text()
 
126
        self.assertEqual(testament_1, testament_2)
 
127
                    
 
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:
 
139
"""
 
140
 
 
141
REV_1_SHORT = """\
 
142
bazaar-ng testament short form 1
 
143
revision-id: test@user-1
 
144
sha1: %s
 
145
""" % sha(REV_1_TESTAMENT).hexdigest()
 
146
 
 
147
 
 
148
REV_2_TESTAMENT = """\
 
149
bazaar-ng testament version 1
 
150
revision-id: test@user-2
 
151
committer: test@user
 
152
timestamp: 1129025483
 
153
timezone: 36000
 
154
parents:
 
155
  test@user-1
 
156
message:
 
157
  add files and directories
 
158
inventory:
 
159
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
 
160
  directory src src-id
 
161
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
 
162
"""
 
163
 
 
164
 
 
165
REV_2_SHORT = """\
 
166
bazaar-ng testament short form 1
 
167
revision-id: test@user-2
 
168
sha1: %s
 
169
""" % sha(REV_2_TESTAMENT).hexdigest()
 
170
 
 
171
 
 
172
REV_PROPS_TESTAMENT = """\
 
173
bazaar-ng testament version 1
 
174
revision-id: test@user-3
 
175
committer: test@user
 
176
timestamp: 1129025493
 
177
timezone: 36000
 
178
parents:
 
179
  test@user-2
 
180
message:
 
181
  revision with properties
 
182
inventory:
 
183
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
 
184
  directory src src-id
 
185
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
 
186
properties:
 
187
  flavor:
 
188
    sour cherry
 
189
    cream cheese
 
190
  size:
 
191
    medium
 
192
"""
 
193
 
 
194
 
 
195
REV_3_TESTAMENT = """\
 
196
bazaar-ng testament version 1
 
197
revision-id: test@user-3
 
198
committer: test@user
 
199
timestamp: 1129025493
 
200
timezone: 36000
 
201
parents:
 
202
  test@user-2
 
203
message:
 
204
  add symlink
 
205
inventory:
 
206
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
 
207
  symlink link link-id wibble/linktarget
 
208
  directory src src-id
 
209
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
 
210
"""