def testRfSwitchesNotAvailable(self):
     """Test logs when no RF Switches are available to lock."""
     afe_instance = self.mock_afe()
     afe_instance.get_hosts.return_value = []
     with mock.patch('logging.Logger.debug') as mock_logger:
         rf_switch_utils.allocate_rf_switch()
         mock_logger.assert_called_with(
             'No RF Switches are available for tests.')
 def testRfSwitchCannotBeLocked(self):
     """Test logs when RF Switch cannot be locked."""
     afe_instance = self.mock_afe()
     mock_host_instance = self.mock_host()
     afe_instance.get_hosts.return_value = [mock_host_instance]
     mock_host_instance.hostname = 'chromeos9-rfswitch1'
     afe_instance.lock_host.return_value = False
     with mock.patch('logging.Logger.error') as mock_logger:
         rf_switch_utils.allocate_rf_switch()
         mock_logger.assert_called_with(
             'RF Switch chromeos9-rfswitch1 could not be locked')
 def testAllocateRfSwitch(self):
     """Test to allocate a RF Switch."""
     afe_instance = self.mock_afe()
     mock_host_instance = self.mock_host()
     mock_host_instance.hostname = 'chromeos9-rfswitch1'
     # AFE returns list of RF Switch Hosts.
     afe_instance.get_hosts.return_value = [mock_host_instance]
     # Locking the first available RF Switch Host.
     afe_instance.lock_host.return_value = True
     rf_switch = rf_switch_utils.allocate_rf_switch()
     self.assertEquals(rf_switch, mock_host_instance)
     self.assertEquals(rf_switch.hostname, 'chromeos9-rfswitch1')