Exemplo n.º 1
0
 def test_does_not_call_second_or_third_op_if_first_op_fails(
     self, mocker, stage, op, op2, op3, callback
 ):
     op.action = "fail"
     run_ops_in_serial(stage, op, op2, op3, callback=callback)
     assert stage.next._run_op.call_count == 1
     assert stage.next._run_op.call_args == mocker.call(op)
Exemplo n.º 2
0
 def test_callback_raises_exception(
     self, stage, op, op2, op3, finally_op, fake_exception, mocker, unhandled_error_handler
 ):
     callback = mocker.Mock(side_effect=fake_exception)
     run_ops_in_serial(stage, op, op2, op3, callback=callback, finally_op=finally_op)
     assert unhandled_error_handler.call_count == 1
     assert unhandled_error_handler.call_args == mocker.call(fake_exception)
Exemplo n.º 3
0
 def test_runs_finally_op_if_third_op_fails(
     self, mocker, stage, op, op2, op3, finally_op, callback
 ):
     op3.action = "fail"
     run_ops_in_serial(stage, op, op2, op3, callback=callback, finally_op=finally_op)
     assert stage.next._run_op.call_count == 4
     assert stage.next._run_op.call_args_list[3] == mocker.call(finally_op)
Exemplo n.º 4
0
 def test_calls_callback_with_error_if_third_op_and_finally_op_both_fail(
     self, stage, op, op2, op3, finally_op, callback
 ):
     op3.action = "fail"
     finally_op.action = "fail"
     run_ops_in_serial(stage, op, op2, op3, callback=callback, finally_op=finally_op)
     assert_callback_failed(callback=callback, op=finally_op, error=op3.error)
Exemplo n.º 5
0
 def test_calls_callbacK_with_error_when_first_op_and_finally_op_both_fail(
     self, stage, op, op2, op3, finally_op, callback
 ):
     op.action = "fail"
     finally_op.action = "fail"
     run_ops_in_serial(stage, op, op2, op3, finally_op=finally_op, callback=callback)
     assert_callback_failed(callback=callback, op=finally_op, error=finally_op.error)
Exemplo n.º 6
0
 def test_runs_second_op(self, mocker, stage, op, op2, op3, finally_op, callback):
     op.action = "pend"
     op2.action = "pend"
     run_ops_in_serial(stage, op, op2, op3, callback=callback, finally_op=finally_op)
     assert stage.next._run_op.call_count == 1
     assert stage.next._run_op.call_args == mocker.call(op)
     complete_op(stage.next, op)
     assert stage.next._run_op.call_args_list[1] == mocker.call(op2)
Exemplo n.º 7
0
 def test_calls_third_op_after_second_op_succeeds(self, mocker, stage, op, op2, op3, callback):
     op2.action = "pend"
     run_ops_in_serial(stage, op, op2, op3, callback=callback)
     assert stage.next._run_op.call_count == 2
     assert stage.next._run_op.call_args_list[0] == mocker.call(op)
     assert stage.next._run_op.call_args_list[1] == mocker.call(op2)
     complete_op(stage.next, op2)
     assert stage.next._run_op.call_count == 3
     assert stage.next._run_op.call_args_list[2] == mocker.call(op3)
Exemplo n.º 8
0
 def test_runs_second_op_after_first_op_succceeds(self, mocker, stage, op, op2, op3, callback):
     op.action = "pend"
     op2.action = "pend"
     run_ops_in_serial(stage, op, op2, op3, callback=callback)
     assert stage.next._run_op.call_count == 1
     assert stage.next._run_op.call_args == mocker.call(op)
     complete_op(stage.next, op)
     assert stage.next._run_op.call_count == 2
     assert stage.next._run_op.call_args_list[1] == mocker.call(op2)
Exemplo n.º 9
0
 def test_callback_throws_exception(
     self, stage, mocker, fake_exception, op, unhandled_error_handler
 ):
     callback = mocker.Mock(side_effect=fake_exception)
     run_ops_in_serial(stage, op, callback=callback)
     assert callback.call_count == 1
     assert callback.call_args == mocker.call(op)
     assert unhandled_error_handler.call_count == 1
     assert unhandled_error_handler.call_args == mocker.call(fake_exception)
