示例#1
0
def get_query_from_yaml(config_path):
    """Creates a Query object from a yaml file found in config_path.

    The Query object is created from the configuration found in the yaml file.
    Filters objects are created from the yaml file aswell and are attached
    to the Query.
    :param config_path: Path to the configuration yaml file.
    :return: A Query object along with the filters in the file, if found.
    """
    try:
        with open(config_path) as config_file:
            yaml_contents = yaml.load(config_file)

    except IOError:
        sys.exit('The config.yaml path you provided, `{0}`, does not '
                 'lead to an existing file.'.format(config_path))

    yaml_config = yaml_contents['query_config']
    yaml_filters = yaml_contents['filters']

    qc = QueryConfig.from_yaml(yaml_config)
    filters = [Filter.from_yaml(yaml_filter) for yaml_filter in yaml_filters]

    query = Query.from_config(qc)
    query.attach_filters(filters)

    return query
示例#2
0
    def test_from_yaml(self):
        yaml_qc = yaml.load(
                'thread_limit:  120\n'
                'data_type:    branch\n'
                'github_org:   cloudify-cosmo\n'
                'output_path:  /home/avia/tattle/output/report.json\n'
        )

        expected_qc = QueryConfig('branch',
                                  120,
                                  Organization('cloudify-cosmo'),
                                  '/home/avia/tattle/output/report.json'
                                  )
        self.assertEqual(QueryConfig.from_yaml(yaml_qc), expected_qc)
示例#3
0
def get_query_from_args(args):
    """Creates a Query object from the CLI arguments.

    Filter objects are created from the CLI argument and attached to the
    Query object.
    :param args: CLI arguments
    :return: A Query object along with the created filters, if found.
    """
    qc = QueryConfig.from_args(args)
    filters = get_filters_from_args(args)

    query = Query.from_config(qc)
    query.attach_filters(filters)

    return query
示例#4
0
 def test_github_credentials_accessing_os_environ(self, mock_os):
     mock_os.environ = {'GITHUB_USER': '******', 'GITHUB_PASS': '******'}
     expected_credentials = ('user', 'pass')
     self.assertEqual(QueryConfig.github_credentials(),
                      expected_credentials)