1
# -*- coding: utf-8 -*-
3
# Copyright 2012 Canonical Ltd.
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.
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.
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/>.
17
"""Tests for the Setup Account page Qt UI."""
19
from PyQt4 import QtGui, QtCore
20
from twisted.internet import defer
22
from ubuntu_sso.qt import gui
23
from ubuntu_sso.qt import email_verification_page
24
from ubuntu_sso.qt.tests import (
31
from ubuntu_sso.qt.ui import email_verification_ui
34
# pylint: disable=W0212
35
class EmailVerificationTestCase(BaseTestCase):
36
"""Test the SetupAccountPage code."""
38
@defer.inlineCallbacks
40
yield super(EmailVerificationTestCase, self).setUp()
41
self.patch(gui.main, "get_sso_client", FakedBackend)
42
self.ui = email_verification_page.EmailVerificationPage(
43
email_verification_ui.Ui_EmailVerificationPage(),
45
self.wizard = FakeWizard()
46
self.patch(self.ui, 'wizard', lambda: self.wizard)
49
"""Test the construction of the object."""
50
self.assertTrue('EmailValidated' in self.ui._signals)
51
self.assertTrue('EmailValidationError' in self.ui._signals)
52
self.assertTrue(callable(self.ui._signals['EmailValidated']))
53
self.assertTrue(callable(self.ui._signals['EmailValidationError']))
54
self.assertEqual(self.ui.backend, FakedBackend.sso_login)
56
# pylint: disable=E1101
57
def test_setup_page(self):
58
"""Test that the backend is received and the methods are called."""
61
'_connect_ui_elements']
62
self.patch(FakedObject, "exposed_methods", exposed_methods)
63
faked_object = FakedObject()
64
self.patch(self.ui, "_setup_signals",
65
faked_object._setup_signals)
66
self.patch(self.ui, "_connect_ui_elements",
67
faked_object._connect_ui_elements)
69
self.assertTrue('_setup_signals' in faked_object._called)
70
self.assertTrue('_connect_ui_elements' in faked_object._called)
71
# pylint: enable=E1101
73
def test_verification_code(self):
74
"""Test the verification value returned."""
75
self.ui.ui.verification_code_edit.setText('asd123')
76
value = self.ui.verification_code
77
self.assertEqual(value, 'asd123')
78
self.assertTrue(isinstance(value, str))
80
def test_next_button(self):
81
"""Test the next button."""
82
value = self.ui.next_button
83
self.assertEqual(value, self.ui.ui.next_button)
84
self.assertTrue(isinstance(value, QtGui.QPushButton))
86
def test_connect_ui_elements(self):
87
"""Test the connect ui method."""
88
self.ui._connect_ui_elements()
89
# We expect 2 values because _connect_ui is called in the init too.
90
self.assertEqual(self.ui.ui.verification_code_edit.receivers(
91
QtCore.SIGNAL("textChanged(const QString&)")), 2)
92
self.assertEqual(self.ui.next_button.receivers(
93
QtCore.SIGNAL("clicked()")), 2)
95
def test_validate_form_not_valid(self):
96
"""Test validate method."""
97
button = FakePageUiStyle()
98
self.patch(self.ui.ui, "next_button", button)
99
self.ui.ui.verification_code_edit.setText(' ')
100
self.ui.validate_form()
101
self.assertFalse(button.isEnabled())
102
self.assertTrue(button.property("DisabledState"))
103
self.assertTrue(button.properties['unpolish'])
104
self.assertTrue(button.properties['polish'])
106
def test_validate_form_valid(self):
107
"""Test validate method."""
108
button = FakePageUiStyle()
109
self.patch(self.ui.ui, "next_button", button)
110
self.ui.ui.verification_code_edit.setText('asd123')
111
self.ui.validate_form()
112
self.assertTrue(button.isEnabled())
113
self.assertFalse(button.property("DisabledState"))
114
self.assertTrue(button.properties['unpolish'])
115
self.assertTrue(button.properties['polish'])
117
def test_set_titles(self):
118
"""Test the set_titles method."""
119
email = 'mail@example'
121
self.ui.app_name = app_name
122
self.ui.email = email
123
self.ui.set_titles(email)
124
self.assertEqual(self.ui.header.title_label.text(),
125
email_verification_page.VERIFY_EMAIL_TITLE)
126
expected = email_verification_page.VERIFY_EMAIL_CONTENT % {
127
"app_name": app_name,
130
self.assertEqual(str(self.ui.header.subtitle_label.text()),
133
def test_initialize_page(self):
134
"""Test the initialization method."""
135
button = FakePageUiStyle()
136
self.patch(self.ui.ui, "next_button", button)
137
self.ui.initializePage()
138
self.assertTrue(button.properties['default'])
139
self.assertFalse(button.isEnabled())
140
self.assertTrue(button.property("DisabledState"))
141
self.assertTrue(button.properties['unpolish'])
142
self.assertTrue(button.properties['polish'])
144
def test_on_email_validation_error(self):
145
"""Test the validate_email method."""
146
self.patch(self.ui.message_box, "critical", self._set_called)
148
error = {email_verification_page: 'error in email_verification_page'}
149
self.ui.on_email_validation_error(app_name, error)
150
expected = ((self.ui, app_name, ''), {})
151
self.assertTrue(expected, self._called)