コード例 #1
0
        def describe_commandline():
            group_api = GroupApi(client)
            group_api.delete = MagicMock()

            def it_calls_the_api(mocker):  # noqa: F811
                mocker.patch('ldap_tools.group.API.delete', return_value=None)
                mocker.patch('ldap_tools.client.Client.prepare_connection',
                             return_value=None)

                # We have to force here, otherwise, we get stuck
                # on an interactive prompt
                runner.invoke(GroupCli.group,
                              ['delete', '--group', group_name, '--force'])

                ldap_tools.group.API.delete.assert_called_once_with(group_name)

            def it_exits_on_no_force_no_confirm(mocker):  # noqa: F811
                mocker.patch('ldap_tools.group.API.delete', return_value=None)
                mocker.patch('ldap_tools.client.Client.prepare_connection',
                             return_value=None)
                mocker.patch('click.confirm', return_value=False)

                # We have to force here, otherwise, we get stuck
                # on an interactive prompt
                result = runner.invoke(GroupCli.group,
                                       ['delete', '--group', group_name])
                assert result.output == "Deletion of {} aborted\n".format(
                    group_name)
コード例 #2
0
            def it_raises_exception_on_no_groups_found():
                client.search = MagicMock()
                group_api = GroupApi(client)

                with pytest.raises(ldap_tools.exceptions.NoGroupsFound,
                                   message=("No Groups Returned by LDAP.")):
                    group_api.lookup_id(group_name)
コード例 #3
0
            def it_calls_the_client():
                client.delete = MagicMock()

                group_api = GroupApi(client)

                group_api.delete(group_name)
                client.delete.assert_called_once_with(
                    'cn={},ou=Group,{}'.format(group_name, client.basedn))
コード例 #4
0
            def it_calls_the_client():
                client.search = MagicMock()
                # client.prepare_connection = MagicMock()
                # client.load_ldap_config = MagicMock()

                group_api = GroupApi(client)

                group_api.index()
                client.search.assert_called_once_with(group_objectclass)
コード例 #5
0
            def it_raises_exception_on_multiple_results():
                client.search = MagicMock(return_value=['foo', 'bar'])
                group_api = GroupApi(client)

                with pytest.raises(
                        ldap_tools.exceptions.TooManyResults,
                        message=(
                            "Multiple groups found. Please narrow your search."
                        )):
                    group_api.lookup_id(group_name)
コード例 #6
0
            def it_calls_the_api(mocker):  # noqa: F811
                mocker.patch('ldap_tools.group.API.index', return_value=None)
                mocker.patch('ldap_tools.client.Client.prepare_connection',
                             return_value=None)
                group_api = GroupApi(client)
                group_api.index = MagicMock()

                runner.invoke(GroupCli.group, ['index'])

                ldap_tools.group.API.index.assert_called_once_with()
コード例 #7
0
            def it_calls_the_client():
                client.modify = MagicMock()

                group_api = GroupApi(client)
                group_api.lookup_id = MagicMock(return_value=99999)

                group_api.remove_user(group_name, username)
                client.modify.assert_called_once_with(
                    'cn={},ou=Group,{}'.format(group_name, client.basedn),
                    {'memberUid': [(ldap3.MODIFY_DELETE, [username])]})
コード例 #8
0
            def it_searches_with_correct_filter():
                pytest.xfail(
                    reason='Need to learn how to mock list.gidNumber.value')
                client.search = MagicMock(return_value=['foo'])

                group_api = GroupApi(client)
                group_api.lookup_id(group_name)
                search_filter = [
                    "(cn={})".format(group_name), "(objectclass=posixGroup)"
                ]
                client.search.assert_called_once_with(search_filter,
                                                      ['gidNumber'])
コード例 #9
0
            def it_calls_the_client():
                client.add = MagicMock()
                client.get_max_id = MagicMock(return_value=99999)
                group_objectclass = ['top', 'posixGroup']

                group_api = GroupApi(client)
                # mocker.patch.object(
                #     group_api, '_API__ldap_attr', return_value=ldap_attributes)

                group_api.create(group_name, group_type)
                client.add.assert_called_once_with(
                    'cn={},ou=Group,{}'.format(group_name, client.basedn),
                    group_objectclass, ldap_attributes)
コード例 #10
0
            def it_calls_the_api(mocker):  # noqa: F811
                mocker.patch('ldap_tools.group.API.add_user',
                             return_value=None)
                mocker.patch('ldap_tools.client.Client.prepare_connection',
                             return_value=None)
                group_api = GroupApi(client)
                group_api.add_user = MagicMock()

                runner.invoke(GroupCli.group, [
                    'add_user', '--group', group_name, '--username', username
                ])

                ldap_tools.group.API.add_user.assert_called_once_with(
                    group_name, username)