~mandel/ubuntuone-control-panel/auto-update-looping-call

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/gui/qt/tests/test_systray.py

  • Committer: Manuel de la Pena
  • Date: 2012-01-23 11:36:36 UTC
  • mfrom: (236.2.16 ubuntuone-control-panel)
  • Revision ID: manuel.delapena@canonical.com-20120123113636-tknfv5jeqn6gjrdq
Merged with trunk and fixed conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from PyQt4 import QtGui
22
22
from twisted.internet import defer, reactor
23
23
 
24
 
from ubuntuone.controlpanel.gui.qt.systray import TrayIcon
 
24
from ubuntuone.controlpanel.gui.qt import systray
25
25
from ubuntuone.controlpanel.tests import TestCase
26
26
import ubuntuone.controlpanel.gui.qt.gui
27
27
 
28
28
 
 
29
class FakeSDTool(object):
 
30
 
 
31
    """Fake SyncDaemonTool."""
 
32
 
 
33
    called = False
 
34
 
 
35
    def quit(self):
 
36
        """Fake quit."""
 
37
        self.called = True
 
38
 
 
39
 
29
40
class FakeMainWindow(QtGui.QWidget):
30
41
 
31
42
    """Fake Main Window."""
68
79
        """Test the quit option with no looping call."""
69
80
        # Not done on setup, because if I patch stop
70
81
        # after instantiation, it doesn't get called.
71
 
        self.patch(TrayIcon, "stop", self._set_called)
72
 
        tray = TrayIcon()
 
82
        self.patch(systray.TrayIcon, "stop", self._set_called)
 
83
        tray = systray.TrayIcon()
73
84
        tray.quit.trigger()
74
85
        self.assertEqual(self._called, ((False,), {}))
75
86
 
76
87
    def test_quit_lc_not_running(self):
77
88
        """Test the quit option with a stopped looping call."""
78
89
        self.patch(reactor, 'stop', self._set_called)
79
 
        tray = TrayIcon()
 
90
        tray = systray.TrayIcon()
80
91
        tray.auto_update_lc = self.looping_call
81
92
        tray.quit.trigger()
82
93
        self.assertEqual(self._called, ((), {}))
86
97
        """Test the quit option with a running looping call."""
87
98
        self.patch(reactor, 'stop', self._set_called)
88
99
        self.looping_call.running = True
89
 
        tray = TrayIcon()
 
100
        tray = systray.TrayIcon()
90
101
        tray.auto_update_lc = self.looping_call
91
102
        tray.quit.trigger()
92
103
        self.assertEqual(self._called, ((), {}))
93
104
        self.assertEqual(1, len(self.looping_call.called))
94
105
        self.assertTrue('stop' in self.looping_call.called[0])
95
106
 
 
107
    @defer.inlineCallbacks
 
108
    def test_stop_sd(self):
 
109
        """Quit should call SyncDaemonTool.quit()."""
 
110
        st = FakeSDTool()
 
111
        self.patch(systray, "SyncDaemonTool", lambda: st)
 
112
        self.patch(reactor, "stop", lambda: None)
 
113
        tray = systray.TrayIcon()
 
114
        yield tray.stop()
 
115
        self.assertTrue(st.called)
 
116
 
96
117
    def test_restore_no_window(self):
97
118
        """Test the restore window option in the menu, with no window."""
98
119
        self.patch(ubuntuone.controlpanel.gui.qt.gui,
99
120
            "MainWindow", FakeMainWindow)
100
 
        tray = TrayIcon()
 
121
        tray = systray.TrayIcon()
101
122
        self.assertEqual(tray.window, None)
102
123
        tray.restore.trigger()
103
124
        self.assertIsInstance(tray.window, FakeMainWindow)
107
128
 
108
129
    def test_activate(self):
109
130
        """Test the icon activation."""
110
 
        tray = TrayIcon()
 
131
        tray = systray.TrayIcon()
111
132
        window = FakeMainWindow()
112
133
        tray.window = window
113
134
        self.assertFalse(tray.window.isVisible())
117
138
 
118
139
    def test_restore_window(self):
119
140
        """Test the restore window option in the menu, with a window."""
120
 
        tray = TrayIcon()
 
141
        tray = systray.TrayIcon()
121
142
        window = FakeMainWindow()
122
143
        tray.window = window
123
144
        self.assertFalse(tray.window.isVisible())
127
148
 
128
149
    def test_delete_window(self):
129
150
        """Test deleting an existing window."""
130
 
        tray = TrayIcon()
 
151
        tray = systray.TrayIcon()
131
152
        window = FakeMainWindow()
132
153
        tray.window = window
133
154
        tray.delete_window()
136
157
 
137
158
    def test_delete_no_window(self):
138
159
        """Test deleting without an existing window."""
139
 
        tray = TrayIcon()
 
160
        tray = systray.TrayIcon()
140
161
        tray.delete_window()
141
162
        self.assertEqual(tray.window, None)
142
163
 
143
164
    def test_initialization(self):
144
165
        """Test that everything initializes correctly."""
145
 
        tray = TrayIcon()
 
166
        tray = systray.TrayIcon()
146
167
        self.assertTrue(tray.isVisible())
147
168
        self.assertEqual(tray.window, None)
148
169
        self.assertIsInstance(tray.context_menu, QtGui.QMenu)
161
182
        def fake_clicked_message_cb():
162
183
            """A fake clicked cb."""
163
184
 
164
 
        self.patch(TrayIcon, 'showMessage', fake_qt_show_message)
165
 
        tray = TrayIcon()
 
185
        self.patch(systray.TrayIcon, 'showMessage', fake_qt_show_message)
 
186
        tray = systray.TrayIcon()
166
187
        tray.show_message(title, message, fake_clicked_message_cb)
167
188
        self.assertTrue(tray in called)
168
189
        self.assertTrue(title in called)