Exemplo n.º 1
0
    def test_from_yaml(self,
                       mock_name_filter_from_yaml,
                       mock_issue_filter_from_yaml):
        Filter.from_yaml({'type': 'name'})
        self.assertTrue(mock_name_filter_from_yaml.called)
        self.assertFalse(mock_issue_filter_from_yaml.called)

        Filter.from_yaml({'type': 'issue'})
        self.assertTrue(mock_issue_filter_from_yaml.called)
Exemplo n.º 2
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