~ubuntu-branches/ubuntu/oneiric/ubuntuone-control-panel/oneiric

« back to all changes in this revision

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

* New upstream release:
  [ Alejandro J. Cura <alecu@canonical.com>]
    - Do not throw a webclient error when closing
      (LP: #845105).
  [ Natalia B. Bidart <natalia.bidart@canonical.com> ]
    - Removed all code related to Bookmarks (LP: #850142).
    - Replaces references to "Evolution" by "Thunderbird" (LP: #849494).
  [ Rodney Dawes <rodney.dawes@canonical.com> ]
    - Don't install a .desktop file for control panel
      (part of LP: #838778).
    - Point the indicator/Unity API at the installer .desktop file
      (part of LP: #838778).
    - Set the WMCLASS so Unity will fall back properly
      (part of LP: #838778).
    - Fix a few grammar mistakes (LP: #835093).
    - Don't show the "Get NGB free!" label on "Join now" button at all
      (LP: #819955).
* debian/control:
  - ubuntuone-control-panel-gtk depends now on ubuntuone-installer >= 2.0.0.
  - require ubuntuone-client >= 2.0.0.
  - require ubuntu-sso-client >= 1.4.0.
  - no longer install a .desktop file (will be installed by ubuntuone-installer).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
 
4
#
 
5
# Copyright 2011 Canonical Ltd.
 
6
#
 
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.
 
10
#
 
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.
 
15
#
 
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/>.
 
18
 
 
19
"""Tests for the Sign In Panel."""
 
20
 
 
21
from twisted.internet import defer
 
22
 
 
23
from ubuntuone.controlpanel.gui import qt
 
24
from ubuntuone.controlpanel.gui.qt import signin as gui
 
25
from ubuntuone.controlpanel.gui.qt.tests import (
 
26
    CrashyBackend,
 
27
    CrashyBackendException,
 
28
)
 
29
from ubuntuone.controlpanel.gui.qt.tests.test_ubuntuonebin import (
 
30
    UbuntuOneBinTestCase,
 
31
)
 
32
 
 
33
EMAIL = 'foo@bar.com'
 
34
PASSWORD = 'h3ll0World'
 
35
TOKEN = {'yadda': 'doo'}
 
36
 
 
37
MSG = {u'errtype': u'AuthenticationError',
 
38
       u'message': u'The authentication failed.'}
 
39
 
 
40
 
 
41
def fail(*a, **kw):
 
42
    """Emit CredentialsError."""
 
43
    raise TypeError(MSG)
 
44
 
 
45
 
 
46
class BaseSignInPanelTestCase(UbuntuOneBinTestCase):
 
47
    """Test the signin panel."""
 
48
 
 
49
    innerclass_ui = gui.signin_ui
 
50
    innerclass_name = "Ui_Form"
 
51
    class_ui = gui.SignInPanel
 
52
    logger = gui.logger
 
53
 
 
54
    @defer.inlineCallbacks
 
55
    def setUp(self):
 
56
        yield super(BaseSignInPanelTestCase, self).setUp()
 
57
        self.ui.backend.next_result = TOKEN
 
58
 
 
59
 
 
60
class SignInPanelTestCase(BaseSignInPanelTestCase):
 
61
    """Test the signin panel."""
 
62
 
 
63
    innerclass_ui = gui.signin_ui
 
64
    innerclass_name = "Ui_Form"
 
65
    class_ui = gui.SignInPanel
 
66
 
 
67
    @defer.inlineCallbacks
 
68
    def setUp(self):
 
69
        yield super(SignInPanelTestCase, self).setUp()
 
70
        self.ui.backend.next_result = TOKEN
 
71
        self.ui.ui.email_entry.setText(gui.QtCore.QString(''))
 
72
        self.ui.ui.password_entry.setText(gui.QtCore.QString(''))
 
73
 
 
74
    @defer.inlineCallbacks
 
75
    def test_is_processing_while_asking_info(self):
 
76
        """The ui is processing while the contents are loaded."""
 
77
        def check(email, password):
 
78
            """The ui must be is_processing."""
 
79
            self.assertTrue(self.ui.is_processing, 'ui must be processing')
 
80
            return TOKEN
 
81
 
 
82
        self.patch(self.ui.backend, 'login', check)
 
83
 
 
84
        self.assertFalse(self.ui.is_processing)
 
85
        yield self.ui.ui.signin_button.click()
 
86
        self.assertFalse(self.ui.is_processing)
 
87
 
 
88
    def test_signin_disabled_at_startup(self):
 
89
        """The signin_button is disabled at startup."""
 
90
        self.assertFalse(self.ui.ui.signin_button.isEnabled())
 
91
 
 
92
    def test_signin_disabled_if_no_email_but_password(self):
 
93
        """Disable signin_button if no email."""
 
94
        self.ui.ui.password_entry.setText(gui.QtCore.QString('doo'))
 
95
        self.assertFalse(self.ui.ui.signin_button.isEnabled())
 
96
 
 
97
    def test_signin_disabled_if_no_password_but_email(self):
 
98
        """Disable signin_button if no password."""
 
99
        self.ui.ui.email_entry.setText(gui.QtCore.QString('duh'))
 
100
        self.assertFalse(self.ui.ui.signin_button.isEnabled())
 
101
 
 
102
    def test_cancel_button(self):
 
103
        """Send a signal when the cancel button is clicked."""
 
104
        self.ui.signinCanceled.connect(self._set_called)
 
105
        self.ui.ui.cancel_button.click()
 
106
        self.assertEqual(self._called, ((), {}))
 
107
 
 
108
    def test_forgot_password_button(self):
 
109
        """When clicking the forgot passsword btn, the proper url is opened."""
 
110
        self.patch(qt, 'uri_hook', self._set_called)
 
111
        self.ui.ui.forgot_password_button.click()
 
112
 
 
113
        self.assertEqual(self._called, ((gui.RESET_PASSWORD_LINK,), {}))
 
114
 
 
115
 
 
116
class SignInButtonPanelTestCase(BaseSignInPanelTestCase):
 
117
    """Test the signin_button widget."""
 
118
 
 
119
    @defer.inlineCallbacks
 
120
    def setUp(self):
 
121
        yield super(SignInButtonPanelTestCase, self).setUp()
 
122
        self.ui.ui.email_entry.setText(gui.QtCore.QString(EMAIL))
 
123
        self.ui.ui.password_entry.setText(gui.QtCore.QString(PASSWORD))
 
124
 
 
125
    @defer.inlineCallbacks
 
126
    def test_signin_button(self):
 
127
        """Call the backend when the signin button is clicked."""
 
128
        yield self.ui.ui.signin_button.click()
 
129
 
 
130
        self.assert_backend_called('login', email=EMAIL, password=PASSWORD)
 
131
        # pylint: disable=W0212
 
132
        for arg in self.ui.backend._called['login'][1].itervalues():
 
133
            self.assertIsInstance(arg, unicode)  # make sure not send QString
 
134
 
 
135
    @defer.inlineCallbacks
 
136
    def test_signin_success(self):
 
137
        """Emit credentialsFound on signin success."""
 
138
        self.ui.credentialsFound.connect(self._set_called)
 
139
        yield self.ui.ui.signin_button.click()
 
140
 
 
141
        self.assertEqual(self._called, ((TOKEN,), {}))
 
142
        self.assertFalse(self.ui.is_processing)
 
143
 
 
144
    def test_signin_enabled_if_email_and_password(self):
 
145
        """Enable signin_button if email and password are non empty."""
 
146
        self.assertTrue(self.ui.ui.signin_button.isEnabled())
 
147
 
 
148
    def test_return_pressed(self):
 
149
        """On return pressed, click the signin_button."""
 
150
        self.patch(self.ui.ui.signin_button, 'click', self._set_called)
 
151
 
 
152
        for entry in (self.ui.ui.email_entry, self.ui.ui.password_entry):
 
153
            entry.returnPressed.emit()
 
154
 
 
155
            # This is failing, so we need to settle with counting recievers
 
156
            #self.assertEqual(self._called, ((), {}))
 
157
            receivers = entry.receivers(gui.QtCore.SIGNAL('returnPressed()'))
 
158
            self.assertEqual(1, receivers)
 
159
 
 
160
            self._called = False
 
161
 
 
162
    @defer.inlineCallbacks
 
163
    def test_backend_error_is_handled(self):
 
164
        """Any error from the backend is properly handled."""
 
165
        self.patch(self.ui, 'backend', CrashyBackend())
 
166
        yield self.ui.ui.signin_button.click()
 
167
 
 
168
        self.assertTrue(self.memento.check_exception(CrashyBackendException))