Ejemplo n.º 1
0
def test_execute_single_success_immediate():
    with mock.patch(
            "umapi_client.connection.requests.Session.post") as mock_post:
        mock_post.return_value = MockResponse(200, {"result": "success"})
        conn = Connection(**mock_connection_params)
        action = Action(top="top").append(a="a")
        assert conn.execute_single(action, immediate=True) == (0, 1, 1)
Ejemplo n.º 2
0
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"
        }]
Ejemplo n.º 3
0
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"
        }]
Ejemplo n.º 4
0
def test_execute_single_success_queued():
    with mock.patch(
            "umapi_client.connection.requests.Session.post") as mock_post:
        mock_post.return_value = MockResponse(200, {"result": "success"})
        conn = Connection(throttle_actions=2, **mock_connection_params)
        action = Action(top="top").append(a="a")
        assert conn.execute_single(action) == (1, 0, 0)
        assert conn.execute_single(action) == (0, 2, 2)
Ejemplo n.º 5
0
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_group_size_limit():
    """
    Test with different 'throttle_groups' value, which governs the max size of the group list before commands are split
    :return:
    """
    with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
        mock_post.return_value = MockResponse(200, {"result": "success"})
        params = mock_connection_params
        params['throttle_groups'] = 5
        conn = Connection(**params)

        group_prefix = "G"
        add_groups = [group_prefix+six.text_type(n+1) for n in range(0, 150)]
        user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**")
        user.add_to_groups(groups=add_groups, group_type=GroupTypes.usergroup)
        assert conn.execute_single(user, immediate=True) == (0, 3, 3)
def test_large_group_action_split():
    """
    Ensure that very large group lists (100+) will be handled appropriately
    Connection.execute_multiple splits commands and splits actions
    Result should be 2 actions, even though we only created one action
    :return:
    """
    with mock.patch("umapi_client.connection.requests.Session.post") as mock_post:
        mock_post.return_value = MockResponse(200, {"result": "success"})
        conn = Connection(**mock_connection_params)

        group_prefix = "G"
        add_groups = [group_prefix+six.text_type(n+1) for n in range(0, 150)]
        user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**")
        user.add_to_groups(groups=add_groups, group_type=GroupTypes.usergroup)
        assert conn.execute_single(user, immediate=True) == (0, 2, 2)
Ejemplo n.º 8
0
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"
        }]