1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2014 Canonical
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
8
from __future__ import absolute_import
9
from autopilot.matchers import Eventually
10
from dbusmock.templates.networkmanager import DEVICE_IFACE
11
from testtools.matchers import Equals
12
from time import sleep
13
from ubuntu_system_settings.tests import WifiBaseTestCase
14
from ubuntu_system_settings.utils.i18n import ugettext as _
15
from unittest import skip
18
class WifiTestCase(WifiBaseTestCase):
19
"""Tests for Language Page"""
21
def test_wifi_page_title_is_correct(self):
22
"""Checks whether Wifi page is available"""
27
def test_connect_to_hidden_network(self):
28
dialog = self.wifi_page.connect_to_hidden_network(
30
scroll_to_and_click=self.system_settings.main_view
33
# allow backend to set up listeners
36
"""Mock a StateChanged signal on the Device, using a likely
37
scenario of a not found SSID:
38
newState = 120 # NM_DEVICE_STATE_FAILED
39
oldState = 0 # does not matter
40
reason = 53 # NM_DEVICE_STATE_REASON_SSID_NOT_FOUND
43
self.device_mock.EmitSignal(
44
DEVICE_IFACE, 'StateChanged', 'uuu', [100, 0, 0])
47
dialog.wait_until_destroyed()
49
def test_connect_to_nonexistant_hidden_network(self):
51
dialog = self.wifi_page.connect_to_hidden_network(
53
scroll_to_and_click=self.system_settings.main_view
56
# allow backend to set up listeners
59
"""Mock a StateChanged signal on the Device, using a likely
60
scenario of a not found SSID:
61
newState = 120 # NM_DEVICE_STATE_FAILED
62
oldState = 0 # does not matter
63
reason = 53 # NM_DEVICE_STATE_REASON_SSID_NOT_FOUND
66
self.device_mock.EmitSignal(
67
DEVICE_IFACE, 'StateChanged', 'uuu', [120, 0, 53])
70
dialog.text, Eventually(Equals(
71
_('The Wi-Fi network could not be found'))))
73
@skip('skipped due to bug 1337556')
74
def test_connect_to_hidden_network_using_secrets(self):
75
dialog = self.wifi_page.connect_to_hidden_network(
76
'yeah', security='wpa', password='abcdefgh',
77
scroll_to_and_click=self.system_settings.main_view
80
# allow backend to set up listeners
83
"""Mock a StateChanged signal on the Device, which
84
lets the backend know it was the wrong secret:
85
newState = 100 # NM_DEVICE_STATE_ACTIVATED
86
oldState = 0 # does not matter
87
reason = 0 # does not matter
90
self.device_mock.EmitSignal(
91
DEVICE_IFACE, 'StateChanged', 'uuu', [100, 0, 0])
94
dialog.wait_until_destroyed()
96
@skip('skipped due to bug 1337556')
97
def test_connect_to_hidden_network_using_incorrect_secrets(self):
98
dialog = self.wifi_page.connect_to_hidden_network(
99
'yeah', security='wpa', password='abcdefgh',
100
scroll_to_and_click=self.system_settings.main_view
101
.scroll_to_and_click)
102
# allow backend to set up listeners
105
"""Mock a StateChanged signal on the Device, which
106
lets the backend know it was the wrong secret:
107
newState = 120 # NM_DEVICE_STATE_FAILED
108
oldState = 0 # does not matter
109
reason = 7 # NM_DEVICE_STATE_REASON_NO_SECRETS
112
self.device_mock.EmitSignal(
113
DEVICE_IFACE, 'StateChanged', 'uuu', [120, 0, 7])
116
dialog.text, Eventually(Equals(
117
_('Your authentication details were incorrect'))))
119
def test_connect_to_hidden_network_then_cancel(self):
121
dialog = self.wifi_page.connect_to_hidden_network(
123
scroll_to_and_click=self.system_settings.main_view
124
.scroll_to_and_click)
126
# allow backend to set up listeners
131
# check that Disconnect was called once
134
len(self.device_mock.GetMethodCalls('Disconnect')),
135
Eventually(Equals(1)))
137
"""Note: this test does not actually remove previous networks from the UI.
138
The NetworkManager dbusmock template does not currently support deletion
140
def test_remove_previous_network(self):
141
click_method = self.system_settings.main_view.scroll_to_and_click
142
previous_networks = [{
143
'ssid': 'Series of Tubes',
144
'connection_name': 'conn_0'
147
'connection_name': 'conn_1'
150
'connection_name': 'conn_2'
153
self.add_previous_networks(previous_networks)
155
self.wifi_page.remove_previous_network(
156
previous_networks[0]['ssid'], scroll_to_and_click=click_method)
158
self.system_settings.main_view.go_back()
160
self.wifi_page.remove_previous_network(
161
previous_networks[2]['ssid'], scroll_to_and_click=click_method)