Ejemplo n.º 1
0
 def test_mqtt_publish(self, mocker, stage, create_transport):
     cb = mocker.MagicMock()
     op_update_sas_token = pipeline_ops_base.UpdateSasTokenOperation(
         sas_token=fake_sas_token, callback=cb)
     stage.run_op(op_update_sas_token)
     assert_callback_succeeded(op_update_sas_token)
     assert stage.sas_token == fake_sas_token
Ejemplo n.º 2
0
 def test_compltetes_active_disconnect_op_when_no_error(self, stage, create_transport, callback):
     op = pipeline_ops_base.DisconnectOperation(callback=callback)
     callback.reset_mock()
     stage.run_op(op)
     assert callback.call_count == 0
     stage.transport.on_mqtt_disconnected_handler(None)
     assert_callback_succeeded(op=op)
Ejemplo n.º 3
0
 def test_completes_active_reconenct_op(self, stage, create_transport, callback):
     op = pipeline_ops_base.ReconnectOperation(callback=callback)
     callback.reset_mock()
     stage.run_op(op)
     assert callback.call_count == 0
     stage.transport.on_mqtt_connected_handler()
     assert_callback_succeeded(op=op)
Ejemplo n.º 4
0
    def test_complete(self, mocker, stage, create_transport, op_publish):
        # Begin publish
        stage.run_op(op_publish)

        # Trigger publish completion
        stage.transport.publish.call_args[1]["callback"]()

        assert_callback_succeeded(op=op_publish)
 def test_compltetes_pending_disconnect_op_when_no_error(self, mocker, stage, create_transport):
     op = pipeline_ops_base.DisconnectOperation(callback=mocker.MagicMock())
     stage.run_op(op)
     assert op.callback.call_count == 0
     assert stage._pending_connection_op is op
     stage.transport.on_mqtt_disconnected_handler(None)
     assert_callback_succeeded(op=op)
     assert stage._pending_connection_op is None
    def test_next_stage_completes_correctly(self, stage, op):
        def next_stage_run_op(self, op):
            op.status_code = 200
            op.callback(op, error=None)

        stage.next.run_op = functools.partial(next_stage_run_op, (stage.next,))
        stage.run_op(op)
        assert_callback_succeeded(op=op)
    def test_publish_op_returns_success(self, stage, op):
        def next_stage_run_op(self, op):
            op.callback(op)

        stage.next.run_op = functools.partial(next_stage_run_op,
                                              (stage.next, ))
        stage.run_op(op)
        assert_callback_succeeded(op=op)
Ejemplo n.º 8
0
    def test_complete(self, mocker, stage, create_transport, op_unsubscribe):
        # Begin unsubscribe
        stage.run_op(op_unsubscribe)

        # Trigger unsubscribe completion
        stage.transport.unsubscribe.call_args[1]["callback"]()

        assert_callback_succeeded(op=op_unsubscribe)
    def test_ignores_duplicate_request_id(self, stage, op, iot_response,
                                          unhandled_error_handler):
        operation_flow.pass_event_to_previous_stage(stage.next, iot_response)
        assert_callback_succeeded(op=op)
        op.callback.reset_mock()

        operation_flow.pass_event_to_previous_stage(stage.next, iot_response)
        assert op.callback.call_count == 0
        assert unhandled_error_handler.call_count == 0
    def test_operation_complete(self, params, op, stage):
        stage.pipeline_root.connected = False

        stage.run_op(op)
        connect_op = stage.next.run_op.call_args[0][0]
        stage.next._complete_op(connect_op)

        stage.next._complete_op(op)
        assert_callback_succeeded(op=op)
    def test_ignores_duplicate_request_id(self, stage, op, iot_response,
                                          unhandled_error_handler):
        stage.next._send_event_up(iot_response)
        assert_callback_succeeded(op=op)
        op.callback.reset_mock()

        stage.next._send_event_up(iot_response)
        assert op.callback.call_count == 0
        assert unhandled_error_handler.call_count == 0
