bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
776.3.3
by Curtis Hovey
Save point before mergining tip. |
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 ( |
|
776.3.11
by Curtis Hovey
Added test to verify that DivergedBranches is handled. |
22 |
errors, |
776.3.3
by Curtis Hovey
Save point before mergining tip. |
23 |
tests, |
776.3.6
by Curtis Hovey
Added tests for push __init__. |
24 |
ui, |
776.3.3
by Curtis Hovey
Save point before mergining tip. |
25 |
)
|
26 |
||
776.3.9
by Curtis Hovey
Added a simple test for _on_push_clicked. |
27 |
from bzrlib.plugins.gtk import ( |
28 |
push, |
|
29 |
set_ui_factory, |
|
776.3.3
by Curtis Hovey
Save point before mergining tip. |
30 |
)
|
776.3.9
by Curtis Hovey
Added a simple test for _on_push_clicked. |
31 |
from bzrlib.plugins.gtk.tests import MockMethod |
776.3.7
by Curtis Hovey
Added test for _build_history. |
32 |
from bzrlib.plugins.gtk.history import UrlHistory |
776.3.6
by Curtis Hovey
Added tests for push __init__. |
33 |
from bzrlib.plugins.gtk.ui import ProgressPanel |
776.3.3
by Curtis Hovey
Save point before mergining tip. |
34 |
|
35 |
||
776.3.5
by Curtis Hovey
Replace deprecated hbox with box. |
36 |
class PushTestCase(tests.TestCaseWithMemoryTransport): |
37 |
||
776.3.7
by Curtis Hovey
Added test for _build_history. |
38 |
def make_push_branch(self): |
39 |
tree = self.make_branch_and_memory_tree('test') |
|
40 |
return tree.branch |
|
41 |
||
776.3.5
by Curtis Hovey
Replace deprecated hbox with box. |
42 |
def test_init(self): |
43 |
set_ui_factory() |
|
776.3.7
by Curtis Hovey
Added test for _build_history. |
44 |
branch = self.make_push_branch() |
776.3.9
by Curtis Hovey
Added a simple test for _on_push_clicked. |
45 |
dialog = push.PushDialog( |
776.3.5
by Curtis Hovey
Replace deprecated hbox with box. |
46 |
repository=None, revid=None, branch=branch, parent=None) |
47 |
self.assertIs(None, dialog.props.parent) |
|
787
by Curtis Hovey
Update tests to reflect the changes to setup the the dialog for nautilus. |
48 |
self.assertIs(branch.repository, dialog.repository) |
49 |
self.assertIs(branch.last_revision(), dialog.revid) |
|
776.3.5
by Curtis Hovey
Replace deprecated hbox with box. |
50 |
self.assertIs(branch, dialog.branch) |
776.3.15
by Curtis Hovey
Follow GNOME HIG. |
51 |
# Layout rules to match HIG.
|
776.3.5
by Curtis Hovey
Replace deprecated hbox with box. |
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) |
|
776.3.6
by Curtis Hovey
Added tests for push __init__. |
56 |
self.assertIsInstance(dialog._progress_widget, ProgressPanel) |
776.3.15
by Curtis Hovey
Follow GNOME HIG. |
57 |
self.assertIsInstance(dialog._push_message, Gtk.Label) |
58 |
self.assertIsInstance(dialog._history, UrlHistory) |
|
776.3.6
by Curtis Hovey
Added tests for push __init__. |
59 |
self.assertIs( |
60 |
ui.ui_factory._progress_bar_widget, dialog._progress_widget) |
|
776.3.15
by Curtis Hovey
Follow GNOME HIG. |
61 |
self.assertEqual( |
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) |
|
68 |
# Show rules.
|
|
776.3.6
by Curtis Hovey
Added tests for push __init__. |
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) |
|
776.3.7
by Curtis Hovey
Added test for _build_history. |
72 |
|
73 |
def test_build_history(self): |
|
74 |
set_ui_factory() |
|
75 |
branch = self.make_push_branch() |
|
776.3.9
by Curtis Hovey
Added a simple test for _on_push_clicked. |
76 |
branch.set_push_location('lp:~user/fnord/trunk') |
77 |
dialog = push.PushDialog(None, None, branch) |
|
776.3.7
by Curtis Hovey
Added test for _build_history. |
78 |
dialog._history.add_entry('lp:~user/fnord/test1') |
79 |
dialog._history.add_entry('lp:~user/fnord/test2') |
|
80 |
dialog._build_history() |
|
81 |
self.assertEqual( |
|
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] |
|
86 |
self.assertEqual( |
|
87 |
['lp:~user/fnord/test1', 'lp:~user/fnord/test2'], locations) |
|
776.3.8
by Curtis Hovey
Added tests for _on_close_clicked. |
88 |
|
89 |
def test_on_close_clicked(self): |
|
90 |
# The ui_factory's progress bar widget is set to None.
|
|
91 |
set_ui_factory() |
|
92 |
branch = self.make_push_branch() |
|
776.3.9
by Curtis Hovey
Added a simple test for _on_push_clicked. |
93 |
dialog = push.PushDialog(None, None, branch) |
776.3.8
by Curtis Hovey
Added tests for _on_close_clicked. |
94 |
dialog._on_close_clicked(None) |
95 |
self.assertIs(None, ui.ui_factory._progress_bar_widget) |
|
776.3.9
by Curtis Hovey
Added a simple test for _on_push_clicked. |
96 |
|
97 |
def test_on_push_clicked_without_errors(self): |
|
776.3.16
by Curtis Hovey
Added comments. |
98 |
# Verify the dialog's and branch's final states after a push.
|
776.3.9
by Curtis Hovey
Added a simple test for _on_push_clicked. |
99 |
MockMethod.bind(self, push, 'do_push', "test success") |
776.3.11
by Curtis Hovey
Added test to verify that DivergedBranches is handled. |
100 |
set_ui_factory() |
101 |
branch = self.make_push_branch() |
|
102 |
dialog = push.PushDialog(None, None, branch) |
|
776.3.10
by Curtis Hovey
Verified that the progress widget was called. |
103 |
MockMethod.bind(self, dialog._progress_widget, 'tick') |
776.3.9
by Curtis Hovey
Added a simple test for _on_push_clicked. |
104 |
dialog._combo.get_child().props.text = 'lp:~user/fnord/test' |
105 |
dialog._on_push_clicked(None) |
|
776.3.10
by Curtis Hovey
Verified that the progress widget was called. |
106 |
self.assertIs(True, dialog._progress_widget.tick.called) |
107 |
self.assertIs(False, dialog._progress_widget.props.visible) |
|
776.3.9
by Curtis Hovey
Added a simple test for _on_push_clicked. |
108 |
self.assertIs(True, push.do_push.called) |
109 |
self.assertEqual( |
|
110 |
(branch, 'lp:~user/fnord/test'), push.do_push.args) |
|
111 |
self.assertEqual( |
|
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) |
|
115 |
self.assertEqual( |
|
116 |
'lp:~user/fnord/test', dialog._history.get_entries()[-1]) |
|
117 |
self.assertEqual('lp:~user/fnord/test', branch.get_push_location()) |
|
776.3.11
by Curtis Hovey
Added test to verify that DivergedBranches is handled. |
118 |
|
119 |
def test_on_push_clicked_with_divered_branches(self): |
|
776.3.16
by Curtis Hovey
Added comments. |
120 |
# Verify that when DivergedBranches is raise, the user can choose
|
121 |
# to overwrite the branch.
|
|
776.3.11
by Curtis Hovey
Added test to verify that DivergedBranches is handled. |
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) |
|
125 |
set_ui_factory() |
|
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) |
|
132 |
self.assertEqual( |
|
133 |
(branch, 'lp:~user/fnord/test'), push.do_push.args) |
|
134 |
self.assertEqual( |
|
135 |
{'overwrite': True}, push.do_push.kwargs) |
|
776.3.19
by Curtis Hovey
Add test coverage for do_push. |
136 |
|
137 |
||
776.3.20
by Curtis Hovey
Fix redefined testcase. Remove unneeded tests. |
138 |
class DoPushTestCase(tests.TestCaseWithTransport): |
776.3.19
by Curtis Hovey
Add test coverage for do_push. |
139 |
|
140 |
def setup_ui(self): |
|
141 |
set_ui_factory() |
|
142 |
progress_panel = ProgressPanel() |
|
143 |
ui.ui_factory.set_progress_bar_widget(progress_panel) |
|
144 |
MockMethod.bind(self, progress_panel.pb, 'tick') |
|
145 |
MockMethod.bind(self, progress_panel.pb, 'update') |
|
146 |
MockMethod.bind(self, progress_panel.pb, 'finished') |
|
147 |
return progress_panel |
|
148 |
||
149 |
def make_from_branch(self): |
|
150 |
from_tree = self.make_branch_and_tree('this') |
|
151 |
self.build_tree(['this/a', 'this/b']) |
|
152 |
from_tree.add(['a', 'b']) |
|
153 |
from_tree.commit("msg") |
|
154 |
return from_tree.branch |
|
155 |
||
156 |
def test_do_push_without_dir(self): |
|
157 |
progress_panel = self.setup_ui() |
|
158 |
from_branch = self.make_from_branch() |
|
159 |
message = push.do_push(from_branch, 'that', False) |
|
160 |
self.assertEqual('1 revision(s) pushed.', message) |
|
161 |
self.assertEqual(True, progress_panel.pb.update.called) |
|
162 |
self.assertEqual(True, progress_panel.pb.finished.called) |
|
163 |
||
164 |
def test_do_push_without_parent_dir(self): |
|
165 |
progress_panel = self.setup_ui() |
|
166 |
from_branch = self.make_from_branch() |
|
167 |
MockMethod.bind(self, push, 'question_dialog', Gtk.ResponseType.OK) |
|
168 |
message = push.do_push(from_branch, 'that/there', False) |
|
169 |
self.assertEqual('1 revision(s) pushed.', message) |
|
170 |
self.assertEqual(True, push.question_dialog.called) |
|
171 |
self.assertEqual(True, progress_panel.pb.update.called) |
|
172 |
self.assertEqual(True, progress_panel.pb.finished.called) |
|
173 |
||
776.3.22
by Curtis Hovey
Added test for aborted message. |
174 |
def test_do_push_without_parent_dir_aborted(self): |
175 |
self.setup_ui() |
|
176 |
from_branch = self.make_from_branch() |
|
177 |
MockMethod.bind(self, push, 'question_dialog', Gtk.ResponseType.CANCEL) |
|
178 |
message = push.do_push(from_branch, 'that/there', False) |
|
179 |
self.assertEqual('Push aborted.', message) |
|
180 |
||
776.3.19
by Curtis Hovey
Add test coverage for do_push. |
181 |
def test_do_push_with_dir(self): |
182 |
progress_panel = self.setup_ui() |
|
183 |
self.make_branch_and_tree('that') |
|
184 |
from_branch = self.make_from_branch() |
|
185 |
message = push.do_push(from_branch, 'that', False) |
|
186 |
self.assertEqual('1 revision(s) pushed.', message) |
|
187 |
self.assertEqual(True, progress_panel.pb.update.called) |
|
188 |
self.assertEqual(True, progress_panel.pb.finished.called) |
|
776.3.21
by Curtis Hovey
Replace do_push with a method based on bzrlib.push. |
189 |
|
190 |
def test_create_push_result_unstacked(self): |
|
191 |
from_branch = object() |
|
192 |
to_branch = self.make_branch_and_tree('that').branch |
|
193 |
push_result = push.create_push_result(from_branch, to_branch) |
|
194 |
self.assertIs(from_branch, push_result.source_branch) |
|
195 |
self.assertIs(to_branch, push_result.target_branch) |
|
196 |
self.assertIs(None, push_result.branch_push_result) |
|
197 |
self.assertIs(None, push_result.master_branch) |
|
198 |
self.assertEqual(0, push_result.old_revno) |
|
199 |
self.assertEqual(to_branch.last_revision(), push_result.old_revid) |
|
200 |
self.assertIs(None, push_result.workingtree_updated) |
|
201 |
self.assertIs(None, push_result.stacked_on) |
|
202 |
||
203 |
def test_create_push_result_stacked(self): |
|
204 |
from_branch = object() |
|
205 |
to_branch = self.make_branch_and_tree('that').branch |
|
206 |
MockMethod.bind(self, to_branch, 'get_stacked_on_url', 'lp:project') |
|
207 |
push_result = push.create_push_result(from_branch, to_branch) |
|
208 |
self.assertEqual('lp:project', push_result.stacked_on) |
|
209 |
||
210 |
def test_create_push_message_stacked_on(self): |
|
211 |
from_branch = object() |
|
212 |
to_branch = self.make_branch_and_tree('that').branch |
|
213 |
MockMethod.bind(self, to_branch, 'get_stacked_on_url', 'lp:project') |
|
214 |
push_result = push.create_push_result(from_branch, to_branch) |
|
215 |
from_branch = self.make_from_branch() |
|
216 |
message = push.create_push_message(from_branch, push_result) |
|
217 |
self.assertEqual( |
|
218 |
'1 revision(s) pushed.\nStacked on lp:project.', message) |
|
219 |
||
220 |
def test_create_push_message_workingtree_updated_false(self): |
|
221 |
from_branch = object() |
|
222 |
to_branch = self.make_branch_and_tree('that').branch |
|
223 |
push_result = push.create_push_result(from_branch, to_branch) |
|
224 |
push_result.workingtree_updated = False |
|
225 |
from_branch = self.make_from_branch() |
|
226 |
message = push.create_push_message(from_branch, push_result) |
|
227 |
self.assertEqual( |
|
228 |
"1 revision(s) pushed.\n\nThe working tree was not updated:\n" |
|
229 |
"See 'bzr help working-trees' for more information.", |
|
230 |
message) |