def event(self, method_name, rid):
     topic = "$iothub/methods/POST/{method_name}/?$rid={rid}".format(
         method_name=method_name, rid=rid
     )
     return pipeline_events_mqtt.IncomingMQTTMessageEvent(
         topic=topic, payload=b'{"some": "json"}'
     )
 def event(self, status, rid, retry_after):
     topic = "$dps/registrations/res/{status}/?$rid={rid}".format(
         status=status, rid=rid)
     if retry_after:
         topic = topic + "&retry-after={}".format(retry_after)
     return pipeline_events_mqtt.IncomingMQTTMessageEvent(
         topic=topic, payload=b"some payload")
 def test_extracts_c2d_message_properties_from_topic_name(
         self, mocker, stage, stage_configured_for_device,
         add_pipeline_root):
     event = pipeline_events_mqtt.IncomingMQTTMessageEvent(
         topic=fake_c2d_topic_with_content_type, payload=fake_mqtt_payload)
     stage.handle_pipeline_event(event)
     new_event = stage.previous.handle_pipeline_event.call_args[0][0]
     assert new_event.message.content_type == fake_content_type
 def event(self, pipeline_config, input_name):
     # topic device id MATCHES THE PIPELINE CONFIG
     topic = "devices/{device_id}/modules/{module_id}/inputs/{input_name}/%24.mid=6b822696-f75a-46f5-8b02-0680db65abf5&%24.to=%2Fdevices%2F{device_id}%2Fmodules%2F{module_id}%2Finputs%2F{input_name}".format(
         device_id=pipeline_config.device_id,
         module_id=pipeline_config.module_id,
         input_name=input_name,
     )
     return pipeline_events_mqtt.IncomingMQTTMessageEvent(topic=topic, payload="some payload")
 def test_if_topic_is_input_message_for_another_module(
         self, mocker, stage, stage_configured_for_module,
         add_pipeline_root, topic):
     event = pipeline_events_mqtt.IncomingMQTTMessageEvent(
         topic=topic, payload=fake_mqtt_payload)
     stage.handle_pipeline_event(event)
     assert stage.previous.handle_pipeline_event.call_count == 1
     assert stage.previous.handle_pipeline_event.call_args == mocker.call(
         event)
 def test_passes_up_mqtt_message_with_unknown_topic(
         self, stage, stages_configured_for_both, add_pipeline_root,
         mocker):
     event = pipeline_events_mqtt.IncomingMQTTMessageEvent(
         topic=unmatched_mqtt_topic, payload=fake_mqtt_payload)
     stage.handle_pipeline_event(event)
     assert stage.previous.handle_pipeline_event.call_count == 1
     assert stage.previous.handle_pipeline_event.call_args == mocker.call(
         event)
 def test_if_topic_is_not_response(self, mocker, stage, stages_configured):
     fake_some_other_topic = "devices/{}/messages/devicebound/".format(
         fake_device_id)
     event = pipeline_events_mqtt.IncomingMQTTMessageEvent(
         topic=fake_some_other_topic, payload=fake_mqtt_payload)
     stage.handle_pipeline_event(event)
     assert stage.previous.handle_pipeline_event.call_count == 1
     assert stage.previous.handle_pipeline_event.call_args == mocker.call(
         event)
 def fake_event(self, fake_topic_name, fake_payload):
     return pipeline_events_mqtt.IncomingMQTTMessageEvent(
         topic=fake_topic_name, payload=fake_payload)
def method_request_event():
    return pipeline_events_mqtt.IncomingMQTTMessageEvent(
        topic=fake_method_request_topic, payload=fake_method_request_payload)
def input_message_event():
    return pipeline_events_mqtt.IncomingMQTTMessageEvent(
        topic=fake_input_message_topic, payload=fake_mqtt_payload)
def c2d_event():
    return pipeline_events_mqtt.IncomingMQTTMessageEvent(
        topic=fake_c2d_topic, payload=fake_mqtt_payload)
def dps_response_event():
    return pipeline_events_mqtt.IncomingMQTTMessageEvent(
        topic=fake_response_topic, payload=fake_mqtt_payload.encode("utf-8"))
 def event(self, status, rid):
     topic = "$iothub/twin/res/{status}/?$rid={rid}".format(status=status,
                                                            rid=rid)
     return pipeline_events_mqtt.IncomingMQTTMessageEvent(
         topic=topic, payload=b"some_payload")
 def event(self, pipeline_config):
     # topic device id MATCHES THE PIPELINE CONFIG
     topic = "devices/{device_id}/messages/devicebound/%24.mid=6b822696-f75a-46f5-8b02-0680db65abf5&%24.to=%2Fdevices%2F{device_id}%2Fmessages%2Fdevicebound".format(
         device_id=pipeline_config.device_id)
     return pipeline_events_mqtt.IncomingMQTTMessageEvent(
         topic=topic, payload="some payload")
 def event(self):
     topic = "not a real topic"
     return pipeline_events_mqtt.IncomingMQTTMessageEvent(
         topic=topic, payload=b"some payload")
 def event(self):
     topic = "$iothub/twin/PATCH/properties/desired/?$version=1"
     # payload will be overwritten in relevant tests
     return pipeline_events_mqtt.IncomingMQTTMessageEvent(
         topic=topic, payload=b'{"some": "payload"}')