Пример #1
0
def test_resource_status_show():
    results = get.resource_search(client=client.Client(), query='name:csv')
    assert results['success'] is True
    if results['result']['count'] > 0:
        id = results['result']['results'][0]['id']
        results = get.resource_status_show(client=client.Client(), id=id)
        assert results['success'] is True
Пример #2
0
def test_group_package_show():
    groups = get.group_list(client=client.Client())
    assert groups['success'] is True
    group = groups['result'][0]
    results = get.group_package_show(client=client.Client(), id=group)
    assert results['success'] is True
    assert len(results['result']) > 0
    assert results['result'][0]['name'] != ''
Пример #3
0
def test_related_list():
    packages = get.package_list(client=client.Client())
    assert len(packages['result']) > 0
    import random
    pkg = random.choice(packages['result'])
    results = get.related_list(client=client.Client(), id=pkg)
    assert results['success'] is True
    assert isinstance(results['result'], list)
Пример #4
0
def test_package_show():
    results = get.package_search(client=client.Client(), q='test')
    assert results['success'] is True
    id = results['result']['results'][0]['id']
    results = get.package_show(client=client.Client(), id=id)
    assert results['success'] is True
    assert isinstance(results['result'], dict)
    assert results['result']['id'] == id
Пример #5
0
def test_revision_show():
    results = get.revision_list(client=client.Client())
    assert results['success'] is True
    if len(results['result']) > 0:
        assert results['result'][0] != ''
        results = get.revision_show(client=client.Client(),
                                    id=results['result'][0])
        assert results['success'] is True
        assert results['result']['timestamp'] != ''
Пример #6
0
def test_roles_show():
    results = get.package_search(client=client.Client(), q='test')
    assert results['success'] is True
    id = results['result']['results'][0]['id']
    results = get.roles_show(client=client.Client(), domain_object=id)
    print results['result']
    assert results['success'] is True
    assert results['result']['domain_object_type'] == 'Package'
    assert isinstance(results['result']['roles'], list)
Пример #7
0
def test_group_show():
    groups = get.group_list(client=client.Client(),
                            order_by='',
                            sort='',
                            groups='',
                            all_fields='')
    group = groups['result'][0]
    results = get.group_show(client=client.Client(), id=group)
    assert results['success'] is True
    assert results['result']['display_name'].lower() == group.lower()
Пример #8
0
def test_user_show():
    results = get.user_list(client=client.Client(), q='', order_by='')
    assert results['success'] is True
    assert len(results['result']) > 0
    assert isinstance(results['result'][0], dict)
    id = results['result'][0]['id']
    name = results['result'][0]['name']
    results = get.user_show(client=client.Client(), id=id)
    assert results['result']['id'] == id
    assert results['result']['name'] == name
Пример #9
0
def test_member_list():
    groups = get.group_list(client=client.Client(),
                            order_by='',
                            sort='',
                            groups='',
                            all_fields='')
    group = groups['result'][0]
    results = get.member_list(client=client.Client(), id=group)
    print results['result']
    assert results['success'] is True
    assert len(results['result']) > 0
Пример #10
0
def test_task_status_show():
    results = get.resource_search(client=client.Client(),
                                  query='name:bus-stops')
    assert results['success'] is True
    if results['result']['count'] > 0:
        id = results['result']['results'][0]['id']
        results = get.resource_status_show(client=client.Client(), id=id)
        assert results['success'] is True
        if results['result']['message']:
            return
        results = get.task_status_show(client=client.Client(), entity_id=id)
        assert results['success'] is True
Пример #11
0
def test_organization_show():
    results = get.organization_list(client=client.Client(),
                                    order_by='',
                                    sort='',
                                    organizations='',
                                    all_fields=True)
    assert results['success'] is True
    orgs = results['result']
    if len(orgs) > 0:
        results = get.organization_show(client=client.Client(),
                                        id=orgs[0]['id'])
        assert results['success'] is True
        assert results['result']['display_name'] == orgs[0]['display_name']
