Пример #1
0
 def test_remoteckan_validlocations(self, project_config_yaml):
     Configuration._create(hdx_site='prod',
                           hdx_key='TEST_HDX_KEY',
                           hdx_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)
     assert Configuration.read().remoteckan() == remoteckan
     remoteckan = ckanapi.RemoteCKAN('http://hahaha',
                                     apikey='54321',
                                     user_agent='HDXPythonLibrary/0.5')
     Configuration._create(remoteckan=remoteckan,
                           hdx_site='prod',
                           hdx_key='TEST_HDX_KEY',
                           hdx_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()
Пример #2
0
    def update_config(self, config_):
        toolkit.add_template_directory(config_, 'templates')
        toolkit.add_public_directory(config_, 'public')
        toolkit.add_resource('fanstatic', 'knowledgehub')

        # Eliminates the need to re-initialize the database when model changes.
        #        _init_knowledgehub_database()
        _patch_ckan_base_controller()

        # patch the CKAN core functionality
        patch_ckan_core_search()
        # Extend CKAN Tag table
        # extend_tag_table()
        # Extend CKAN ResourceView table
        # extend_resource_view_table()
        # Upgrade the dashboard table.
        #dashboard_table_upgrade()

        DatastoreBackend.register_backends()
        # DatastoreBackend.set_active_backend(config)

        # Create the HDX configuration
        hdx_api_key = config.get(u'ckanext.knowledgehub.hdx.api_key')
        hdx_site = config.get(u'ckanext.knowledgehub.hdx.site', 'test')
        Configuration.delete()
        Configuration.create(
            hdx_site=hdx_site,  # from config, default to test
            user_agent='admin',
            hdx_key=hdx_api_key)
 def test_create_set_configuration(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)
     with pytest.raises(ConfigurationError):
         Configuration.create(user_agent='test', hdx_site='prod', hdx_key='TEST_HDX_KEY',
                              hdx_base_config_dict={}, project_config_yaml=project_config_yaml)
     configuration = Configuration(user_agent='test', hdx_site='test', hdx_key='OTHER_TEST_HDX_KEY',
                                   hdx_base_config_dict={}, project_config_yaml=project_config_yaml)
     Configuration.setup(configuration)
     assert Configuration.read() == configuration
     Configuration.delete()
     with pytest.raises(ConfigurationError):
         Configuration.read()
     Configuration.create(user_agent='test', hdx_site='prod', hdx_key='TEST_HDX_KEY',
                          hdx_base_config_dict={}, project_config_yaml=project_config_yaml)
     assert Configuration.read().get_api_key() == 'TEST_HDX_KEY'