Exemplo n.º 10
0
 def test_runs_finally_op_when_second_op_fails(
     self, mocker, stage, op, op2, op3, finally_op, callback
 ):
     op2.action = "fail"
     run_ops_in_serial(stage, op, op2, op3, callback=callback, finally_op=finally_op)
     assert stage.next._run_op.call_count == 3
     assert stage.next._run_op.call_args_list[0] == mocker.call(op)
     assert stage.next._run_op.call_args_list[1] == mocker.call(op2)
     assert stage.next._run_op.call_args_list[2] == mocker.call(finally_op)
Exemplo n.º 11
0
    def _run_op(self, op):
        def pipeline_ops_done(completed_op):
            op.error = completed_op.error
            op.callback(op)

        if isinstance(op, pipeline_ops_iothub.SetAuthProviderOperation):
            auth_provider = op.auth_provider
            operation_flow.run_ops_in_serial(
                self,
                pipeline_ops_iothub.SetAuthProviderArgsOperation(
                    device_id=auth_provider.device_id,
                    module_id=getattr(auth_provider, "module_id", None),
                    hostname=auth_provider.hostname,
                    gateway_hostname=getattr(auth_provider, "gateway_hostname", None),
                    ca_cert=getattr(auth_provider, "ca_cert", None),
                ),
                pipeline_ops_base.SetSasTokenOperation(
                    sas_token=auth_provider.get_current_sas_token()
                ),
                callback=pipeline_ops_done,
            )
        elif isinstance(op, pipeline_ops_iothub.SetX509AuthProviderOperation):
            auth_provider = op.auth_provider
            operation_flow.run_ops_in_serial(
                self,
                pipeline_ops_iothub.SetAuthProviderArgsOperation(
                    device_id=auth_provider.device_id,
                    module_id=getattr(auth_provider, "module_id", None),
                    hostname=auth_provider.hostname,
                    gateway_hostname=getattr(auth_provider, "gateway_hostname", None),
                    ca_cert=getattr(auth_provider, "ca_cert", None),
                ),
                pipeline_ops_base.SetClientAuthenticationCertificateOperation(
                    certificate=auth_provider.get_x509_certificate()
                ),
                callback=pipeline_ops_done,
            )
        else:
            operation_flow.pass_op_to_next_stage(self, op)
Exemplo n.º 12
0
    def _run_op(self, op):
        def pipeline_ops_done(completed_op):
            op.error = completed_op.error
            op.callback(op)

        if isinstance(
                op, pipeline_ops_provisioning.
                SetSymmetricKeySecurityClientOperation):

            security_client = op.security_client
            operation_flow.run_ops_in_serial(
                self,
                pipeline_ops_provisioning.SetSecurityClientArgsOperation(
                    provisioning_host=security_client.provisioning_host,
                    registration_id=security_client.registration_id,
                    id_scope=security_client.id_scope,
                ),
                pipeline_ops_base.SetSasTokenOperation(
                    sas_token=security_client.get_current_sas_token()),
                callback=pipeline_ops_done,
            )
        elif isinstance(
                op, pipeline_ops_provisioning.SetX509SecurityClientOperation):
            security_client = op.security_client
            operation_flow.run_ops_in_serial(
                self,
                pipeline_ops_provisioning.SetSecurityClientArgsOperation(
                    provisioning_host=security_client.provisioning_host,
                    registration_id=security_client.registration_id,
                    id_scope=security_client.id_scope,
                ),
                pipeline_ops_base.SetClientAuthenticationCertificateOperation(
                    certificate=security_client.get_x509_certificate()),
                callback=pipeline_ops_done,
            )

        else:
            operation_flow.pass_op_to_next_stage(self, op)
Exemplo n.º 13
0
 def test_callback_with_success_if_op_and_finally_op_succeed(
     self, stage, callback, op, finally_op
 ):
     run_ops_in_serial(stage, op, finally_op=finally_op, callback=callback)
     assert_callback_succeeded(callback=callback, op=finally_op)
Exemplo n.º 14
0
 def test_successful_operation(self, stage, callback, op):
     run_ops_in_serial(stage, op, callback=callback)
     assert_callback_succeeded(op=op, callback=callback)
Exemplo n.º 15
0
 def test_failed_operation(self, stage, callback, op):
     op.action = "fail"
     run_ops_in_serial(stage, op, callback=callback)
     assert_callback_failed(op=op, callback=callback)
Exemplo n.º 16
0
 def test_throws_on_missing_callback(self, stage, op, op2):
     with pytest.raises(TypeError):
         run_ops_in_serial(stage, op, op2)
