1
# -*- coding: utf-8 -*-
3
# Authors: Alejandro J. Cura <alecu@canonical.com>
4
# Roberto Alsina <roberto.alsina@canonical.com>
6
# Copyright 2011 Canonical Ltd.
8
# This program is free software: you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License version 3, as published
10
# by the Free Software Foundation.
12
# This program is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranties of
14
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
# PURPOSE. See the GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License along
18
# with this program. If not, see <http://www.gnu.org/licenses/>.
20
"""Tests for the Windows main."""
22
from twisted.internet import defer
24
from ubuntuone_installer.gui.qt.main import windows
25
from ubuntuone_installer.tests import TestCase
28
class FakeLogger(object):
36
def error(self, *args, **kwargs):
38
self.error_args = (args, kwargs)
40
def debug(self, *args, **kwargs):
42
self.debug_args = (args, kwargs)
44
def info(self, *args, **kwargs):
46
self.info_args = (args, kwargs)
49
class FakeGui(object):
50
"""Fake gui module."""
53
"""Create a new instance."""
54
self.main_window = None
56
self.installing = False
59
# pylint: disable=C0103
60
def MainWindow(self, close_callback=lambda: None, installing=False):
61
"""Fake main window creation."""
62
self.close = close_callback
63
self.installing = installing
64
self.called.append('MainWindow')
65
return self.main_window
66
# pylint: enable=C0103
69
class FakeWindow(object):
73
"""Create a new instance."""
77
"""Fake a shown window."""
81
class SuccessTestCase(TestCase):
82
"""Test the success callback."""
84
@defer.inlineCallbacks
86
"""Set up the diff tests."""
87
yield super(SuccessTestCase, self).setUp()
89
self.start_name = 'start'
90
self.update_name = 'update'
91
self.stop_name = 'stop'
93
self.gui.main_window = FakeWindow()
94
self.logger = FakeLogger()
96
def fake_start(with_icon=False):
97
"""Fake the control panel start."""
98
self.called.append((self.start_name, with_icon))
99
return defer.succeed(None)
101
def fake_check_updates(gui, logger):
102
"""Fake the check of updates."""
103
self.called.append((self.update_name, gui, logger))
104
return defer.succeed(None)
108
self.called.append((self.stop_name,))
110
self.patch(windows, 'stop', fake_stop)
111
self.start_cb = fake_start
112
self.check_updates_cb = fake_check_updates
114
@defer.inlineCallbacks
115
def test_success_with_creds(self):
116
"""Test the success callback with creds."""
117
yield windows.success_cb('creds', self.gui, False, self.logger,
118
self.start_cb, self.check_updates_cb)
119
self.assertEqual(self.start_name, self.called[0][0])
120
self.assertFalse(self.called[0][1])
121
self.assertEqual(self.update_name, self.called[1][0])
122
self.assertEqual(self.gui, self.called[1][1])
123
self.assertEqual(self.logger, self.called[1][2])
124
self.assertEqual(self.stop_name, self.called[2][0])
125
self.assertEqual(0, len(self.gui.called))
127
@defer.inlineCallbacks
128
def test_success_not_creds(self):
129
"""Test the success callback with no creds."""
130
yield windows.success_cb(None, self.gui, True, self.logger,
131
self.start_cb, self.check_updates_cb)
132
self.assertTrue('MainWindow' in self.gui.called)
133
self.assertTrue(self.gui.main_window.shown)
136
class ErrorTestCase(TestCase):
137
"""Test the success callback."""
139
@defer.inlineCallbacks
141
"""Set up the diff tests."""
142
yield super(ErrorTestCase, self).setUp()
144
self.stop_name = 'stop'
145
self.logger = FakeLogger()
149
self.called.append(self.stop_name)
151
self.patch(windows, 'stop', fake_stop)
154
"""Test the error_cb"""
155
windows.error_cb(Exception('test'), self.logger)
156
self.assertTrue(self.stop_name in self.called)