/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to tests/test_push.py

  • Committer: Curtis Hovey
  • Date: 2012-03-04 00:09:11 UTC
  • mto: This revision was merged to the branch mainline in revision 782.
  • Revision ID: sinzui.is@verizon.net-20120304000911-iaw196xcw4zfta9m
Added test to verify that DivergedBranches is handled.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2012 Curtis Hovey <sinzui.is@verizon.net>
 
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 ui functionality."""
 
18
 
 
19
from gi.repository import Gtk
 
20
 
 
21
from bzrlib import (
 
22
    errors,
 
23
    tests,
 
24
    ui,
 
25
    )
 
26
 
 
27
from bzrlib.plugins.gtk import (
 
28
    push,
 
29
    set_ui_factory,
 
30
    )
 
31
from bzrlib.plugins.gtk.tests import MockMethod
 
32
from bzrlib.plugins.gtk.history import UrlHistory
 
33
from bzrlib.plugins.gtk.ui import ProgressPanel
 
34
 
 
35
 
 
36
class PushTestCase(tests.TestCaseWithMemoryTransport):
 
37
 
 
38
    def make_push_branch(self):
 
39
        tree = self.make_branch_and_memory_tree('test')
 
40
        return tree.branch
 
41
 
 
42
    def test_init(self):
 
43
        set_ui_factory()
 
44
        branch = self.make_push_branch()
 
45
        dialog = push.PushDialog(
 
46
            repository=None, revid=None, branch=branch, parent=None)
 
47
        self.assertIs(None, dialog.props.parent)
 
48
        self.assertIs(None, dialog.repository)
 
49
        self.assertIs(None, dialog.revid)
 
50
        self.assertIs(branch, dialog.branch)
 
51
        self.assertIsInstance(dialog._label_location, Gtk.Label)
 
52
        self.assertEqual((0.0, 0.5), dialog._label_location.get_alignment())
 
53
        self.assertIsInstance(dialog._combo, Gtk.ComboBox)
 
54
        self.assertIsInstance(dialog._button_push, Gtk.Button)
 
55
        self.assertIsInstance(dialog._hbox_location, Gtk.Box)
 
56
        self.assertEqual(
 
57
            Gtk.Orientation.HORIZONTAL,
 
58
            dialog._hbox_location.props.orientation)
 
59
        self.assertEqual(3, dialog._hbox_location.props.spacing)
 
60
        self.assertEqual(3, dialog.get_content_area().props.spacing)
 
61
        self.assertIsInstance(dialog._progress_widget, ProgressPanel)
 
62
        self.assertIs(
 
63
            ui.ui_factory._progress_bar_widget, dialog._progress_widget)
 
64
        self.assertIsInstance(dialog._push_message, Gtk.Label)
 
65
        self.assertIs(True, dialog._combo.props.visible)
 
66
        self.assertIs(False, dialog._progress_widget.props.visible)
 
67
        self.assertIs(False, dialog._push_message.props.visible)
 
68
        self.assertIsInstance(dialog._history, UrlHistory)
 
69
 
 
70
    def test_build_history(self):
 
71
        set_ui_factory()
 
72
        branch = self.make_push_branch()
 
73
        branch.set_push_location('lp:~user/fnord/trunk')
 
74
        dialog = push.PushDialog(None, None, branch)
 
75
        dialog._history.add_entry('lp:~user/fnord/test1')
 
76
        dialog._history.add_entry('lp:~user/fnord/test2')
 
77
        dialog._build_history()
 
78
        self.assertEqual(
 
79
            'lp:~user/fnord/trunk', dialog._combo.get_child().props.text)
 
80
        self.assertIsInstance(dialog._combo_model, Gtk.ListStore)
 
81
        self.assertIs(dialog._combo.get_model(), dialog._combo_model)
 
82
        locations = [row[0] for row in dialog._combo_model]
 
83
        self.assertEqual(
 
84
            ['lp:~user/fnord/test1', 'lp:~user/fnord/test2'], locations)
 
85
 
 
86
    def test_on_close_clicked(self):
 
87
        # The ui_factory's progress bar widget is set to None.
 
88
        set_ui_factory()
 
89
        branch = self.make_push_branch()
 
90
        dialog = push.PushDialog(None, None, branch)
 
91
        dialog._on_close_clicked(None)
 
92
        self.assertIs(None, ui.ui_factory._progress_bar_widget)
 
93
 
 
94
    def test_on_push_clicked_without_errors(self):
 
95
        MockMethod.bind(self, push, 'do_push', "test success")
 
96
        set_ui_factory()
 
97
        branch = self.make_push_branch()
 
98
        dialog = push.PushDialog(None, None, branch)
 
99
        MockMethod.bind(self, dialog._progress_widget, 'tick')
 
100
        dialog._combo.get_child().props.text = 'lp:~user/fnord/test'
 
101
        dialog._on_push_clicked(None)
 
102
        self.assertIs(True, dialog._progress_widget.tick.called)
 
103
        self.assertIs(False, dialog._progress_widget.props.visible)
 
104
        self.assertIs(True, push.do_push.called)
 
105
        self.assertEqual(
 
106
            (branch, 'lp:~user/fnord/test'), push.do_push.args)
 
107
        self.assertEqual(
 
108
            {'overwrite': False}, push.do_push.kwargs)
 
109
        self.assertIs(True, dialog._push_message.props.visible)
 
110
        self.assertEqual('test success', dialog._push_message.props.label)
 
111
        self.assertEqual(
 
112
            'lp:~user/fnord/test', dialog._history.get_entries()[-1])
 
113
        self.assertEqual('lp:~user/fnord/test', branch.get_push_location())
 
114
 
 
115
    def test_on_push_clicked_with_divered_branches(self):
 
116
        error = errors.DivergedBranches(None, None)
 
117
        MockMethod.bind(self, push, 'do_push', raise_error=error)
 
118
        MockMethod.bind(self, push, 'question_dialog', Gtk.ResponseType.YES)
 
119
        set_ui_factory()
 
120
        branch = self.make_push_branch()
 
121
        dialog = push.PushDialog(None, None, branch)
 
122
        dialog._combo.get_child().props.text = 'lp:~user/fnord/test'
 
123
        dialog._on_push_clicked(None)
 
124
        self.assertIs(True, push.do_push.called)
 
125
        self.assertEqual(2, push.do_push.call_count)
 
126
        self.assertEqual(
 
127
            (branch, 'lp:~user/fnord/test'), push.do_push.args)
 
128
        self.assertEqual(
 
129
            {'overwrite': True}, push.do_push.kwargs)