Пример #12
0
def test_group_list():
    results = get.group_list(client=client.Client(),
                             order_by='',
                             sort='',
                             groups='',
                             all_fields='')
    assert results['success'] is True
    assert len(results['result']) > 0
    assert results['result'][0] != ''
    results = get.group_list(client=client.Client(), all_fields=True)
    assert results['success'] is True
    assert len(results['result']) > 0
    assert isinstance(results['result'][0], dict)
Пример #13
0
def test_user_autocomplete():
    results = get.user_list(client=client.Client(), q='', order_by='')
    assert results['success'] is True
    assert len(results['result']) > 0
    assert isinstance(results['result'][0], dict)
    name = results['result'][0]['name']
    assert name != ''
    results = get.user_autocomplete(client=client.Client(), q=name[:3])
    assert results['success'] is True
    found = False
    for result in results['result']:
        if result['name'] == name:
            found = True
    assert found == True
Пример #14
0
def test_resource_show():
    results = get.resource_search(client=client.Client(), query='name:csv')
    assert results['success'] is True
    if results['result']['count'] > 0:
        res_orig = results['result']['results'][0]
        try:
            res_show = get.resource_show(client=client.Client(),
                                         id=res_orig['id'])
            assert results['success'] is True
            assert res_show['id'] == res_orig['id']
        except exceptions.CKANError, e:
            if str(e.type).lower().find('auth') >= 0:
                return
            else:
                raise exceptions.CKANError(e)
