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
"""The test suite for Network Detection UI."""
19
from twisted.internet import defer
21
from PyQt4 import QtGui
23
from ubuntu_sso.qt import network_detection_page
24
from ubuntu_sso.qt.tests import (
26
FakeWizardButtonStyle,
30
class NetworkDetectionTestCase(BaseTestCase):
32
"""Test the CurrentUserController."""
34
@defer.inlineCallbacks
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)
42
def _get_wizard(self):
43
"""Fake wizard method for wizard page."""
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], {})),
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)
66
self.network_detection.btn_try_again.data['polish'],
67
self.network_detection.btn_try_again)
69
self.network_detection.btn_try_again.data['unpolish'],
70
self.network_detection.btn_try_again)
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',
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))
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',
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