def test_execute_multiple_dofirst_error(): with mock.patch( "umapi_client.connection.requests.Session.post") as mock_post: mock_post.return_value = MockResponse( 200, { "result": "error", "completed": 1, "notCompleted": 1, "errors": [{ "index": 1, "step": 1, "errorCode": "test.error", "message": "Test error message" }] }) conn = Connection(**mock_connection_params) action0 = Action(top="top0").append(a="a0") action1 = Action(top="top1").append(a="a1").insert(b="b") assert conn.execute_multiple([action0, action1]) == (0, 2, 1) assert action0.execution_errors() == [] assert action1.execution_errors() == [{ "command": { "a": "a1" }, "target": { "top": "top1" }, "errorCode": "test.error", "message": "Test error message" }]
def test_execute_multiple_single_queued_throttle_actions(): with mock.patch( "umapi_client.connection.requests.Session.post") as mock_post: mock_post.side_effect = [ MockResponse(200, {"result": "success"}), MockResponse( 200, { "result": "partial", "completed": 1, "notCompleted": 1, "errors": [{ "index": 0, "step": 0, "errorCode": "test" }] }) ] conn = Connection(throttle_actions=2, **mock_connection_params) action0 = Action(top="top0").append(a="a0") action1 = Action(top="top1").append(a="a1") action2 = Action(top="top2").append(a="a2") action3 = Action(top="top3").append(a="a3") assert conn.execute_multiple([action0, action1, action2], immediate=False) == (1, 2, 2) local_status, server_status = conn.status(remote=False) assert server_status == { "status": "Never contacted", "endpoint": conn.endpoint } assert local_status == { "multiple-query-count": 0, "single-query-count": 0, "actions-sent": 2, "actions-completed": 2, "actions-queued": 1 } assert conn.execute_single(action3) == (0, 2, 1) local_status, _ = conn.status(remote=False) assert local_status == { "multiple-query-count": 0, "single-query-count": 0, "actions-sent": 4, "actions-completed": 3, "actions-queued": 0 } assert action0.execution_errors() == [] assert action1.execution_errors() == [] assert action2.execution_errors() == [{ "command": { "a": "a2" }, "target": { "top": "top2" }, "errorCode": "test" }] assert action3.execution_errors() == []
def test_execute_single_dofirst_error_immediate(): with mock.patch( "umapi_client.connection.requests.Session.post") as mock_post: mock_post.return_value = MockResponse( 200, { "result": "error", "errors": [{ "index": 0, "step": 0, "errorCode": "test.error", "message": "Test error message" }] }) conn = Connection(**mock_connection_params) action = Action(top="top").insert(a="a") assert conn.execute_single(action, immediate=True) == (0, 1, 0) assert action.execution_errors() == [{ "command": { "a": "a" }, "target": { "top": "top" }, "errorCode": "test.error", "message": "Test error message" }]
def test_execute_single_error_immediate_throttled(): with mock.patch( "umapi_client.connection.requests.Session.post") as mock_post: mock_post.return_value = MockResponse( 200, { "result": "partial", "completed": 1, "notCompleted": 1, "errors": [{ "index": 1, "step": 0, "errorCode": "test" }] }) conn = Connection(throttle_commands=2, **mock_connection_params) action = Action(top="top0").append(a="a0").append(a="a1").append( a="a2") assert conn.execute_single(action, immediate=True) == (0, 2, 1) assert action.execution_errors() == [{ "command": { "a": "a2" }, "target": { "top": "top0" }, "errorCode": "test" }]
def test_execute_single_error_queued_throttled(): with mock.patch( "umapi_client.connection.requests.Session.post") as mock_post: mock_post.side_effect = [ MockResponse(200, {"result": "success"}), MockResponse( 200, { "result": "partial", "completed": 1, "notCompleted": 1, "errors": [{ "index": 1, "step": 0, "errorCode": "test.error", "message": "Test error message" }] }) ] conn = Connection(throttle_actions=2, throttle_commands=1, **mock_connection_params) action = Action(top="top").append(a="a").append(b="b").append( c="c").append(d="d") assert conn.execute_single(action) == (0, 4, 3) assert action.execution_errors() == [{ "command": { "d": "d" }, "target": { "top": "top" }, "errorCode": "test.error", "message": "Test error message" }]