예제 #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)
예제 #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
예제 #3
0
def get_filters_from_args(args):
    """Creates Filter objects from CLI arguments.

    :param args: CLI arguments.
    :return: List of created Filter objects.
    """
    filters_list = []

    if args.branch_names:
        filter_dict = {'type': 'name', 'regular_expressions':
            args.branch_names}
        filters_list.append(Filter.from_args(filter_dict))

    if args.jira_team:
        if hasattr(args, 'jira_statuses') and args.jira_statuses:
            jira_statuses = args.jira_statuses
        else:
            jira_statuses = []

        filter_dict = {'type': 'issue', 'jira_team_name': args.jira_team,
                         'jira_statuses': jira_statuses}
        filters_list.append(Filter.from_args(filter_dict))

    return filters_list
예제 #4
0
 def test_get_filter_class(self):
     self.assertEqual(Filter.get_filter_class('name'), NameFilter)
     self.assertEqual(Filter.get_filter_class('issue'), IssueFilter)
     self.assertRaises(KeyError, Filter.get_filter_class, 'invalid_key')
예제 #5
0
 def test_from_args_with_filter_types(self):
     filter_dict = {'type': 'name'}
     self.assertIsInstance(Filter.from_args(filter_dict), NameFilter)
     filter_dict['type'] = 'issue'
     self.assertIsInstance(Filter.from_args(filter_dict), IssueFilter)