1
# -*- coding: utf-8 -*-
3
# Author: Roberto Alsina <roberto.alsina@canonical.com>
5
# Copyright 2011 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
"""Tests for the start function."""
21
from twisted.internet import defer
23
from ubuntuone.controlpanel.gui.qt import gui
24
from ubuntuone.controlpanel.gui.qt.tests import NO_OP
25
from ubuntuone.controlpanel.tests import TestCase
28
class FakeThing(object):
36
def __call__(self, *args, **kwargs):
37
self.args.append((args, kwargs))
45
class FakeReactor(object):
55
class StartTestCase(TestCase):
56
"""Test the qt control panel."""
58
@defer.inlineCallbacks
60
yield super(StartTestCase, self).setUp()
61
self.main_window = FakeThing()
62
self.tray_icon = FakeThing()
63
self.patch(gui, "MainWindow", self.main_window)
64
self.patch(gui, "TrayIcon", self.tray_icon)
66
def test_minimized(self):
67
"""Test behaviour with minimized=True."""
68
gui.start(NO_OP, minimized=True, with_icon=True)
69
self.assertEqual(self.tray_icon.args, [((), {'window': None})])
70
self.assertEqual(self.main_window.args, [])
72
def test_with_icon(self):
73
"""Test behaviour with with_icon=True."""
74
gui.start(NO_OP, with_icon=True, minimized=False)
75
self.assertEqual(self.main_window.args, [((), {})])
76
self.assertEqual(self.tray_icon.args, [((),
77
{'window': self.main_window})])
79
def test_both_false(self):
80
"""Test behaviour when with_icon and minimized are False."""
81
gui.start(NO_OP, with_icon=False, minimized=False)
83
self.assertNotEqual(self.main_window.args, [])
84
# Should not be called
85
self.assertEqual(self.tray_icon.args, [])
87
def test_both_true(self):
88
"""Test behaviour when with_icon and minimized are True."""
89
gui.start(NO_OP, with_icon=True, minimized=True)
90
self.assertEqual(self.tray_icon.args, [((), {'window': None})])
91
self.assertEqual(self.main_window.args, [])