def test_ignores_request_id_from_failure(self, stage, op, mocker, unhandled_error_handler): stage.next._execute_op = mocker.MagicMock(side_effect=Exception) stage.run_op(op) req = stage.next.run_op.call_args[0][0] resp = pipeline_events_base.IotResponseEvent( request_id=req.request_id, status_code=fake_status_code, response_body=fake_response_body, ) op.callback.reset_mock() operation_flow.pass_event_to_previous_stage(stage.next, resp) assert op.callback.call_count == 0 assert unhandled_error_handler.call_count == 0
def _handle_pipeline_event(self, event): """ Pipeline Event handler function to convert incoming MQTT messages into the appropriate IoTHub events, based on the topic of the message """ if isinstance(event, pipeline_events_mqtt.IncomingMQTTMessageEvent): topic = event.topic if mqtt_topic_iothub.is_c2d_topic(topic, self.device_id): message = Message(event.payload) mqtt_topic_iothub.extract_properties_from_topic(topic, message) self.send_event_up( pipeline_events_iothub.C2DMessageEvent(message)) elif mqtt_topic_iothub.is_input_topic(topic, self.device_id, self.module_id): message = Message(event.payload) mqtt_topic_iothub.extract_properties_from_topic(topic, message) input_name = mqtt_topic_iothub.get_input_name_from_topic(topic) self.send_event_up( pipeline_events_iothub.InputMessageEvent( input_name, message)) elif mqtt_topic_iothub.is_method_topic(topic): request_id = mqtt_topic_iothub.get_method_request_id_from_topic( topic) method_name = mqtt_topic_iothub.get_method_name_from_topic( topic) method_received = MethodRequest( request_id=request_id, name=method_name, payload=json.loads(event.payload.decode("utf-8")), ) self.send_event_up( pipeline_events_iothub.MethodRequestEvent(method_received)) elif mqtt_topic_iothub.is_twin_response_topic(topic): request_id = mqtt_topic_iothub.get_twin_request_id_from_topic( topic) status_code = int( mqtt_topic_iothub.get_twin_status_code_from_topic(topic)) self.send_event_up( pipeline_events_base.IotResponseEvent( request_id=request_id, status_code=status_code, response_body=event.payload)) elif mqtt_topic_iothub.is_twin_desired_property_patch_topic(topic): self.send_event_up( pipeline_events_iothub.TwinDesiredPropertiesPatchEvent( patch=json.loads(event.payload.decode("utf-8")))) else: logger.debug( "Uunknown topic: {} passing up to next handler".format( topic)) self.send_event_up(event) else: # all other messages get passed up self.send_event_up(event)
def iot_response(self, stage, iot_request): return pipeline_events_base.IotResponseEvent( request_id=iot_request.request_id, status_code=fake_status_code, response_body=fake_response_body, )