~diegosarmentero/ubuntu-sso-client/message-critical

« back to all changes in this revision

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

Reset Password Page Complete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Author: Manuel de la Pena <manuel@canonical.com>
 
3
#
 
4
# Copyright 2011 Canonical Ltd.
 
5
#
 
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.
 
9
#
 
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.
 
14
#
 
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."""
 
18
 
 
19
from PyQt4 import QtGui, QtCore
 
20
from twisted.trial.unittest import TestCase
 
21
 
 
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
 
25
 
 
26
 
 
27
class FakePasswordAssistance(object):
 
28
    """Fake password_assistance_* calls."""
 
29
 
 
30
    _called = False
 
31
 
 
32
    def call(self, *args, **kwargs):
 
33
        """Check if the method was called."""
 
34
        FakePasswordAssistance._called = True
 
35
 
 
36
    def clenaup(self):
 
37
        """Clean up the variable."""
 
38
        FakePasswordAssistance._called = False
 
39
 
 
40
 
 
41
class SetupAccountTestCase(TestCase):
 
42
    """Test the ResetPasswordPage code."""
 
43
 
 
44
    def setUp(self):
 
45
        super(SetupAccountTestCase, self).setUp()
 
46
        self.page = ResetPasswordPage(Ui_ResetPasswordPage(),
 
47
                                                None,
 
48
                                                None)
 
49
        self.fake = FakePasswordAssistance()
 
50
 
 
51
    def test_init(self):
 
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)
 
57
 
 
58
    def test_focus_changed_password_visibility(self):
 
59
        """Check visibility changes when focus_changed() is executed."""
 
60
        self.page.show()
 
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())
 
64
 
 
65
    def test_show_hide_event(self):
 
66
        """Check connections to focusChanged on show and hide event."""
 
67
        self.page.show()
 
68
        self.addCleanup(self.page.hide)
 
69
        self.assertEqual(QtGui.QApplication.instance().receivers(
 
70
            QtCore.SIGNAL("focusChanged(QWidget*, QWidget*)")), 1)
 
71
        self.page.hide()
 
72
        self.assertEqual(QtGui.QApplication.instance().receivers(
 
73
            QtCore.SIGNAL("focusChanged(QWidget*, QWidget*)")), 0)
 
74
 
 
75
    # pylint: disable=W0212
 
76
 
 
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)
 
81
        self.page.show()
 
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)
 
87
 
 
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)
 
92
        self.page.show()
 
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)
 
98
 
 
99
    # pylint: enable=W0212