Exemplo n.º 17
0
 def test_runs_operation(self, mocker, stage, callback, op):
     run_ops_in_serial(stage, op, callback=callback)
     assert stage.next._run_op.call_count == 1
     assert stage.next._run_op.call_args == mocker.call(op)
Exemplo n.º 18
0
 def test_callback_raises_base_exception(
     self, stage, op, op2, op3, finally_op, fake_base_exception, mocker
 ):
     callback = mocker.Mock(side_effect=fake_base_exception)
     with pytest.raises(UnhandledException):
         run_ops_in_serial(stage, op, op2, op3, callback=callback, finally_op=finally_op)
Exemplo n.º 19
0
 def test_throws_for_unknown_keyword_args(self, stage, op, op2, op3, callback):
     with pytest.raises(TypeError):
         run_ops_in_serial(stage, op, op2, callback=callback, unknown_arg=op3)
Exemplo n.º 20
0
 def test_does_not_run_third_op_if_second_op_fails(self, mocker, stage, op, op2, op3, callback):
     op2.action = "fail"
     run_ops_in_serial(stage, op, op2, op3, callback=callback)
     assert stage.next._run_op.call_count == 2
     assert stage.next._run_op.call_args_list[0] == mocker.call(op)
     assert stage.next._run_op.call_args_list[1] == mocker.call(op2)
Exemplo n.º 21
0
 def test_accepts_default_args(self, stage, op, op2, callback):
     run_ops_in_serial(stage, op, op2, callback=callback)
Exemplo n.º 22
0
 def test_calls_callback_with_third_op_succeeds(self, stage, op, op2, op3, callback):
     run_ops_in_serial(stage, op, op2, op3, callback=callback)
     assert_callback_succeeded(callback=callback, op=op3)
Exemplo n.º 23
0
 def test_calls_callback_with_no_error_if_third_op_and_finally_op_both_succeed(
     self, stage, op, op2, op3, finally_op, callback
 ):
     run_ops_in_serial(stage, op, op2, op3, callback=callback, finally_op=finally_op)
     assert_callback_succeeded(callback=callback, op=finally_op)
Exemplo n.º 24
0
 def test_calls_callback_with_error_when_second_op_fails_and_finally_op_succeeds(
     self, stage, op, op2, op3, finally_op, callback
 ):
     op2.action = "fail"
     run_ops_in_serial(stage, op, op2, op3, finally_op=finally_op, callback=callback)
     assert_callback_failed(callback=callback, op=finally_op, error=op.error)
Exemplo n.º 25
0
 def test_runs_finally_op_on_op_failure(self, mocker, stage, callback, op, finally_op):
     op.action = "fail"
     run_ops_in_serial(stage, op, finally_op=finally_op, callback=callback)
     assert stage.next._run_op.call_args_list[1] == mocker.call(finally_op)
Exemplo n.º 26
0
 def test_calls_callback_when_third_op_fails(self, stage, op, op2, op3, callback):
     op3.action = "fail"
     run_ops_in_serial(stage, op, op2, op3, callback=callback)
     assert_callback_failed(callback=callback, op=op3)
Exemplo n.º 27
0
 def test_calls_callback_with_error_if_op_succeeds_and_finally_op_fails(
     self, stage, callback, op, finally_op
 ):
     finally_op.action = "fail"
     run_ops_in_serial(stage, op, finally_op=finally_op, callback=callback)
     assert_callback_failed(callback=callback, op=finally_op, error=finally_op.error)
Exemplo n.º 28
0
 def test_accepts_finally_op(self, stage, op, op2, finally_op, callback):
     run_ops_in_serial(stage, op, op2, callback=callback, finally_op=finally_op)
Exemplo n.º 29
0
 def test_runs_finally_op_on_success(self, mocker, stage, callback, op, finally_op):
     run_ops_in_serial(stage, op, finally_op=finally_op, callback=callback)
     assert stage.next._run_op.call_args_list[1] == mocker.call(finally_op)
Exemplo n.º 30
0
 def test_runs_first_op(self, mocker, stage, op, op2, op3, finally_op, callback):
     op.action = "pend"
     run_ops_in_serial(stage, op, op2, op3, finally_op=finally_op, callback=callback)
     assert stage.next._run_op.call_count == 1
     assert stage.next._run_op.call_args == mocker.call(op)