Ejemplo n.º 12
0
    def test_completes_original_op_after_new_op_completes(self, stage, op, new_op, callback):
        op.callback = callback
        new_op.action = "pend"

        delegate_to_different_op(stage, original_op=op, new_op=new_op)
        assert callback.call_count == 0  # because new_op is pending

        complete_op(stage.next, new_op)
        assert_callback_succeeded(op=op)
    def test_next_stage_completes_correctly(self, stage, op, twin, twin_as_bytes):
        def next_stage_run_op(self, op):
            op.status_code = 200
            op.response_body = twin_as_bytes
            op.callback(op, error=None)

        stage.next.run_op = functools.partial(next_stage_run_op, (stage.next,))
        stage.run_op(op)
        assert_callback_succeeded(op=op)
        assert op.twin == twin
    def test_completes_original_op_after_worker_op_completes(
        self, stage, arbitrary_op, arbitrary_worker_op
    ):
        callback = arbitrary_op.callback

        stage._send_worker_op_down(worker_op=arbitrary_worker_op, op=arbitrary_op)
        assert callback.call_count == 0  # because arbitrary_worker_op is pending

        stage.next._complete_op(arbitrary_worker_op)
        assert_callback_succeeded(op=arbitrary_op)
    def test_completes_original_op_after_new_op_completes(
            self, stage, op, new_op):
        callback = op.callback
        new_op.action = "pend"

        stage._send_worker_op_down(worker_op=new_op, op=op)
        assert callback.call_count == 0  # because new_op is pending

        stage.next._complete_op(new_op)
        assert_callback_succeeded(op=op)
 def test_calls_callback_on_retried_op_success(self, stage, yes_retry_op,
                                               retry_error, mock_timer):
     op_callback = yes_retry_op.callback
     stage.run_op(yes_retry_op)
     stage.next.complete_op(op=yes_retry_op, error=retry_error)
     timer_callback = mock_timer.call_args[0][1]
     timer_callback()
     assert op_callback.call_count == 0
     stage.next.complete_op(op=yes_retry_op)
     assert yes_retry_op.callback == op_callback
     assert_callback_succeeded(op=yes_retry_op)
    def test_immediately_completes_second_op(self, stage, params, mocker):
        first_connection_op = params["first_connection_op"](mocker.MagicMock())
        second_connection_op = params["second_connection_op"](
            mocker.MagicMock())
        stage.pipeline_root.connected = params["pre_connected_flag"]

        stage.run_op(first_connection_op)
        stage.run_op(second_connection_op)

        # first_connection_op has been passed down.  second_connection_op is waiting for first disconnect to complete.
        assert stage.next.run_op.call_count == 1
        assert stage.next.run_op.call_args[0][0] == first_connection_op

        # complete first_connection_op
        stage.pipeline_root.connected = params["mid_connect_flag"]
        stage.next._complete_op(first_connection_op)

        # second connect_op should be completed without having been passed down.
        assert stage.next.run_op.call_count == 1
        assert_callback_succeeded(op=second_connection_op)
 def test_calls_callback_on_success(self, stage, op):
     stage._complete_op(op)
     assert_callback_succeeded(op)
 def test_calls_callback_on_success(self, stage, arbitrary_op):
     stage._complete_op(arbitrary_op)
     assert_callback_succeeded(arbitrary_op)
 def test_calls_callback_on_success(self, stage, op):
     op.completed = True
     stage._send_completed_op_up(op)
     assert_callback_succeeded(op)
 def test_calls_callback_on_success(self, stage, arbitrary_op):
     arbitrary_op.completed = True
     stage._send_completed_op_up(arbitrary_op)
     assert_callback_succeeded(arbitrary_op)
 def test_operation_succeeds(self, params, stage,
                             stages_configured_for_both, op):
     stage.run_op(op)
     assert_callback_succeeded(op)
 def test_set_connection_args_succeeds(self, stage, mocker,
                                       set_auth_provider_args):
     stage.run_op(set_auth_provider_args)
     assert_callback_succeeded(op=set_auth_provider_args)
 def test_returns_success_if_publish_succeeds(self, params, mock_stage,
                                              stages_configured, op):
     mock_stage.run_op(op)
     assert_callback_succeeded(op)
 def test_returns_success_if_set_connection_args_succeeds(
         self, mock_stage, mocker, set_security_client_args):
     mock_stage.run_op(set_security_client_args)
     assert_callback_succeeded(op=set_security_client_args)
 def test_returns_success_if_set_sas_token_or_set_client_certificate_succeeds(
     self, stage, set_auth_provider
 ):
     stage.run_op(set_auth_provider)
     assert_callback_succeeded(op=set_auth_provider)
 def test_completes_op_with_matching_request_id(self, stage, op,
                                                iot_response):
     stage.next._send_event_up(iot_response)
     assert_callback_succeeded(op=op)
     assert op.status_code == iot_response.status_code
     assert op.response_body == iot_response.response_body
 def test_disconnect_while_disconnected(self, stage, mocker):
     op = pipeline_ops_base.DisconnectOperation(callback=mocker.MagicMock())
     stage.pipeline_root.connected = False
     stage.run_op(op)
     assert_callback_succeeded(op=op)
 def test_completes_op_with_matching_request_id(self, stage, op,
                                                iot_response):
     operation_flow.pass_event_to_previous_stage(stage.next, iot_response)
     assert_callback_succeeded(op=op)
     assert op.status_code == iot_response.status_code
     assert op.response_body == iot_response.response_body
Ejemplo n.º 30
0
 def test_succeeds(self, stage, transport, op_set_connection_args):
     stage.run_op(op_set_connection_args)
     assert_callback_succeeded(op=op_set_connection_args)