~ubuntu-branches/ubuntu/precise/ubuntu-sso-client/precise

46 by Natalia Bidart (nessita)
* New upstream release:
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
"""The test suite for Network Detection UI."""
18
19
from twisted.internet import defer
20
21
from PyQt4 import QtGui
22
23
from ubuntu_sso.qt import network_detection_page
24
from ubuntu_sso.qt.tests import (
25
    BaseTestCase,
26
    FakeWizardButtonStyle,
27
)
28
29
30
class NetworkDetectionTestCase(BaseTestCase):
31
32
    """Test the CurrentUserController."""
33
34
    @defer.inlineCallbacks
35
    def setUp(self):
36
        """Initialize this test instance."""
37
        yield super(NetworkDetectionTestCase, self).setUp()
38
        self.wizard = FakeWizardButtonStyle()
39
        self.network_detection = network_detection_page.NetworkDetectionPage()
40
        self.patch(self.network_detection, 'wizard', self._get_wizard)
41
42
    def _get_wizard(self):
43
        """Fake wizard method for wizard page."""
44
        return self.wizard
45
46
    # pylint: disable=W0212
47
    def test_initialize_page(self):
48
        """Check Network detection initialize page."""
49
        self.network_detection.initializePage()
50
        self.assertEqual(self.wizard._next_id, None)
51
        self.assertTrue(('setButtonLayout', ([
52
            QtGui.QWizard.Stretch,
53
            QtGui.QWizard.CustomButton1,
54
            QtGui.QWizard.CancelButton], {})),
55
            self.wizard.called)
56
57
    def test_initialize_page_button_property(self):
58
        """Test the Try Again button properties."""
59
        self.patch(self.network_detection,
60
            "wizard", FakeWizardButtonStyle)
61
        self.network_detection.initializePage()
62
        self.assertTrue(self.network_detection.btn_try_again.isDefault())
63
        self.assertIn('polish', self.network_detection.btn_try_again.data)
64
        self.assertIn('unpolish', self.network_detection.btn_try_again.data)
65
        self.assertEqual(
66
            self.network_detection.btn_try_again.data['polish'],
67
            self.network_detection.btn_try_again)
68
        self.assertEqual(
69
            self.network_detection.btn_try_again.data['unpolish'],
70
            self.network_detection.btn_try_again)
71
72
    def test_try_again_with_connection(self):
73
        """Check try again method with connection."""
74
        self.patch(network_detection_page.networkstate, 'is_machine_connected',
75
            lambda: True)
76
        self.wizard._next_id = -1
77
        if 'next' in self.wizard.data:
78
            self.wizard.data.pop('next')
79
        self.network_detection.try_again()
80
        self.assertEqual(self.wizard._next_id, None)
81
        self.assertTrue(self.wizard.data.get('next', False))
82
83
    def test_try_again_without_connection(self):
84
        """Check try again method without connection."""
85
        self.patch(network_detection_page.networkstate, 'is_machine_connected',
86
            lambda: False)
87
        self.wizard._next_id = -1
88
        if 'next' in self.wizard.data:
89
            self.wizard.data.pop('next')
90
        self.network_detection.try_again()
91
        self.assertEqual(self.wizard._next_id, -1)
92
        self.assertFalse(self.wizard.data.get('next', False))
93
    # pylint: enable=W0212