Пример #15
0
def package_autocomplete(client=client.Client(), q=''):
    """
    Return a list of datasets (packages) that match a string.

    Datasets with names or titles that contain the query string will be
    returned.

    

    :param client: the CKAN Client. 
        Default: an instance of libckan.model.client.Client
    :type client: libckan.model.client.Client
    :param q: the string to search for
    :type q: string

    :rtype: list of dictionaries

    

    :returns: the dictionary returned by the CKAN API, 
        with the keys "help","result", and "success". 
        "results" is a list of packages (dict).
    :return: dict

    Raises: :class:`libckan.model.exceptions.CKANError`: 
        An error occurred accessing CKAN API
    """
    args = client.sanitize_params(locals())

    resp = client.request(action='package_autocomplete', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp
Пример #16
0
def group_package_show(client=client.Client(), id='', limit=''):
    """
    Return the datasets (packages) of a group.


    :param client: the CKAN Client. 
        Default: an instance of libckan.model.client.Client
    :type client: libckan.model.client.Client
    :param id: the id or name of the group
    :type id: string
    :param limit: the maximum number of datasets to return (optional)
    :type limit: int

    :rtype: list of dictionaries

    

    :returns: the dictionary returned by the CKAN API, 
        with the keys "help","result", and "success". 
        "results" is a list of packages (dict).
    :return: dict

    Raises: :class:`libckan.model.exceptions.CKANError`: 
        An error occurred accessing CKAN API
    """
    args = client.sanitize_params(locals())

    resp = client.request(action='group_package_show', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp
Пример #17
0
def roles_show(client=client.Client(), domain_object='', user=''):
    """
    Return the roles of all users and authorization groups for an object.

    

    :param client: the CKAN Client. 
        Default: an instance of libckan.model.client.Client
    :type client: libckan.model.client.Client
    :param domain_object: a package or group name or id
        to filter the results by
    :type domain_object: string
    :param user: a user name or id
    :type user: string

    :rtype: list of dictionaries

    

    :returns: the dictionary returned by the CKAN API, 
        with the keys "help","result", and "success". 
        "results" is a list of packages (dict).
    :return: dict

    Raises: :class:`libckan.model.exceptions.CKANError`: 
        An error occurred accessing CKAN API
    """
    args = client.sanitize_params(locals())

    resp = client.request(action='roles_show', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp
Пример #18
0
def test_organization_list_for_user():
    results = get.organization_list_for_user(client=client.Client())
    assert results['success'] is True
    orgs = results['result']
    assert len(orgs) >= 0
    if len(orgs) > 0:
        assert orgs[0] != ''
Пример #19
0
def test_resource_search():
    results = get.resource_search(client=client.Client(), query='name:csv')
    assert results['success'] is True
    if results['result']['count'] > 0:
        print results['result']['results']
        assert isinstance(results['result']['results'][0], dict)
        assert results['result']['results'][0]['name'] != ''
Пример #20
0
def dashboard_new_activities_count(client=client.Client()):
    """
    Return the number of new activities in the user's dashboard.

    Return the number of new activities in the authorized user's dashboard
    activity stream.

    Activities from the user herself are not counted by this function even
    though they appear in the dashboard (users don't want to be notified about
    things they did themselves).

    :rtype: int

   

    :param client: the CKAN Client. 
        Default: an instance of libckan.model.client.Client
    :type client: libckan.model.client.Client
     

    :returns: the dictionary returned by the CKAN API, 
        with the keys "help","result", and "success". 
        "results" is a list of packages (dict).
    :return: dict

    Raises: :class:`libckan.model.exceptions.CKANError`: 
        An error occurred accessing CKAN API
    """
    args = client.sanitize_params(locals())

    resp = client.request(action='dashboard_new_activities_count', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp
Пример #21
0
def user_show(client=client.Client(), id='', user_obj=''):
    """
    Return a user account.

    Either the ``id`` or the ``user_obj`` parameter must be given.

    

    :param client: the CKAN Client. 
        Default: an instance of libckan.model.client.Client
    :type client: libckan.model.client.Client
    :param id: the id or name of the user (optional)
    :type id: string
    :param user_obj: the user dictionary of the user (optional)
    :type user_obj: user dictionary

    :rtype: dictionary

    

    :returns: the dictionary returned by the CKAN API, 
        with the keys "help","result", and "success". 
        "results" is a list of packages (dict).
    :return: dict

    Raises: :class:`libckan.model.exceptions.CKANError`: 
        An error occurred accessing CKAN API
    """
    args = client.sanitize_params(locals())

    resp = client.request(action='user_show', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp
Пример #22
0
def tag_show(client=client.Client(), id=''):
    """
    Return the details of a tag and all its datasets.

    

    :param client: the CKAN Client. 
        Default: an instance of libckan.model.client.Client
    :type client: libckan.model.client.Client
    :param id: the name or id of the tag
    :type id: string

    :returns: the details of the tag, including a list of all of the tag's
        datasets and their details
    :rtype: dictionary

    

    :returns: the dictionary returned by the CKAN API, 
        with the keys "help","result", and "success". 
        "results" is a list of packages (dict).
    :return: dict

    Raises: :class:`libckan.model.exceptions.CKANError`: 
        An error occurred accessing CKAN API
    """
    args = client.sanitize_params(locals())

    resp = client.request(action='tag_show', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp
Пример #23
0
def user_autocomplete(client=client.Client(), q='', limit=''):
    """
    Return a list of user names that contain a string.

    

    :param client: the CKAN Client. 
        Default: an instance of libckan.model.client.Client
    :type client: libckan.model.client.Client
    :param q: the string to search for
    :type q: string
    :param limit: the maximum number of user names to return (optional,
        default: 20)
    :type limit: int

    :rtype: a list of user dictionaries each with keys ``'name'``,
        ``'fullname'``, and ``'id'``

    

    :returns: the dictionary returned by the CKAN API, 
        with the keys "help","result", and "success". 
        "results" is a list of packages (dict).
    :return: dict

    Raises: :class:`libckan.model.exceptions.CKANError`: 
        An error occurred accessing CKAN API
    """
    args = client.sanitize_params(locals())

    resp = client.request(action='user_autocomplete', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp
Пример #24
0
def group_list_authz(client=client.Client(), available_only=''):
    """
    Return the list of groups that the user is authorized to edit.

    

    :param client: the CKAN Client. 
        Default: an instance of libckan.model.client.Client
    :type client: libckan.model.client.Client
    :param available_only: remove the existing groups in the package
      (optional, default: ``False``)
    :type available_only: boolean

    :returns: the names of groups that the user is authorized to edit
    :rtype: list of strings

    

    :returns: the dictionary returned by the CKAN API, 
        with the keys "help","result", and "success". 
        "results" is a list of packages (dict).
    :return: dict

    Raises: :class:`libckan.model.exceptions.CKANError`: 
        An error occurred accessing CKAN API
    """
    args = client.sanitize_params(locals())

    resp = client.request(action='group_list_authz', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp
Пример #25
0
def test_tag_show():
    results = get.tag_list(query='', vocabulary_id='', all_fields=False)
    tags = results['result']
    tag = tags[0]
    results = get.tag_show(client=client.Client(), id=tag)
    assert results['success'] is True
    assert results['result']['display_name'] == tag
Пример #26
0
def package_relationships_list(client=client.Client(), id='', id2='', rel=''):
    """
    Return a dataset (package)'s relationships.

    

    :param client: the CKAN Client. 
        Default: an instance of libckan.model.client.Client
    :type client: libckan.model.client.Client
    :param id: the id or name of the package
    :type id: string
    :param id2:
    :type id2:
    :param rel:
    :type rel:

    :rtype: list of dictionaries

    

    :returns: the dictionary returned by the CKAN API, 
        with the keys "help","result", and "success". 
        "results" is a list of packages (dict).
    :return: dict

    Raises: :class:`libckan.model.exceptions.CKANError`: 
        An error occurred accessing CKAN API
    """
    args = client.sanitize_params(locals())

    resp = client.request(action='package_relationships_list', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp
Пример #27
0
def user_list(client=client.Client(), q='', order_by=''):
    """
    Return a list of the site's user accounts.

    

    :param client: the CKAN Client. 
        Default: an instance of libckan.model.client.Client
    :type client: libckan.model.client.Client
    :param q: restrict the users returned to those whose names contain a string
      (optional)
    :type q: string
    :param order_by: which field to sort the list by (optional, default:
      ``'name'``)
    :type order_by: string

    :rtype: list of dictionaries

    

    :returns: the dictionary returned by the CKAN API, 
        with the keys "help","result", and "success". 
        "results" is a list of packages (dict).
    :return: dict

    Raises: :class:`libckan.model.exceptions.CKANError`: 
        An error occurred accessing CKAN API
    """
    args = client.sanitize_params(locals())

    resp = client.request(action='user_list', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp
Пример #28
0
def organization_activity_list_html(client=client.Client(), id=''):
    """
    Return a organization's activity stream as HTML.

    The activity stream is rendered as a snippet of HTML meant to be included
    in an HTML page, i.e. it doesn't have any HTML header or footer.

    

    :param client: the CKAN Client. 
        Default: an instance of libckan.model.client.Client
    :type client: libckan.model.client.Client
    :param id: the id or name of the organization
    :type id: string

    :rtype: string

    

    :returns: the dictionary returned by the CKAN API, 
        with the keys "help","result", and "success". 
        "results" is a list of packages (dict).
    :return: dict

    Raises: :class:`libckan.model.exceptions.CKANError`: 
        An error occurred accessing CKAN API
    """
    args = client.sanitize_params(locals())

    resp = client.request(action='organization_activity_list_html', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp
Пример #29
0
def related_show(client=client.Client(), id=''):
    """
    Return a single related item.

    

    :param client: the CKAN Client. 
        Default: an instance of libckan.model.client.Client
    :type client: libckan.model.client.Client
    :param id: the id of the related item to show
    :type id: string

    :rtype: dictionary

    

    :returns: the dictionary returned by the CKAN API, 
        with the keys "help","result", and "success". 
        "results" is a list of packages (dict).
    :return: dict

    Raises: :class:`libckan.model.exceptions.CKANError`: 
        An error occurred accessing CKAN API
    """
    args = client.sanitize_params(locals())

    resp = client.request(action='related_show', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp
Пример #30
0
def revision_list(client=client.Client()):
    """
    Return a list of the IDs of the site's revisions.

    :rtype: list of strings

   

    :param client: the CKAN Client. 
        Default: an instance of libckan.model.client.Client
    :type client: libckan.model.client.Client
     

    :returns: the dictionary returned by the CKAN API, 
        with the keys "help","result", and "success". 
        "results" is a list of packages (dict).
    :return: dict

    Raises: :class:`libckan.model.exceptions.CKANError`: 
        An error occurred accessing CKAN API
    """
    args = client.sanitize_params(locals())

    resp = client.request(action='revision_list', data=args)
    if not resp['success']:
        raise exceptions.CKANError(resp.error)
    return resp