• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Tests for rf_switch_client_box."""
2
3import mock
4import unittest
5
6from autotest_lib.server import frontend
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        self.patcher = mock.patch('autotest_lib.server.frontend.Host')
17        self.client_box_host = self.patcher.start()
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 tearDown(self):
24        """End patchers."""
25        self.patcher.stop()
26
27
28    @mock.patch('autotest_lib.server.frontend.AFE')
29    @mock.patch('autotest_lib.server.frontend.Host')
30    def testGetDevices(self, mock_host, mock_afe):
31        """Test to get all devices from a Client Box."""
32        dut_host = mock_host()
33        dut_host.hostname = 'chromeos9-device1'
34        dut_host.labels =  ['rf_switch_1', 'client_box_1', 'rf_switch_dut']
35        # Add a device to the Client Box and verify.
36        afe_instance = mock_afe()
37        afe_instance.get_hosts.return_value = [self.client_box_host, dut_host]
38        client_box = rf_switch_client_box.ClientBox(self.client_box_host)
39        devices = client_box.get_devices()
40        self.assertEquals(len(devices), 1)
41        device = devices[0]
42        self.assertEquals(device.hostname, 'chromeos9-device1')
43
44
45    @mock.patch('autotest_lib.server.frontend.AFE')
46    def testNoDevicesInClientbox(self, mock_afe):
47        """Test for no devices in the Client Box."""
48        afe_instance = mock_afe()
49        afe_instance.get_hosts.return_value = [self.client_box_host]
50        client_box = rf_switch_client_box.ClientBox(self.client_box_host)
51        devices = client_box.get_devices()
52        self.assertEquals(len(devices), 0)
53
54
55
56if __name__ == '__main__':
57  unittest.main()
58