1
# -*- coding: utf-8 -*-
3
# Author: Manuel de la Pena<manuel@canonical.com>
5
# Copyright 2011 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
18
"""Tests for the network manager."""
19
from mocker import MockerTestCase
20
from ubuntu_sso.networkstate.windows import (
27
class TestNetworkManager(MockerTestCase):
28
"""Test he Network Manager."""
31
super(TestNetworkManager, self).setUp()
32
self.connection_info = self.mocker.mock()
33
self.connection_no_info = self.mocker.mock()
34
self.disconnected = self.mocker.mock()
35
self.manager = NetworkManager(self.connection_no_info,
36
self.connection_info, self.disconnected)
38
def test_connection_made(self):
39
"""Ensure db is called."""
40
self.connection_info()
42
self.manager.ConnectionMade()
44
def test_connection_made_no_cb(self):
45
"""Ensure db is called."""
46
self.manager.connected_cb_info = None
48
self.manager.ConnectionMade()
50
def test_connection_made_no_info(self):
51
"""Ensure db is called."""
52
self.connection_no_info()
54
self.manager.ConnectionMadeNoQOCInfo()
56
def test_connection_made_no_info_no_cb(self):
57
"""Ensure db is called."""
58
self.manager.connected_cb = None
60
self.manager.ConnectionMadeNoQOCInfo()
62
def test_disconnection(self):
63
"""Ensure db is called."""
66
self.manager.ConnectionLost()
68
def test_disconnection_no_cb(self):
69
"""Ensure db is called."""
70
self.manager.disconnected_cb = None
72
self.manager.ConnectionLost()
75
class TestNetworkManagerState(MockerTestCase):
76
"""Test he Network Manager State."""
79
super(TestNetworkManagerState, self).setUp()
80
self.network_manager = self.mocker.mock()
81
self.is_connected = self.mocker.replace(
82
'ubuntu_sso.networkstate.windows.is_machine_connected')
83
self.thread = self.mocker.mock()
84
self.cb = self.mocker.mock()
85
self.state = NetworkManagerState(self.cb)
87
def test_connection_made(self):
88
"""Test that the cb is actually called."""
91
self.state.connection_made()
93
def test_connection_lost(self):
94
"""Test that the cb is actually called."""
97
self.state.connection_lost()
99
def test_find_online_state_not_connected(self):
100
"""Test that we do find the online state correctly."""
102
self.mocker.result(False)
104
self.mocker.result(self.thread)
107
self.state.find_online_state(listener=self.network_manager,
108
listener_thread=self.thread)
110
def test_find_online_state_connected(self):
111
"""Test that we do find the online state correctly."""
113
self.mocker.result(ONLINE)
115
self.mocker.result(self.thread)
118
self.state.find_online_state(listener=self.network_manager,
119
listener_thread=self.thread)