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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-

# Copyright 2012 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program.  If not, see <http://www.gnu.org/licenses/>.

"""The test suite for Network Detection UI."""

from twisted.internet import defer

from PyQt4 import QtGui

from ubuntu_sso.qt import network_detection_page
from ubuntu_sso.qt.tests import (
    BaseTestCase,
    FakeWizardButtonStyle,
)


class NetworkDetectionTestCase(BaseTestCase):

    """Test the CurrentUserController."""

    @defer.inlineCallbacks
    def setUp(self):
        """Initialize this test instance."""
        yield super(NetworkDetectionTestCase, self).setUp()
        self.wizard = FakeWizardButtonStyle()
        self.network_detection = network_detection_page.NetworkDetectionPage()
        self.patch(self.network_detection, 'wizard', self._get_wizard)

    def _get_wizard(self):
        """Fake wizard method for wizard page."""
        return self.wizard

    # pylint: disable=W0212
    def test_initialize_page(self):
        """Check Network detection initialize page."""
        self.network_detection.initializePage()
        self.assertEqual(self.wizard._next_id, None)
        self.assertTrue(('setButtonLayout', ([
            QtGui.QWizard.Stretch,
            QtGui.QWizard.CustomButton1,
            QtGui.QWizard.CancelButton], {})),
            self.wizard.called)

    def test_initialize_page_button_property(self):
        """Test the Try Again button properties."""
        self.patch(self.network_detection,
            "wizard", FakeWizardButtonStyle)
        self.network_detection.initializePage()
        self.assertTrue(self.network_detection.btn_try_again.isDefault())
        self.assertIn('polish', self.network_detection.btn_try_again.data)
        self.assertIn('unpolish', self.network_detection.btn_try_again.data)
        self.assertEqual(
            self.network_detection.btn_try_again.data['polish'],
            self.network_detection.btn_try_again)
        self.assertEqual(
            self.network_detection.btn_try_again.data['unpolish'],
            self.network_detection.btn_try_again)

    def test_try_again_with_connection(self):
        """Check try again method with connection."""
        self.patch(network_detection_page.networkstate, 'is_machine_connected',
            lambda: True)
        self.wizard._next_id = -1
        if 'next' in self.wizard.data:
            self.wizard.data.pop('next')
        self.network_detection.try_again()
        self.assertEqual(self.wizard._next_id, None)
        self.assertTrue(self.wizard.data.get('next', False))

    def test_try_again_without_connection(self):
        """Check try again method without connection."""
        self.patch(network_detection_page.networkstate, 'is_machine_connected',
            lambda: False)
        self.wizard._next_id = -1
        if 'next' in self.wizard.data:
            self.wizard.data.pop('next')
        self.network_detection.try_again()
        self.assertEqual(self.wizard._next_id, -1)
        self.assertFalse(self.wizard.data.get('next', False))
    # pylint: enable=W0212