Exemple #1
0
def facade(projectmainfn: Callable[[Configuration], None], **kwargs) -> bool:
    """Facade that handles ScraperWiki and calls project main function

    Args:
        projectmainfn ((configuration) -> None): main function of project
        **kwargs: configuration parameters to pass to HDX Configuration class

    Returns:
        bool: True = success, False = failure
    """

    try:
        #
        # Setting up configuration
        #
        configuration = Configuration(**kwargs)

        logger.info('--------------------------------------------------')
        logger.info('> HDX Site: %s' % configuration.get_hdx_site_url())

        projectmainfn(configuration)

    except Exception as e:
        logger.critical(e, exc_info=True)
        scraperwiki.status('error', 'Run failed: %s' % sys.exc_info()[0])
        return False
    logger.info('Run completed successfully.\n')
    scraperwiki.status('ok')
    return True
 def test_get_hdx_key_site(self, hdx_key_file, project_config_yaml):
     actual_configuration = Configuration(hdx_site='prod', hdx_key_file=hdx_key_file,
                                          hdx_config_dict={},
                                          project_config_yaml=project_config_yaml)
     assert actual_configuration.get_api_key() == '12345'
     assert actual_configuration.get_hdx_site_url() == 'https://data.humdata.org/'
     assert actual_configuration._get_credentials() == ('', '')
Exemple #3
0
 def __init__(self, configuration: Configuration, initial_data: dict):
     super(HDXObject, self).__init__(initial_data)
     self.configuration = configuration
     self.old_data = None
     version_file = open(script_dir_plus_file(join('..', 'version.txt'), HDXObject))
     version = version_file.read().strip()
     self.hdxpostsite = ckanapi.RemoteCKAN(configuration.get_hdx_site_url(),
                                           apikey=configuration.get_api_key(),
                                           user_agent='HDXPythonLibrary/%s' % version)
Exemple #4
0
def facade(projectmainfn: Callable[[Configuration], None], **kwargs) -> None:
    """Facade to simplify project setup that calls project main function

    Args:
        projectmainfn ((configuration) -> None): main function of project
        **kwargs: configuration parameters to pass to HDX Configuration class

    Returns:
        None
    """

    #
    # Setting up configuration
    #
    configuration = Configuration(**kwargs)

    logger.info('--------------------------------------------------')
    logger.info('> HDX Site: %s' % configuration.get_hdx_site_url())

    projectmainfn(configuration)
Exemple #5
0
def my_excfn(configuration: Configuration):
    testresult.actual_result = configuration.get_hdx_site_url()
    raise ValueError('Some failure!')
Exemple #6
0
def my_testfn(configuration: Configuration):
    testresult.actual_result = configuration.get_hdx_site_url()