/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
622.1.2 by John Arbash Meinel
Add tests of RevisionView that it can handle broken file-info properties.
1
# Copyright (C) 2007, 2008 John Arbash Meinel <john@arbash-meinel.com>
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 the RevisionView functionality."""
18
19
from bzrlib import (
20
    tests,
21
    )
645 by Jelmer Vernooij
Fix more bencode imports.
22
try:
646 by Jelmer Vernooij
Reorder bencode imports, prefer the new location to prevent deprecation warnings.
23
    from bzrlib import bencode
24
except ImportError:
645 by Jelmer Vernooij
Fix more bencode imports.
25
    from bzrlib.util import bencode
622.1.2 by John Arbash Meinel
Add tests of RevisionView that it can handle broken file-info properties.
26
27
from bzrlib.plugins.gtk import revisionview
28
29
30
class TestPendingRevisions(tests.TestCaseWithMemoryTransport):
31
32
    def assertBufferText(self, text, buffer):
33
        """Check the text stored in the buffer."""
34
        self.assertEqual(text, buffer.get_text(buffer.get_start_iter(),
734.1.7 by Curtis Hovey
Updated buffer.getText() calls and ModifierType enums.
35
                                               buffer.get_end_iter(),
36
                                               True))
622.1.2 by John Arbash Meinel
Add tests of RevisionView that it can handle broken file-info properties.
37
38
    def test_create_view(self):
39
        builder = self.make_branch_builder('test')
40
        builder.build_snapshot('A', None,
41
            [('add', ('', 'root-id', 'directory', None))])
42
        b = builder.get_branch()
43
44
        rv = revisionview.RevisionView(b)
45
        rev = b.repository.get_revision('A')
46
        rv.set_revision(rev)
47
        self.assertEqual(rev.committer, rv.committer.get_text())
48
        self.assertFalse(rv.author.get_property('visible'))
49
        self.assertFalse(rv.author_label.get_property('visible'))
50
        self.assertFalse(rv.file_info_box.get_property('visible'))
51
52
    def test_create_view_with_file_info(self):
53
        tree = self.make_branch_and_memory_tree('test')
54
        file_info = bencode.bencode([{'file_id':'root-id', 'path':'',
55
                                      'message':'test-message\n'}])
56
        tree.lock_write()
57
        try:
58
            tree.add([''], ['root-id'])
59
            tree.commit('test', rev_id='A', revprops={'file-info': file_info})
60
        finally:
61
            tree.unlock()
62
        b = tree.branch
63
64
        rv = revisionview.RevisionView(b)
65
        rev = b.repository.get_revision('A')
66
        rv.set_revision(rev)
67
68
        self.assertEqual(rev.committer, rv.committer.get_text())
69
        self.assertTrue(rv.file_info_box.get_property('visible'))
70
        self.assertBufferText('\ntest-message\n', rv.file_info_buffer)
71
72
    def test_create_view_with_broken_file_info(self):
73
        tree = self.make_branch_and_memory_tree('test')
74
        # This should be 'message13:'
75
        file_info = 'ld7:file_id7:root-id7:message11:test-message\n4:path0:ee'
76
        tree.lock_write()
77
        try:
78
            tree.add([''], ['root-id'])
79
            tree.commit('test', rev_id='A', revprops={'file-info': file_info})
80
        finally:
81
            tree.unlock()
82
        b = tree.branch
83
84
        rv = revisionview.RevisionView(b)
85
        rev = b.repository.get_revision('A')
86
        rv.set_revision(rev)
87
88
        self.assertEqual(rev.committer, rv.committer.get_text())
89
        self.assertFalse(rv.file_info_box.get_property('visible'))
734 by Jelmer Vernooij
Use TestCase.get_log rather than TestCase._get_log.
90
        log = self.get_log()
622.1.2 by John Arbash Meinel
Add tests of RevisionView that it can handle broken file-info properties.
91
        self.assertContainsRe(log, 'Invalid per-file info for revision:A')