~mvo/ubuntu-sso-client/strawman-lp711413

« back to all changes in this revision

Viewing changes to ubuntu_sso/tests/networkstate/test_windows_networkstate.py

Added the network status implementation for windows.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# Author: Manuel de la Pena<manuel@canonical.com>
 
4
#
 
5
# Copyright 2011 Canonical Ltd.
 
6
#
 
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.
 
10
#
 
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.
 
15
#
 
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 (
 
21
    NetworkManager,
 
22
    NetworkManagerState,
 
23
    ONLINE,
 
24
    OFFLINE)
 
25
 
 
26
 
 
27
class TestNetworkManager(MockerTestCase):
 
28
    """Test he Network Manager."""
 
29
 
 
30
    def setUp(self):
 
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)
 
37
 
 
38
    def test_connection_made(self):
 
39
        """Ensure db is called."""
 
40
        self.connection_info()
 
41
        self.mocker.replay()
 
42
        self.manager.ConnectionMade()
 
43
 
 
44
    def test_connection_made_no_cb(self):
 
45
        """Ensure db is called."""
 
46
        self.manager.connected_cb_info = None
 
47
        self.mocker.replay()
 
48
        self.manager.ConnectionMade()
 
49
 
 
50
    def test_connection_made_no_info(self):
 
51
        """Ensure db is called."""
 
52
        self.connection_no_info()
 
53
        self.mocker.replay()
 
54
        self.manager.ConnectionMadeNoQOCInfo()
 
55
 
 
56
    def test_connection_made_no_info_no_cb(self):
 
57
        """Ensure db is called."""
 
58
        self.manager.connected_cb = None
 
59
        self.mocker.replay()
 
60
        self.manager.ConnectionMadeNoQOCInfo()
 
61
 
 
62
    def test_disconnection(self):
 
63
        """Ensure db is called."""
 
64
        self.disconnected()
 
65
        self.mocker.replay()
 
66
        self.manager.ConnectionLost()
 
67
 
 
68
    def test_disconnection_no_cb(self):
 
69
        """Ensure db is called."""
 
70
        self.manager.disconnected_cb = None
 
71
        self.mocker.replay()
 
72
        self.manager.ConnectionLost()
 
73
 
 
74
 
 
75
class TestNetworkManagerState(MockerTestCase):
 
76
    """Test he Network Manager State."""
 
77
 
 
78
    def setUp(self):
 
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)
 
86
 
 
87
    def test_connection_made(self):
 
88
        """Test that the cb is actually called."""
 
89
        self.cb(ONLINE)
 
90
        self.mocker.replay()
 
91
        self.state.connection_made()
 
92
 
 
93
    def test_connection_lost(self):
 
94
        """Test that the cb is actually called."""
 
95
        self.cb(OFFLINE)
 
96
        self.mocker.replay()
 
97
        self.state.connection_lost()
 
98
 
 
99
    def test_find_online_state_not_connected(self):
 
100
        """Test that we do find the online state correctly."""
 
101
        self.is_connected()
 
102
        self.mocker.result(False)
 
103
        self.cb(OFFLINE)
 
104
        self.mocker.result(self.thread)
 
105
        self.thread.start()
 
106
        self.mocker.replay()
 
107
        self.state.find_online_state(listener=self.network_manager,
 
108
                                     listener_thread=self.thread)
 
109
 
 
110
    def test_find_online_state_connected(self):
 
111
        """Test that we do find the online state correctly."""
 
112
        self.is_connected()
 
113
        self.mocker.result(ONLINE)
 
114
        self.cb(ONLINE)
 
115
        self.mocker.result(self.thread)
 
116
        self.thread.start()
 
117
        self.mocker.replay()
 
118
        self.state.find_online_state(listener=self.network_manager,
 
119
                                     listener_thread=self.thread)