~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.23 by Martin Pool
- clean up imports
19
# TODO: Testaments with symlinks, x-bits
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.12 by Martin Pool
- basic testament class
30
31
class TestamentTests(TestCaseInTempDir):
1185.16.15 by Martin Pool
- test text form for testaments
32
    def setUp(self):
33
        super(TestamentTests, self).setUp()
34
        b = self.b = Branch.initialize('.')
1185.16.12 by Martin Pool
- basic testament class
35
        b.commit(message='initial null commit',
36
                 committer='test@user',
37
                 timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
38
                 timezone=0,
39
                 rev_id='test@user-1')
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
40
        build_tree_contents([('hello', 'contents of hello file'),
41
                             ('src/', ),
1185.16.22 by Martin Pool
- more testament development
42
                             ('src/foo.c', 'int main()\n{\n}\n')])
43
        b.add(['hello', 'src', 'src/foo.c'],
44
              ['hello-id', 'src-id', 'foo.c-id'])
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
45
        b.commit(message='add files and directories',
46
                 timestamp=1129025483,
47
                 timezone=36000,
48
                 rev_id='test@user-2',
49
                 committer='test@user')
1185.16.15 by Martin Pool
- test text form for testaments
50
51
    def test_null_testament(self):
52
        """Testament for a revision with no contents."""
53
        t = Testament.from_revision(self.b, 'test@user-1')
1185.16.12 by Martin Pool
- basic testament class
54
        ass = self.assertTrue
55
        eq = self.assertEqual
56
        ass(isinstance(t, Testament))
57
        eq(t.revision_id, 'test@user-1')
58
        eq(t.committer, 'test@user')
59
        eq(t.timestamp, 1129025423)
60
        eq(t.timezone, 0)
61
1185.16.15 by Martin Pool
- test text form for testaments
62
    def test_testment_text_form(self):
63
        """Conversion of testament to canonical text form."""
64
        t = Testament.from_revision(self.b, 'test@user-1')
1185.16.22 by Martin Pool
- more testament development
65
        text_form = t.as_text()
1185.16.15 by Martin Pool
- test text form for testaments
66
        self.log('testament text form:\n' + text_form)
67
        expect = """\
68
bazaar-ng testament version 1
69
revision-id: test@user-1
70
committer: test@user
1185.16.22 by Martin Pool
- more testament development
71
timestamp: 1129025423
1185.16.15 by Martin Pool
- test text form for testaments
72
timezone: 0
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
73
parents:
1185.16.15 by Martin Pool
- test text form for testaments
74
message:
75
  initial null commit
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
76
inventory:
1185.16.15 by Martin Pool
- test text form for testaments
77
"""
78
        self.assertEqual(text_form, expect)
79
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
80
    def test_testament_with_contents(self):
81
        """Testament containing a file and a directory."""
82
        t = Testament.from_revision(self.b, 'test@user-2')
1185.16.22 by Martin Pool
- more testament development
83
        text_form = t.as_text()
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
84
        self.log('testament text form:\n' + text_form)
1185.16.24 by Martin Pool
- add and test 'testament' builtin command
85
        self.assertEqualDiff(text_form, REV_2_TESTAMENT)
86
        actual_short = t.as_short_text()
87
        self.assertEqualDiff(actual_short, """\
88
bazaar-ng testament short form 1
89
revision test@user-2
90
sha1 %s
91
""" % sha(REV_2_TESTAMENT).hexdigest())
92
93
    def test_testament_command(self):
94
        """Testament containing a file and a directory."""
95
        out, err = self.run_bzr_captured(['testament', '--long'])
96
        self.assertEqualDiff(err, '')
97
        self.assertEqualDiff(out, REV_2_TESTAMENT)
98
99
100
REV_2_TESTAMENT = """\
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
101
bazaar-ng testament version 1
102
revision-id: test@user-2
103
committer: test@user
1185.16.22 by Martin Pool
- more testament development
104
timestamp: 1129025483
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
105
timezone: 36000
106
parents:
107
  test@user-1
108
message:
109
  add files and directories
110
inventory:
1185.16.22 by Martin Pool
- more testament development
111
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
112
  directory src src-id
113
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
1185.16.19 by Martin Pool
- testament now contains summary of parents and inventory
114
"""