def test_split_remove_all():
    """
    Don't split groups if "remove" is "all" instead of list
    :return:
    """
    group_prefix = "G"
    add_groups = [group_prefix+six.text_type(n+1) for n in range(0, 11)]
    user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**")
    user.remove_from_groups(all_groups=True)
    assert user.maybe_split_groups(1) is False
    assert user.wire_dict() == {'do': [{'remove': 'all'}], 'user': '******'}
    user.add_to_groups(groups=add_groups)
    assert user.maybe_split_groups(10) is True
    assert user.wire_dict() == {'do': [{'remove': 'all'},
                                       {'add': {'product': ['G1',
                                                            'G2',
                                                            'G3',
                                                            'G4',
                                                            'G5',
                                                            'G6',
                                                            'G7',
                                                            'G8',
                                                            'G9',
                                                            'G10']}},
                                       {'add': {'product': ['G11']}}],
                                'user': '******'}
Beispiel #2
0
def test_large_group_mix_split():
    """
    Ensure that group split works on add and remove
    Each "add" and "remove" group should be split into 2 groups each
    :return:
    """
    group_prefix = "G"
    add_groups = [group_prefix + six.text_type(n + 1) for n in range(0, 15)]
    remove_groups = [
        group_prefix + six.text_type(n + 1) for n in range(15, 30)
    ]
    user = UserAction(id_type=IdentityTypes.enterpriseID,
                      email="*****@*****.**")
    user.add_to_groups(groups=add_groups, group_type=GroupTypes.usergroup) \
        .remove_from_groups(groups=remove_groups, group_type=GroupTypes.usergroup)
    assert user.maybe_split_groups(10) is True
    assert len(user.commands) == 4
    assert user.commands[0]["add"][
        GroupTypes.usergroup.name] == add_groups[0:10]
    assert user.commands[1]["add"][
        GroupTypes.usergroup.name] == add_groups[10:]
    assert user.commands[2]["remove"][
        GroupTypes.usergroup.name] == remove_groups[0:10]
    assert user.commands[3]["remove"][
        GroupTypes.usergroup.name] == remove_groups[10:]
Beispiel #3
0
def test_add_to_groups_federatedid_all():
    user = UserAction(id_type=IdentityTypes.federatedID,
                      email="*****@*****.**")
    user.add_to_groups(all_groups=True)
    assert user.wire_dict() == {
        "do": [{
            "add": "all"
        }],
        "user": "******"
    }
def test_no_group_split():
    """
    maybe_split should return false if nothing was split
    :return:
    """
    group_prefix = "G"
    add_groups = [group_prefix+six.text_type(n+1) for n in range(0, 5)]
    user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**")
    user.add_to_groups(groups=add_groups, group_type=GroupTypes.usergroup)
    assert user.maybe_split_groups(10) is False
    assert len(user.commands) == 1
def test_large_group_assignment_split_recursive():
    """
    Test group list large enough to trigger recursive split
    :return:
    """
    group_prefix = "G"
    add_groups = [group_prefix+six.text_type(n+1) for n in range(0, 100)]
    user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**")
    user.add_to_groups(groups=add_groups, group_type=GroupTypes.usergroup)
    assert user.maybe_split_groups(10) is True
    assert len(user.commands) == 10
Beispiel #6
0
def test_add_products_federatedid_unicode():
    user = UserAction(id_type=IdentityTypes.federatedID,
                      email="*****@*****.**")
    user.add_to_groups(groups=["Photoshop", u"Người vẽ minh hoạ"])
    assert user.wire_dict() == {
        "do": [{
            "add": {
                "group": ["Photoshop", u"Người vẽ minh hoạ"]
            }
        }],
        "user": "******"
    }
Beispiel #7
0
def test_add_org_federatedid():
    user = UserAction(id_type=IdentityTypes.federatedID,
                      email="*****@*****.**")
    user.add_to_groups()
    assert user.wire_dict() == {
        "do": [{
            "add": {
                "group": []
            }
        }],
        "user": "******"
    }
def test_add_products_federatedid():
    user = UserAction(id_type=IdentityTypes.federatedID,
                      email="*****@*****.**")
    user.add_to_groups(groups=["Photoshop", "Illustrator"])
    assert user.wire_dict() == {
        "do": [{
            "add": {
                "product": ["Photoshop", "Illustrator"]
            }
        }],
        "user": "******"
    }
def test_large_group_assignment_split():
    """
    Ensure that large group list can be split into multiple commands
    :return:
    """
    group_prefix = "G"
    add_groups = [group_prefix+six.text_type(n+1) for n in range(0, 15)]
    user = UserAction(id_type=IdentityTypes.enterpriseID, email="*****@*****.**")
    user.add_to_groups(groups=add_groups, group_type=GroupTypes.usergroup)
    assert user.maybe_split_groups(10) is True
    assert len(user.commands) == 2
    assert user.commands[0]["add"][GroupTypes.usergroup.name] == add_groups[0:10]
    assert user.commands[1]["add"][GroupTypes.usergroup.name] == add_groups[10:]
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)
def test_add_to_groups_federatedid_all_error():
    user = UserAction(id_type="federatedID", email="*****@*****.**")
    with pytest.raises(ValueError):
        user.add_to_groups(all_groups=True, groups=["Photoshop"])