~mvo/ubuntu-sso-client/strawman-lp711413

« back to all changes in this revision

Viewing changes to ubuntu_sso/qt/tests/test_ssl_dialog.py

  • Committer: Tarmac
  • Author(s): Natalia B. Bidart, Manuel de la Pena, Roberto Alsina, Diego Sarmentero
  • Date: 2012-03-06 17:54:16 UTC
  • mfrom: (827.1.2 stable-3-0-update-2.99.90)
  • Revision ID: tarmac-20120306175416-nvsq3pby6w9fzxzv
- Updating from trunk up to revno 901:

[ Diego Sarmentero <diego.sarmentero@canonical.com> ]
  - Hide the errors label on refresh captcha (LP: #947202).
  - Changed the name of the function assigned to the lambda that is called
    on passwordChanged signal from reset_password_page (LP: #945080).
  - Made on_user_validated also emit stopProcessing so callers can hide
    any processing overlay they are showing (LP: #945094).
  - Fixed: Qt UI: there is a Back button in the "Enter verification page"
    (LP: #944769).
  - Fixed: Qt UI: there is not loading overvaly while validating an
    email address (LP: #944767).
  - Fixed: Qt UI: clicking on the "Set Up Account" button takes me
    instantly to the verification page, even if there are form errors
    (LP: #934502).
  - Fix: [UIFe] Improve the display of errors in the Qt UI (LP: #938604).
  - Fix: Qt UI: center when first opening (LP: #934173).
  - Fixed: The header in the pages is above the overlay (LP: #934523).
  - Fixed: [UIFE] The padding of the wizard pages in the Qt UI is not
    correct  (LP: #934519).

[ Manuel de la Pena <manuel.delapena@canonical.com> ]
  - Ensure that the strings used in sso do not have "ubuntu one" in them
    (LP: #933729).
  - Ensure that the strings used are the ones provided by design
    (LP: #937905).
  - Added the dialog that will be used to show that a certificate has issues
    (LP: #933729).

[ Natalia B. Bidart <natalia.bidart@canonical.com> ]
  - Add proper titles and subtitles for the Login and Forgot password
    pages (LP: #945061).
  - Made UI modules to setup the gui logging logger (LP: #947469).
  - Fallback to the GTK+ UI when the specified ui_executable does
    not exist (LP: #939821).
  - Move the 'choose sign in page' to client code (U1 control panel
    in this case) (LP: #933576).
  - Make use of the 'login_only' parameter that is being passed to the
    UbuntuSSOWizard (LP: #939558).
  - Stop using is_reactor_installed since is buggy (LP: #933644).
  - Do not mask ImportError by importing inside a function (LP: #939173).
  - No more strings coming up from the Designer ui files (LP: #938626).

[ Roberto Alsina <roberto.alsina@canonical.com> ]
  - Made the network detection code return ONLINE if NM is not available
    (but still UNKNOWN if it's available and fails) (LP: #939703).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# Copyright 2012 Canonical Ltd.
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify it
 
6
# under the terms of the GNU General Public License version 3, as published
 
7
# by the Free Software Foundation.
 
8
#
 
9
# This program is distributed in the hope that it will be useful, but
 
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
12
# PURPOSE.  See the GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License along
 
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 
 
17
"""Test the ssl dialog."""
 
18
 
 
19
from PyQt4.QtGui import QStyle
 
20
from twisted.internet import defer
 
21
from twisted.trial.unittest import TestCase
 
22
 
 
23
from ubuntu_sso import USER_CANCELLATION, USER_SUCCESS
 
24
from ubuntu_sso.qt import ssl_dialog
 
25
from ubuntu_sso.utils.ui import (
 
26
    CANCEL_BUTTON,
 
27
    SSL_APPNAME_HELP,
 
28
    SSL_DETAILS_HELP,
 
29
    SSL_DESCRIPTION,
 
30
    SSL_DOMAIN_HELP,
 
31
    SSL_HEADER,
 
32
    SSL_EXPLANATION,
 
33
    SSL_FIRST_REASON,
 
34
    SSL_SECOND_REASON,
 
35
    SSL_THIRD_REASON,
 
36
    SSL_CERT_DETAILS,
 
37
    SSL_NOT_SURE,
 
38
    SSL_REMEMBER_DECISION,
 
39
    SSL_HELP_BUTTON,
 
40
    SSL_CONNECT_BUTTON,
 
41
)
 
42
 
 
43
# pylint: disable=W0212, C0103,
 
44
 
 
45
 
 
46
class SSLDialogTestCase(TestCase):
 
47
    """Test the ssl dialog."""
 
48
 
 
49
    @defer.inlineCallbacks
 
50
    def setUp(self):
 
51
        """Set the tests."""
 
52
        yield super(SSLDialogTestCase, self).setUp()
 
53
        self.domain = 'test-domain'
 
54
        self.details = 'SSL details'
 
55
        self.appname = 'test'
 
56
 
 
57
        self.dialog = ssl_dialog.SSLDialog(self.appname,
 
58
                                           domain=self.domain,
 
59
                                           details=self.details)
 
60
        self.return_code = None
 
61
 
 
62
        def fake_done(code):
 
63
            """Fake done for the dialog."""
 
64
            self.return_code = code
 
65
 
 
66
        self.patch(self.dialog, 'done', fake_done)
 
67
 
 
68
    def test_init_none_domain(self):
 
69
        """Test the init method when the domain is none."""
 
70
        dialog = ssl_dialog.SSLDialog(self.appname, domain=None,
 
71
                                      details=self.details)
 
72
        self.assertEqual(self.details, dialog.details)
 
73
        self.assertEqual('', dialog.domain)
 
74
 
 
75
    def test_init_none_details(self):
 
76
        """Test the init method when the details are none."""
 
77
        dialog = ssl_dialog.SSLDialog(self.appname, domain=self.domain,
 
78
                                      details=None)
 
79
        self.assertEqual('', dialog.details)
 
80
        self.assertEqual(self.domain, dialog.domain)
 
81
 
 
82
    def test_set_labels(self):
 
83
        """Test that the labels contain the correct info."""
 
84
        self.assertEqual(SSL_HEADER,
 
85
                         unicode(self.dialog.ui.title_label.text()))
 
86
        explanation = SSL_EXPLANATION % dict(domain=self.domain)
 
87
        intro = ssl_dialog.REASONS_TEMPLATE % dict(explanation=explanation,
 
88
                                              first_reason=SSL_FIRST_REASON,
 
89
                                              second_reason=SSL_SECOND_REASON,
 
90
                                              third_reason=SSL_THIRD_REASON)
 
91
        self.assertEqual(intro, unicode(self.dialog.ui.intro_label.text()))
 
92
        self.assertEqual(SSL_NOT_SURE % dict(app_name=self.appname),
 
93
                unicode(self.dialog.ui.not_sure_label.text()))
 
94
        self.assertEqual(SSL_REMEMBER_DECISION,
 
95
                unicode(self.dialog.ui.remember_checkbox.text()))
 
96
 
 
97
    def test_on_cancel_clicked(self):
 
98
        """Test the cancelation action."""
 
99
        self.dialog._on_cancel_clicked()
 
100
        self.assertEqual(USER_CANCELLATION, self.return_code)
 
101
 
 
102
    def test_on_connect_clicked(self):
 
103
        """Test the connect action."""
 
104
        self.dialog._on_connect_clicked()
 
105
        self.assertEqual(USER_SUCCESS, self.return_code)
 
106
 
 
107
    def test_set_buttons(self):
 
108
        """Test that the buttons are correctly set up."""
 
109
 
 
110
        # assert that the buttons have been correctly connected
 
111
        called = []
 
112
 
 
113
        def fake_on_connect_clicked(event):
 
114
            """Fake the on connect clicked method."""
 
115
            called.append('_on_connect_clicked')
 
116
 
 
117
        self.patch(ssl_dialog.SSLDialog, '_on_connect_clicked',
 
118
                                          fake_on_connect_clicked)
 
119
 
 
120
        def fake_on_cancel_clicked(event):
 
121
            """Fake the on cancle clicked."""
 
122
            called.append('_on_cancel_clicked')
 
123
 
 
124
        self.patch(ssl_dialog.SSLDialog, '_on_cancel_clicked',
 
125
                                          fake_on_cancel_clicked)
 
126
 
 
127
        dialog = ssl_dialog.SSLDialog(self.appname, domain=None,
 
128
                                      details=self.details)
 
129
 
 
130
        dialog.ui.connect_button.clicked.emit(True)
 
131
        self.assertIn('_on_connect_clicked', called)
 
132
 
 
133
        dialog.ui.cancel_button.clicked.emit(True)
 
134
        self.assertIn('_on_cancel_clicked', called)
 
135
 
 
136
        self.assertEqual(CANCEL_BUTTON,
 
137
                unicode(dialog.ui.cancel_button.text()))
 
138
        self.assertEqual(SSL_CONNECT_BUTTON,
 
139
                unicode(dialog.ui.connect_button.text()))
 
140
        self.assertEqual(SSL_HELP_BUTTON,
 
141
                unicode(dialog.ui.help_button.text()))
 
142
 
 
143
    def test_set_expander(self):
 
144
        """Test that the expander is correctly set."""
 
145
        self.assertEqual(SSL_CERT_DETAILS, self.dialog.expander.text())
 
146
        self.assertNotEqual(None, self.dialog.expander.content)
 
147
        self.assertEqual(2, self.dialog.ui.expander_layout.indexOf(
 
148
                                                        self.dialog.expander))
 
149
 
 
150
    def test_set_icon(self):
 
151
        """Test that the icon is correctly set."""
 
152
        self.assertNotEqual(None, self.dialog.ui.logo_label.pixmap())
 
153
        icon = self.dialog.style().standardIcon(QStyle.SP_MessageBoxWarning)
 
154
        self.assertEqual(icon.pixmap(48, 48).toImage(),
 
155
                         self.dialog.ui.logo_label.pixmap().toImage())
 
156
        self.assertEqual('', self.dialog.ui.logo_label.text())
 
157
 
 
158
 
 
159
class FakeArgumentParser(object):
 
160
    """Fake args parse."""
 
161
 
 
162
    def __init__(self):
 
163
        """Create an instance."""
 
164
        self.called = []
 
165
 
 
166
    def __call__(self, description=''):
 
167
        """Instance callable."""
 
168
        self.called.append(('__init__', description))
 
169
        return self
 
170
 
 
171
    # pylint: disable=W0622
 
172
    def add_argument(self, name, required=False, help=''):
 
173
        """Add an argument."""
 
174
        self.called.append(('add_argument', name, required, help))
 
175
    # pylint: enable=W0622
 
176
 
 
177
    def parse_args(self):
 
178
        """Parse the args."""
 
179
        self.called.append(('parse_args',))
 
180
        return self
 
181
 
 
182
 
 
183
class ParseArgTestCase(TestCase):
 
184
    """Test the parse of the args."""
 
185
 
 
186
    def test_parse_args(self):
 
187
        """Set tests."""
 
188
        argparse = FakeArgumentParser()
 
189
        self.patch(ssl_dialog.argparse, 'ArgumentParser', argparse)
 
190
        args = ssl_dialog.parse_args()
 
191
        self.assertEqual(argparse, args)
 
192
        self.assertIn(('__init__', SSL_DESCRIPTION), argparse.called)
 
193
        self.assertIn(('add_argument', '--domain', True, SSL_DOMAIN_HELP),
 
194
                                                         argparse.called)
 
195
        self.assertIn(('add_argument', '--details', True, SSL_DETAILS_HELP),
 
196
                                                          argparse.called)
 
197
        self.assertIn(('add_argument', '--appname', True, SSL_APPNAME_HELP),
 
198
                                                          argparse.called)
 
199
        self.assertIn(('parse_args',), argparse.called)