def test_sas_auth(self, mocker, device_connection_string, pipeline_configuration):
     mocker.spy(pipeline_stages_base.PipelineRootStage, "run_op")
     auth_provider = SymmetricKeyAuthenticationProvider.parse(device_connection_string)
     pipeline = IoTHubPipeline(auth_provider, pipeline_configuration)
     op = pipeline._pipeline.run_op.call_args[0][1]
     assert pipeline._pipeline.run_op.call_count == 1
     assert isinstance(op, pipeline_ops_iothub.SetAuthProviderOperation)
     assert op.auth_provider is auth_provider
    def test_sas_auth_op_fail(self, mocker, device_connection_string):
        mocker.patch.object(pipeline_stages_base, "PipelineRootStage")
        auth_provider = SymmetricKeyAuthenticationProvider.parse(device_connection_string)
        pipeline = IoTHubPipeline(auth_provider)
        op = pipeline._pipeline.run_op.call_args[0][0]
        op.error = Exception()

        with pytest.raises(Exception):
            op.callback(op)
    def test_sas_auth_op_fail(self, mocker, device_connection_string, fake_exception):
        old_execute_op = pipeline_stages_base.PipelineRootStage._execute_op

        def fail_set_auth_provider(self, op):
            if isinstance(op, pipeline_stages_base.SetAuthProviderOperation):
                op.error = fake_exception
                operation_flow.complete_op(stage=self, op=op)
            else:
                old_execute_op(self, op)

        mocker.patch.object(
            pipeline_stages_base.PipelineRootStage,
            "_execute_op",
            side_effect=fail_set_auth_provider,
        )

        auth_provider = SymmetricKeyAuthenticationProvider.parse(device_connection_string)
        with pytest.raises(fake_exception.__class__):
            IoTHubPipeline(auth_provider)
示例#4
0
    def test_sas_auth_op_fail(self, mocker, device_connection_string,
                              arbitrary_exception, pipeline_configuration):
        old_execute_op = pipeline_stages_base.PipelineRootStage._execute_op

        def fail_set_auth_provider(self, op):
            if isinstance(op, pipeline_ops_iothub.SetAuthProviderOperation):
                self._complete_op(op, error=arbitrary_exception)
            else:
                old_execute_op(self, op)

        mocker.patch.object(
            pipeline_stages_base.PipelineRootStage,
            "_execute_op",
            side_effect=fail_set_auth_provider,
            autospec=True,
        )

        auth_provider = SymmetricKeyAuthenticationProvider.parse(
            device_connection_string)
        with pytest.raises(arbitrary_exception.__class__):
            IoTHubPipeline(auth_provider, pipeline_configuration)