def test_pipeline_configuration(self, pipeline_configuration): pipeline = MQTTPipeline(pipeline_configuration) curr_stage = pipeline._pipeline expected_stage_order = [ pipeline_stages_base.PipelineRootStage, pipeline_stages_base.SasTokenStage, pipeline_stages_provisioning.RegistrationStage, pipeline_stages_provisioning.PollingStatusStage, pipeline_stages_base.CoordinateRequestAndResponseStage, pipeline_stages_provisioning_mqtt.ProvisioningMQTTTranslationStage, pipeline_stages_base.AutoConnectStage, pipeline_stages_base.ReconnectStage, pipeline_stages_base.ConnectionLockStage, pipeline_stages_base.RetryStage, pipeline_stages_base.OpTimeoutStage, pipeline_stages_mqtt.MQTTTransportStage, ] # Assert that all PipelineStages are there, and they are in the right order for i in range(len(expected_stage_order)): expected_stage = expected_stage_order[i] assert isinstance(curr_stage, expected_stage) curr_stage = curr_stage.next # Assert there are no more additional stages assert curr_stage is None
def test_running(self, mocker, pipeline_configuration): # Because this is an init test, there isn't really a way to check that it only occurs after # the op. The reason is because this is the object's init, the object doesn't actually # exist until the entire method has completed, so there's no reference you can check prior # to method completion. pipeline = MQTTPipeline(pipeline_configuration) assert pipeline._running
def test_init_pipeline(self, mocker, pipeline_configuration): mocker.spy(pipeline_stages_base.PipelineRootStage, "run_op") pipeline = MQTTPipeline(pipeline_configuration) op = pipeline._pipeline.run_op.call_args[0][1] assert pipeline._pipeline.run_op.call_count == 1 assert isinstance(op, pipeline_ops_base.InitializePipelineOperation)
def test_init_pipeline_failure(self, mocker, arbitrary_exception, pipeline_configuration): old_run_op = pipeline_stages_base.PipelineRootStage._run_op def fail_set_security_client(self, op): if isinstance(op, pipeline_ops_base.InitializePipelineOperation): op.complete(error=arbitrary_exception) else: old_run_op(self, op) mocker.patch.object( pipeline_stages_base.PipelineRootStage, "_run_op", side_effect=fail_set_security_client, autospec=True, ) with pytest.raises(arbitrary_exception.__class__) as e_info: MQTTPipeline(pipeline_configuration) assert e_info.value is arbitrary_exception
def test_handlers_configured(self, pipeline_configuration): pipeline = MQTTPipeline(pipeline_configuration) assert pipeline._pipeline.on_pipeline_event_handler is not None assert pipeline._pipeline.on_connected_handler is not None assert pipeline._pipeline.on_disconnected_handler is not None
def test_handlers_set_to_none(self, pipeline_configuration): pipeline = MQTTPipeline(pipeline_configuration) assert pipeline.on_connected is None assert pipeline.on_disconnected is None assert pipeline.on_message_received is None
def test_features_disabled(self, pipeline_configuration): pipeline = MQTTPipeline(pipeline_configuration) assert not pipeline.responses_enabled[feature]
def test_features(self, pipeline_configuration): pipeline = MQTTPipeline(pipeline_configuration) pipeline.responses_enabled[feature]
def pipeline(mocker, pipeline_configuration): pipeline = MQTTPipeline(pipeline_configuration) mocker.patch.object(pipeline._pipeline, "run_op") return pipeline
def test_pipeline_nucleus(self, pipeline_configuration): pipeline = MQTTPipeline(pipeline_configuration) assert isinstance(pipeline._nucleus, pipeline_nucleus.PipelineNucleus) assert pipeline._nucleus.pipeline_configuration is pipeline_configuration