1
# -*- coding: utf-8 -*-
2
# Author: Manuel de la Pena <manuel@canonical.com>
4
# Copyright 2011 Canonical Ltd.
6
# This program is free software: you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License version 3, as published
8
# by the Free Software Foundation.
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranties of
12
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13
# PURPOSE. See the GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License along
16
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
"""Test the Reset Password Page."""
19
from PyQt4 import QtGui, QtCore
20
from twisted.trial.unittest import TestCase
22
from ubuntu_sso.qt import common
23
from ubuntu_sso.qt.gui import ResetPasswordPage
24
from ubuntu_sso.qt.reset_password_ui import Ui_ResetPasswordPage
27
class FakePasswordAssistance(object):
28
"""Fake password_assistance_* calls."""
32
def call(self, *args, **kwargs):
33
"""Check if the method was called."""
34
FakePasswordAssistance._called = True
37
"""Clean up the variable."""
38
FakePasswordAssistance._called = False
41
class SetupAccountTestCase(TestCase):
42
"""Test the ResetPasswordPage code."""
45
super(SetupAccountTestCase, self).setUp()
46
self.page = ResetPasswordPage(Ui_ResetPasswordPage(),
49
self.fake = FakePasswordAssistance()
52
"""Check the initial state of ResetPassword."""
53
self.assertEqual(self.page.ui.password_line_edit.receivers(
54
QtCore.SIGNAL('textEdited(QString)')), 1)
55
self.assertEqual(self.page.ui.confirm_password_line_edit.receivers(
56
QtCore.SIGNAL('textEdited(QString)')), 1)
58
def test_focus_changed_password_visibility(self):
59
"""Check visibility changes when focus_changed() is executed."""
61
self.addCleanup(self.page.hide)
62
self.page.focus_changed(None, self.page.ui.password_line_edit)
63
self.assertTrue(self.page.ui.password_assistance.isVisible())
65
def test_show_hide_event(self):
66
"""Check connections to focusChanged on show and hide event."""
68
self.addCleanup(self.page.hide)
69
self.assertEqual(QtGui.QApplication.instance().receivers(
70
QtCore.SIGNAL("focusChanged(QWidget*, QWidget*)")), 1)
72
self.assertEqual(QtGui.QApplication.instance().receivers(
73
QtCore.SIGNAL("focusChanged(QWidget*, QWidget*)")), 0)
75
# pylint: disable=W0212
77
def test_focus_changed_1(self):
78
"""Check functions execution when focus_changed() is executed."""
79
self.patch(common, 'password_default_assistance', self.fake.call)
80
self.addCleanup(self.fake.clenaup)
82
self.addCleanup(self.page.hide)
83
self.assertFalse(FakePasswordAssistance._called)
84
self.page.focus_changed(None, self.page.ui.password_line_edit)
85
self.assertTrue(self.page.ui.password_assistance.isVisible())
86
self.assertTrue(FakePasswordAssistance._called)
88
def test_focus_changed_2(self):
89
"""Check functions execution when focus_changed() is executed."""
90
self.patch(common, 'password_check_match', self.fake.call)
91
self.addCleanup(self.fake.clenaup)
93
self.addCleanup(self.page.hide)
94
self.assertFalse(FakePasswordAssistance._called)
95
self.page.focus_changed(None, self.page.ui.confirm_password_line_edit)
96
self.assertTrue(self.page.ui.password_assistance.isVisible())
97
self.assertTrue(FakePasswordAssistance._called)
99
# pylint: enable=W0212