~ralsina/ubuntuone-control-panel/unique_in_ubuntu

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Natalia B. Bidart, Manuel de la Pena
  • Date: 2012-04-05 18:07:56 UTC
  • mfrom: (307.1.6 autoupdate)
  • Revision ID: tarmac-20120405180756-bwh9460pl303hfwi
- Check for updates when the main window is shown. On linux, this is a no
operation. On windows, this will check for new versions of the software and
will prompt the user for confirmation to install updates (LP: #971455).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
 
 
3
 
# Authors: Alejandro J. Cura <alecu@canonical.com>
4
2
#
5
 
# Copyright 2011 Canonical Ltd.
 
3
# Copyright 2011-2012 Canonical Ltd.
6
4
#
7
5
# This program is free software: you can redistribute it and/or modify it
8
6
# under the terms of the GNU General Public License version 3, as published
21
19
from twisted.internet import defer
22
20
 
23
21
from ubuntuone.controlpanel.gui.qt import gui
24
 
from ubuntuone.controlpanel.gui.qt.tests import BaseTestCase
 
22
from ubuntuone.controlpanel.gui.qt.tests import BaseTestCase, FakedDialog
25
23
 
26
24
 
27
25
class FakeEntry(object):
119
117
        self.assertEqual(entry.called, (('urgent', "foo"), {}))
120
118
 
121
119
 
 
120
class CheckUpdatesNoUpdatesTestCase(MainWindowTestCase):
 
121
    """Test the check_updates method when there are no updates."""
 
122
 
 
123
    updates_available = False
 
124
 
 
125
    @defer.inlineCallbacks
 
126
    def setUp(self):
 
127
        """Set the different tests."""
 
128
        yield super(CheckUpdatesNoUpdatesTestCase, self).setUp()
 
129
        self.patch(gui.utils, 'are_updates_present',
 
130
                   lambda: defer.succeed(self.updates_available))
 
131
        self.patch(gui.utils, 'perform_update',
 
132
                   lambda: defer.fail(ValueError()))
 
133
 
 
134
    @defer.inlineCallbacks
 
135
    def test_update_confirmation_dialog(self):
 
136
        """The confirmation dialog is not shown."""
 
137
        yield self.ui.check_updates()
 
138
        self.assertEqual(None, FakedDialog.args)
 
139
        self.assertEqual(None, FakedDialog.kwargs)
 
140
 
 
141
    @defer.inlineCallbacks
 
142
    def test_perform_update(self):
 
143
        """The perform_update method is not called."""
 
144
        yield self.ui.check_updates()
 
145
        self.assertFalse(self._called)
 
146
 
 
147
 
 
148
class CheckUpdatesUserSaysNoTestCase(CheckUpdatesNoUpdatesTestCase):
 
149
    """Test check_updates when there are updates and user rejects them."""
 
150
 
 
151
    updates_available = True
 
152
    user_response = gui.QtGui.QMessageBox.No
 
153
 
 
154
    @defer.inlineCallbacks
 
155
    def setUp(self):
 
156
        """Set the different tests."""
 
157
        yield super(CheckUpdatesUserSaysNoTestCase, self).setUp()
 
158
        self.patch(FakedDialog, 'response', self.user_response)
 
159
 
 
160
    @defer.inlineCallbacks
 
161
    def test_update_confirmation_dialog(self):
 
162
        """The confirmation dialog is shown with correct params."""
 
163
        yield self.ui.check_updates()
 
164
        args = (self.ui, gui.UPDATE_TITLE, gui.UPDATE_SOFTWARE,
 
165
                gui.QtGui.QMessageBox.Yes | gui.QtGui.QMessageBox.No,
 
166
                gui.QtGui.QMessageBox.Yes)
 
167
        self.assertEqual(args, FakedDialog.args)
 
168
        self.assertEqual({}, FakedDialog.kwargs)
 
169
 
 
170
 
 
171
class CheckUpdatesUserSaysYesTestCase(CheckUpdatesUserSaysNoTestCase):
 
172
    """Test check_updates when there are updates and user accepts them."""
 
173
 
 
174
    user_response = gui.QtGui.QMessageBox.Yes
 
175
 
 
176
    @defer.inlineCallbacks
 
177
    def setUp(self):
 
178
        """Set the different tests."""
 
179
        self.updated = defer.Deferred()
 
180
        yield super(CheckUpdatesUserSaysYesTestCase, self).setUp()
 
181
        self.patch(gui.utils, 'perform_update',
 
182
                   lambda *a, **kw: self.updated.callback((a, kw)))
 
183
 
 
184
    @defer.inlineCallbacks
 
185
    def test_perform_update(self):
 
186
        """The perform_update method is called."""
 
187
        yield self.ui.check_updates()
 
188
        result = yield self.updated  # perform_update will fire this deferred
 
189
 
 
190
        self.assertEqual(result, ((), {}))
 
191
 
 
192
 
122
193
class AutoStartTestCase(MainWindowTestCase):
123
194
    """Test the add_to_autostart call."""
124
195
 
125
196
    @defer.inlineCallbacks
126
197
    def setUp(self):
127
198
        # Be sure to patch add_to_autostart *before* class_ui creation occurs.
128
 
        self.patch(gui, "add_to_autostart", self._set_called)
 
199
        self.patch(gui.utils, "add_to_autostart", self._set_called)
129
200
        yield super(AutoStartTestCase, self).setUp()
130
201
 
131
202
    def test_add_to_autostart(self):