~diegosarmentero/ubuntuone-windows-installer/not-validated-account

« back to all changes in this revision

Viewing changes to ubuntuone_installer/gui/qt/main/tests/test_windows.py

  • Committer: Tarmac
  • Author(s): Natalia B. Bidart
  • Date: 2011-11-12 02:00:31 UTC
  • mfrom: (85.1.5 import-qt4reactor)
  • Revision ID: tarmac-20111112020031-gvj3ise8dpm2xs7g
- Import qt4reactor properly (LP: #888722).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
 
3
 
# Authors: Alejandro J. Cura <alecu@canonical.com>
4
 
#          Roberto Alsina <roberto.alsina@canonical.com>
5
 
#
6
 
# Copyright 2011 Canonical Ltd.
7
 
#
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.
11
 
#
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.
16
 
#
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/>.
19
 
 
20
 
"""Tests for the Windows main."""
21
 
 
22
 
from twisted.internet import defer
23
 
 
24
 
from ubuntuone_installer.gui.qt.main import windows
25
 
from ubuntuone_installer.tests import TestCase
26
 
 
27
 
 
28
 
class FakeLogger(object):
29
 
 
30
 
    """Fake Logger."""
31
 
 
32
 
    error_args = None
33
 
    debug_args = None
34
 
    info_args = None
35
 
 
36
 
    def error(self, *args, **kwargs):
37
 
        """Save the error."""
38
 
        self.error_args = (args, kwargs)
39
 
 
40
 
    def debug(self, *args, **kwargs):
41
 
        """Save the debug."""
42
 
        self.debug_args = (args, kwargs)
43
 
 
44
 
    def info(self, *args, **kwargs):
45
 
        """Save the info."""
46
 
        self.info_args = (args, kwargs)
47
 
 
48
 
 
49
 
class FakeGui(object):
50
 
    """Fake gui module."""
51
 
 
52
 
    def __init__(self):
53
 
        """Create a new instance."""
54
 
        self.main_window = None
55
 
        self.close = None
56
 
        self.installing = False
57
 
        self.called = []
58
 
 
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
67
 
 
68
 
 
69
 
class FakeWindow(object):
70
 
    """Fake a window."""
71
 
 
72
 
    def __init__(self):
73
 
        """Create a new instance."""
74
 
        self.shown = False
75
 
 
76
 
    def show(self):
77
 
        """Fake a shown window."""
78
 
        self.shown = True
79
 
 
80
 
 
81
 
class SuccessTestCase(TestCase):
82
 
    """Test the success callback."""
83
 
 
84
 
    @defer.inlineCallbacks
85
 
    def setUp(self):
86
 
        """Set up the diff tests."""
87
 
        yield super(SuccessTestCase, self).setUp()
88
 
        self.called = []
89
 
        self.start_name = 'start'
90
 
        self.update_name = 'update'
91
 
        self.stop_name = 'stop'
92
 
        self.gui = FakeGui()
93
 
        self.gui.main_window = FakeWindow()
94
 
        self.logger = FakeLogger()
95
 
 
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)
100
 
 
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)
105
 
 
106
 
        def fake_stop():
107
 
            """Fake stop."""
108
 
            self.called.append((self.stop_name,))
109
 
 
110
 
        self.patch(windows, 'stop', fake_stop)
111
 
        self.start_cb = fake_start
112
 
        self.check_updates_cb = fake_check_updates
113
 
 
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))
126
 
 
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)
134
 
 
135
 
 
136
 
class ErrorTestCase(TestCase):
137
 
    """Test the success callback."""
138
 
 
139
 
    @defer.inlineCallbacks
140
 
    def setUp(self):
141
 
        """Set up the diff tests."""
142
 
        yield super(ErrorTestCase, self).setUp()
143
 
        self.called = []
144
 
        self.stop_name = 'stop'
145
 
        self.logger = FakeLogger()
146
 
 
147
 
        def fake_stop():
148
 
            """Fake stop."""
149
 
            self.called.append(self.stop_name)
150
 
 
151
 
        self.patch(windows, 'stop', fake_stop)
152
 
 
153
 
    def test_stop(self):
154
 
        """Test the error_cb"""
155
 
        windows.error_cb(Exception('test'), self.logger)
156
 
        self.assertTrue(self.stop_name in self.called)