1
# Copyright (C) 2012 Curtis Hovey <sinzui.is@verizon.net>
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.
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.
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
17
"""Test the ui functionality."""
19
from gi.repository import Gtk
27
from bzrlib.plugins.gtk import (
31
from bzrlib.plugins.gtk.tests import MockMethod
32
from bzrlib.plugins.gtk.history import UrlHistory
33
from bzrlib.plugins.gtk.ui import ProgressPanel
36
class PushTestCase(tests.TestCaseWithMemoryTransport):
38
def make_push_branch(self):
39
tree = self.make_branch_and_memory_tree('test')
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
# Layout rules to match HIG.
52
self.assertIsInstance(dialog._label_location, Gtk.Label)
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.assertIsInstance(dialog._progress_widget, ProgressPanel)
57
self.assertIsInstance(dialog._push_message, Gtk.Label)
58
self.assertIsInstance(dialog._history, UrlHistory)
60
ui.ui_factory._progress_bar_widget, dialog._progress_widget)
62
Gtk.Orientation.HORIZONTAL,
63
dialog._hbox_location.props.orientation)
64
self.assertEqual(0.0, dialog._push_message.props.xalign)
65
self.assertEqual(6, dialog.props.border_width)
66
self.assertEqual(6, dialog._hbox_location.props.spacing)
67
self.assertEqual(6, dialog.get_content_area().props.spacing)
69
self.assertIs(True, dialog._combo.props.visible)
70
self.assertIs(False, dialog._progress_widget.props.visible)
71
self.assertIs(False, dialog._push_message.props.visible)
73
def test_build_history(self):
75
branch = self.make_push_branch()
76
branch.set_push_location('lp:~user/fnord/trunk')
77
dialog = push.PushDialog(None, None, branch)
78
dialog._history.add_entry('lp:~user/fnord/test1')
79
dialog._history.add_entry('lp:~user/fnord/test2')
80
dialog._build_history()
82
'lp:~user/fnord/trunk', dialog._combo.get_child().props.text)
83
self.assertIsInstance(dialog._combo_model, Gtk.ListStore)
84
self.assertIs(dialog._combo.get_model(), dialog._combo_model)
85
locations = [row[0] for row in dialog._combo_model]
87
['lp:~user/fnord/test1', 'lp:~user/fnord/test2'], locations)
89
def test_on_close_clicked(self):
90
# The ui_factory's progress bar widget is set to None.
92
branch = self.make_push_branch()
93
dialog = push.PushDialog(None, None, branch)
94
dialog._on_close_clicked(None)
95
self.assertIs(None, ui.ui_factory._progress_bar_widget)
97
def test_on_push_clicked_without_errors(self):
98
# Verify the dialog's and branch's final states after a push.
99
MockMethod.bind(self, push, 'do_push', "test success")
101
branch = self.make_push_branch()
102
dialog = push.PushDialog(None, None, branch)
103
MockMethod.bind(self, dialog._progress_widget, 'tick')
104
dialog._combo.get_child().props.text = 'lp:~user/fnord/test'
105
dialog._on_push_clicked(None)
106
self.assertIs(True, dialog._progress_widget.tick.called)
107
self.assertIs(False, dialog._progress_widget.props.visible)
108
self.assertIs(True, push.do_push.called)
110
(branch, 'lp:~user/fnord/test'), push.do_push.args)
112
{'overwrite': False}, push.do_push.kwargs)
113
self.assertIs(True, dialog._push_message.props.visible)
114
self.assertEqual('test success', dialog._push_message.props.label)
116
'lp:~user/fnord/test', dialog._history.get_entries()[-1])
117
self.assertEqual('lp:~user/fnord/test', branch.get_push_location())
119
def test_on_push_clicked_with_divered_branches(self):
120
# Verify that when DivergedBranches is raise, the user can choose
121
# to overwrite the branch.
122
error = errors.DivergedBranches(None, None)
123
MockMethod.bind(self, push, 'do_push', raise_error=error)
124
MockMethod.bind(self, push, 'question_dialog', Gtk.ResponseType.YES)
126
branch = self.make_push_branch()
127
dialog = push.PushDialog(None, None, branch)
128
dialog._combo.get_child().props.text = 'lp:~user/fnord/test'
129
dialog._on_push_clicked(None)
130
self.assertIs(True, push.do_push.called)
131
self.assertEqual(2, push.do_push.call_count)
133
(branch, 'lp:~user/fnord/test'), push.do_push.args)
135
{'overwrite': True}, push.do_push.kwargs)