• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Tests for rf_switch_client_box."""
2
3import common
4import mock
5import unittest
6
7from autotest_lib.server.cros.network import rf_switch_client_box
8
9
10class RfSwitchClientBoxTest(unittest.TestCase):
11    """Tests for the RfSwitchClientBox."""
12
13
14    def setUp(self):
15        """Initial set up for the tests."""
16        rf_switch_client_box.frontend = mock.MagicMock()
17        self.client_box_host = rf_switch_client_box.frontend.Host('', '')
18        self.client_box_host.hostname = 'chromeos9-clientbox1'
19        self.client_box_host.labels = [
20                'rf_switch_1', 'client_box_1', 'rf_switch_client']
21
22
23    def testGetDevices(self):
24        """Test to get all devices from a Client Box."""
25        rf_switch_client_box.frontend = mock.MagicMock()
26        dut_host = rf_switch_client_box.frontend.Host('', '')
27        dut_host.hostname = 'chromeos9-device1'
28        dut_host.labels = ['rf_switch_1', 'client_box_1', 'rf_switch_dut']
29        # Add a device to the Client Box and verify.
30        afe_instance = rf_switch_client_box.frontend.AFE()
31        afe_instance.get_hosts.return_value = [self.client_box_host, dut_host]
32        client_box = rf_switch_client_box.ClientBox(self.client_box_host)
33        devices = client_box.get_devices()
34        self.assertEqual(len(devices), 1)
35        device = devices[0]
36        self.assertEqual(device, 'chromeos9-device1')
37
38
39    def testNoDevicesInClientbox(self):
40        """Test for no devices in the Client Box."""
41        rf_switch_client_box.frontend = mock.MagicMock()
42        afe_instance =rf_switch_client_box.frontend.AFE()
43        afe_instance.get_hosts.return_value = [self.client_box_host]
44        client_box = rf_switch_client_box.ClientBox(self.client_box_host)
45        devices = client_box.get_devices()
46        self.assertEqual(len(devices), 0)
47
48
49    def testGetOtherDevices(self):
50        """Test to get stumpy from ClientBox if installed."""
51        rf_switch_client_box.frontend = mock.MagicMock()
52        stumpy_host = rf_switch_client_box.frontend.Host('', '')
53        stumpy_host.hostname = 'chromeos9-stumpy1'
54        stumpy_host.labels = ['rf_switch_1', 'client_box_1', 'stumpy']
55        afe_instance = rf_switch_client_box.frontend.AFE()
56        afe_instance.get_hosts.side_effect = [[stumpy_host]]
57        client_box = rf_switch_client_box.ClientBox(self.client_box_host)
58        self.assertEqual(
59                client_box.get_devices_using_labels(stumpy_host.labels),
60                ['chromeos9-stumpy1'])
61
62
63    def testGetOtherDeviceWithWrongLabels(self):
64        """Test to get Devices when using wrong list of labels."""
65        rf_switch_client_box.frontend = mock.MagicMock()
66        stumpy_host = rf_switch_client_box.frontend.Host('', '')
67        stumpy_host.hostname = 'chromeos9-stumpy1'
68        stumpy_host.labels = ['rf_switch_1', 'client_box_1', 'stumpy']
69        list_of_labels = ['rf_switch_1', 'client_box_1', 'packet_capture']
70        afe_instance = rf_switch_client_box.frontend.AFE()
71        afe_instance.get_hosts.side_effect = [[self.client_box_host],
72                                              [stumpy_host]]
73        client_box = rf_switch_client_box.ClientBox(self.client_box_host)
74        self.assertEqual(
75                len(client_box.get_devices_using_labels(list_of_labels)), 0)
76
77
78if __name__ == '__main__':
79    unittest.main()
80
81