def test_process_new_doppler_correction(self): """ Verifies that the process_new_position() callback correctly responds to new doppler correction information. """ # Create a test pipeline test_pipeline = MagicMock() test_pipeline.id = "test_pipeline" test_pipeline.current_session.user_id = "test_user" def mock_parse_command(command_request, **keywords): if command_request["command"] == "set_rx_freq": self.assertEqual(command_request["parameters"]["frequency"], 5) elif command_request["command"] == "set_tx_freq": self.assertEqual(command_request["parameters"]["frequency"], 25) return defer.succeed({"response": {"status": "okay"}}) # Create a test Icom driver test_cp = MagicMock() test_cp.parse_command = mock_parse_command test_device = icom_910.ICOM_910(self.standard_icom_config, test_cp) test_device._session_pipeline = test_pipeline test_device._radio_state["set_rx_freq"] = 20 test_device._radio_state["set_tx_freq"] = 100 # Create a mock target_position and submit it doppler_correction = {"doppler_multiplier": 0.25} test_deferred = test_device.process_new_doppler_correction(doppler_correction) results = yield test_deferred # Verify result self.assertTrue(results) self.assertTrue(test_device._last_doppler_update > 0)
def test_update_state_command_error(self): """ Tests that the _update_state() method of the antenna controller driver responds correctly to an error from the antenna controller device. """ # Create a mock pipeline to test with test_pipeline = MagicMock() test_pipeline.id = "test_pipeline" test_pipeline.current_session.user_id = "test_user" def mock_parse_command(command_request, **keywords): self.assertEqual(command_request['command'], "get_state") self.assertEqual(command_request['destination'], test_pipeline.id+".test_device") self.assertEqual(keywords['user_id'], test_pipeline.current_session.user_id) test_response = { 'response': { 'status': 'error' } } return defer.succeed(test_response) # Create a test device test_cp = MagicMock() test_cp.parse_command = mock_parse_command test_device = mxl_antenna_controller.MXL_Antenna_Controller(self.standard_device_configuration, test_cp) test_device._session_pipeline = test_pipeline # Try updating the state self.assertEqual(test_device._controller_state['timestamp'], None) result = yield test_device._update_state() # Check results self.assertEqual(result, None)
def test_process_new_position(self): """ Verifies that the process_new_position() method correctly responds to new targeting information. """ # Create a test pipeline test_pipeline = MagicMock() test_pipeline.id = "test_pipeline" test_pipeline.current_session.user_id = "test_user" def mock_parse_command(command_request, **keywords): self.assertEqual(command_request['command'], "move") self.assertEqual(command_request['destination'], test_pipeline.id+".test_device") self.assertEqual(command_request['parameters']['azimuth'], 42) self.assertEqual(command_request['parameters']['elevation'], 42) self.assertEqual(keywords['user_id'], test_pipeline.current_session.user_id) return defer.succeed(True) # Create a test device test_cp = MagicMock() test_cp.parse_command = mock_parse_command test_device = mxl_antenna_controller.MXL_Antenna_Controller(self.standard_device_configuration, test_cp) test_device._session_pipeline = test_pipeline # Create a mock target_position and submit it target_position = { "azimuth": 42.1, "elevation": 42.1 } command_deferred = test_device.process_new_position(target_position) return command_deferred
def test_cleanup_after_session(self): """ Tests that the antenna controller takes the correct actions once a session has ended. """ def mock_parse_command(command_request, **keywords): self.assertEqual(command_request['command'], "calibrate_and_park") self.assertEqual(keywords['user_id'], None) self.assertEqual(keywords['kernel_mode'], True) return defer.succeed(True) # Create a driver instance to test with test_pipeline = MagicMock() test_pipeline.id = "test_pipeline" test_cp = MagicMock() test_cp.parse_command = mock_parse_command test_device = mxl_antenna_controller.MXL_Antenna_Controller(self.standard_device_configuration, test_cp) test_device._session_pipeline = test_pipeline # Create a mock 'tracker' service test_pipeline.load_service = MagicMock() # Run prepare_for_session and check results test_deferred = test_device.cleanup_after_session() result = yield test_deferred # Make sure the tracker state was reset self.assertEqual(test_device._current_position, None) self.assertEqual(test_device._tracker_service, None) self.assertEqual(test_device._session_pipeline, None) self.assertEqual(test_device._controller_state['timestamp'], None) self.assertEqual(test_device._controller_state['azimuth'], 0) self.assertEqual(test_device._controller_state['elevation'], 0) self.assertEqual(test_device._controller_state['state'], "inactive")
def test_update_state(self): """ Tests the _update_state() method of the antenna controller driver, which is responsible for periodically querying the antenna controller for its current orientation. """ # Create a mock pipeline to test with test_pipeline = MagicMock() test_pipeline.id = "test_pipeline" test_pipeline.current_session.user_id = "test_user" def mock_parse_command(command_request, **keywords): self.assertEqual(command_request['command'], "get_state") self.assertEqual(command_request['destination'], test_pipeline.id+".test_device") self.assertEqual(keywords['user_id'], test_pipeline.current_session.user_id) test_response = { 'response': { 'status': 'okay', 'azimuth': 42, 'elevation': 42 } } return defer.succeed(test_response) # Create a test device test_cp = MagicMock() test_cp.parse_command = mock_parse_command test_device = mxl_antenna_controller.MXL_Antenna_Controller(self.standard_device_configuration, test_cp) test_device._session_pipeline = test_pipeline # Try updating the state self.assertEqual(test_device._controller_state['timestamp'], None) result = yield test_device._update_state() # Check results self.assertTrue(result['timestamp'] is not None) self.assertEqual(result['azimuth'], 42) self.assertEqual(result['elevation'], 42)
def test_process_new_doppler_correction_error(self): """ Verifies that the ICOM driver can handle any errors that may occur while responding to the doppler correction. """ # Create a test pipeline test_pipeline = MagicMock() test_pipeline.id = "test_pipeline" test_pipeline.current_session.user_id = "test_user" def mock_parse_command(command_request, **keywords): if command_request["command"] == "set_rx_freq": return defer.succeed({"response": {"status": "okay"}}) elif command_request["command"] == "set_tx_freq": return defer.succeed({"response": {"status": "error"}}) # Create a test Icom driver test_cp = MagicMock() test_cp.parse_command = mock_parse_command test_device = icom_910.ICOM_910(self.standard_icom_config, test_cp) test_device._session_pipeline = test_pipeline test_device._radio_state["set_downlink_freq"] = 20 test_device._radio_state["set_uplink_freq"] = 100 # First submit an invalid doppler correction doppler_correction = {"ya_dun_goofed": True} test_deferred = test_device.process_new_doppler_correction(doppler_correction) results = yield test_deferred # Verify results and submit a valid doppler correction self.assertTrue(not results) doppler_correction = {"doppler_multiplier": 0.25} test_deferred = test_device.process_new_doppler_correction(doppler_correction) results = yield test_deferred # Make sure the update failed (due to a failed set_tx_freq command) self.assertTrue(not results) self.assertEqual(test_device._last_doppler_update, 0)