35
35
self.called = (args, kwargs)
38
class FakeMainWindow(object):
41
def __init__(self, close_callback=None):
42
"""Create a new instance."""
44
self.close_callback = None
46
def __call__(self, *args, **kwargs):
47
"""Make the object callable to fake a constructor."""
51
"""Fake show the window."""
52
self.called.append(('show',))
55
class FakeTrayIcon(object):
58
def __init__(self, window=None):
59
"""Create a new instance."""
60
self.auto_update = None
63
def __call__(self, window, *args, **kwargs):
64
"""Make the object callable to fake a cosntructor."""
68
def get_auto_update_lc(self):
69
"""Get the auto_update_lc."""
70
return self.auto_update
72
def set_auto_update_lc(self, value):
73
"""Set the auto_update_lc."""
74
self.auto_update = value
76
auto_update_lc = property(get_auto_update_lc,
80
class FakeLoopingCall(object):
81
"""Fake a looping call."""
84
"""Create a new instance."""
90
def __call__(self, f, *args, **kwargs):
91
"""Call looping call."""
97
def start(self, interval, now=False):
99
self.called.append(('start', interval, now))
38
102
class MainWindowTestCase(BaseTestCase):
39
103
"""Test the qt main window."""
131
195
def test_add_to_autostart(self):
132
196
"""Test that the add_to_autostart function is called when CP opens."""
133
197
self.assertTrue(self._called)
200
class StartTestCase(BaseTestCase):
201
"""Test the start method."""
203
@defer.inlineCallbacks
206
yield super(StartTestCase, self).setUp()
208
self.auto_update_interval = 0.5
209
self.looping_call = FakeLoopingCall()
212
"""Fake stop function."""
213
self.called.append(('stop',))
215
def auto_update(title, message, icon, logger):
216
"""Fake auto_update_cb."""
217
self.called.append(('auto_update_cb', title, message,
221
self.auto_update_cb = auto_update
222
self.main_window = FakeMainWindow()
223
self.tray_icon = FakeTrayIcon()
225
def test_start_not_minimized_no_icon(self):
226
"""Test the not minimized mode with no icon."""
227
icon, window = gui.start(self.stop_cb, minimized=False,
229
self.assertEqual(1, len(self.main_window.called))
230
self.assertTrue('show' in self.main_window.called[0])
231
self.assertEqual(None, self.looping_call.function)
232
self.assertNotEqual(None, window)
233
self.assertEqual(None, icon)
235
def _assert_minimized_or_icon(self, icon, window):
236
"""Assert the start of a minimized of icon mode."""
237
self.assertIsInstance(self.tray_icon.auto_update, FakeLoopingCall)
238
self.assertNotEqual(None, self.looping_call.function)
239
self.assertNotEqual(None, icon)
241
def test_start_with_icon(self):
242
"""Test the with icon start."""
243
icon, window = gui.start(self.stop_cb, minimized=False,
245
self._assert_minimized_or_icon(icon, window)
246
self.assertEqual(1, len(self.main_window.called))
247
self.assertTrue('show' in self.main_window.called[0])
248
self.assertNotEqual(None, window)
249
self.assertNotEqual(None, self.tray_icon.window)
251
def test_start_minimized(self):
252
"""Test the minimized start."""
253
icon, window = gui.start(self.stop_cb, minimized=True,
255
self._assert_minimized_or_icon(icon, window)
256
self.assertEqual(0, len(self.main_window.called))
257
self.assertEqual(None, window)
258
self.assertEqual(None, self.tray_icon.window)