How to use ckanapi - 10 common examples

To help you get started, we’ve selected a few ckanapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ADEQUATeDQ / portalmonitor / odpw / testing / __init__.py View on Github external
def analyseAPI(url):
    #if url == "http://catalog.data.gov/":
    #    return
    print url
    try:
        
        
        
        
        package_list, status = util.getPackageList(url)
        print "\t",len(package_list),"getPackageList", status 
    
        ps_name=[]
        ps_id=[]
        api = ckanapi.RemoteCKAN(url, get_only=True)
        response = api.action.package_search(rows=100000000)
        if response:
            datasets= response["results"]
            for ds in datasets:
                ps_name.append(ds['name'])
                ps_id.append(ds['id'])
        ps_name=set(ps_name)       
        ps_id=set(ps_id) 
        print "\t",len(ps_name),len(ps_id),"package_search"
        
        start=0
        steps=len(ps_name)
        pss_name=[]
        pss_id=[]

        while True:
github OCHA-DAP / hdx-python-api / tests / hdx / test_hdx_configuration.py View on Github external
def test_remoteckan_validlocations(self, project_config_yaml):
        Configuration._create(user_agent='test', hdx_site='prod', hdx_key='TEST_HDX_KEY',
                              hdx_base_config_dict={}, project_config_yaml=project_config_yaml)
        remoteckan = ckanapi.RemoteCKAN('http://lalala', apikey='12345',
                                        user_agent='HDXPythonLibrary/1.0')
        Configuration.read().setup_remoteckan(remoteckan=remoteckan)
        assert Configuration.read().remoteckan() == remoteckan
        remoteckan = ckanapi.RemoteCKAN('http://hahaha', apikey='54321',
                                        user_agent='HDXPythonLibrary/0.5')
        Configuration._create(user_agent='test',
                              remoteckan=remoteckan,
                              hdx_site='prod', hdx_key='TEST_HDX_KEY',
                              hdx_base_config_dict={},
                              project_config_yaml=project_config_yaml)
        assert Configuration.read().remoteckan() == remoteckan
        Configuration.read()._remoteckan = None
        with pytest.raises(ConfigurationError):
            Configuration.read().remoteckan()
        Configuration.delete()
        with pytest.raises(ConfigurationError):
            Configuration.read().remoteckan()
github ckan / ckanapi / ckanapi / testappckan.py View on Github external
:param action: the action name, e.g. 'package_create'
        :param data_dict: the dict to pass to the action as JSON,
                          defaults to {}
        :param context: not supported
        :param files: not supported

        This function parses the response from the server as JSON and
        returns the decoded value.  When an error is returned this
        function will convert it back to an exception that matches the
        one the action function itself raised.
        """
        if context:
            raise CKANAPIError("TestAppCKAN.call_action does not support "
                "use of context parameter, use apikey instead")
        if files:
            raise CKANAPIError("TestAppCKAN.call_action does not support "
                "file uploads, consider contributing it if you need it")
        url, data, headers = prepare_action(action, data_dict,
                                            apikey or self.apikey)
        r = self.test_app.post('/' + url, data, headers, expect_errors=True)
        return reverse_apicontroller_action(url, r.status, r.body)
github ckan / ckanext-scheming / tests / test_group_logic.py View on Github external
def test_group_schema_list(self):
        lc = LocalCKAN('visitor')
        group_schemas = lc.action.scheming_group_schema_list()
        assert_equals(sorted(group_schemas), ['group', 'theme'])
github ckan / ckanext-scheming / tests / test_group_logic.py View on Github external
def test_organization_schema_not_found(self):
        lc = LocalCKAN('visitor')
        assert_raises(NotFound,
            lc.action.scheming_organization_schema_show,
            type='elmo')
github ckan / ckanext-scheming / tests / test_group_logic.py View on Github external
def test_group_schema_show(self):
        lc = LocalCKAN('visitor')
        schema = lc.action.scheming_group_schema_show(
            type='group')
        assert_equals(schema['fields'][4]['label'], 'Bookface')
github ckan / ckanext-scheming / tests / test_group_logic.py View on Github external
def test_group_schema_not_found(self):
        lc = LocalCKAN('visitor')
        assert_raises(NotFound,
            lc.action.scheming_group_schema_show,
            type='bert')
github ckan / ckanext-scheming / tests / test_group_logic.py View on Github external
def test_organization_schema_show(self):
        lc = LocalCKAN('visitor')
        schema = lc.action.scheming_organization_schema_show(
            type='organization')
        assert_equals(schema['fields'][4]['label'], 'Department ID')
github ckan / ckanext-scheming / tests / test_group_logic.py View on Github external
def test_organization_schema_list(self):
        lc = LocalCKAN('visitor')
        org_schemas = lc.action.scheming_organization_schema_list()
        assert_equals(sorted(org_schemas), ['organization', 'publisher'])
github ckan / ckanext-scheming / tests / test_group_logic.py View on Github external
def test_organization_schema_not_found(self):
        lc = LocalCKAN('visitor')
        assert_raises(NotFound,
            lc.action.scheming_organization_schema_show,
            type='elmo')