Exemplo n.º 1
0
def test_tagsmatcher_with_both_tag_and_tags():
    """If both 'tag' and 'tags' params are used they should all become tags."""
    params = {'tag': 'foo', 'tags': 'bar'}

    result = query.TagsMatcher()(params)

    assert list(result.keys()) == ['bool']
    assert list(result['bool'].keys()) == ['must']
    assert len(result['bool']['must']) == 2
    assert {
        'match': {
            'tags': {
                'query': 'foo',
                'operator': 'and'
            }
        }
    } in result['bool']['must']
    assert {
        'match': {
            'tags': {
                'query': 'bar',
                'operator': 'and'
            }
        }
    } in result['bool']['must']
Exemplo n.º 2
0
def test_tagsmatcher_aliases_tag_to_tags():
    """'tag' params should be transformed into 'tags' queries.

    'tag' is aliased to 'tags' because users often type tag instead of tags.

    """
    params = multidict.MultiDict()
    params.add('tag', 'foo')
    params.add('tag', 'bar')

    result = query.TagsMatcher()(params)

    assert list(result.keys()) == ['bool']
    assert list(result['bool'].keys()) == ['must']
    assert len(result['bool']['must']) == 2
    assert {
        'match': {
            'tags': {
                'query': 'foo',
                'operator': 'and'
            }
        }
    } in result['bool']['must']
    assert {
        'match': {
            'tags': {
                'query': 'bar',
                'operator': 'and'
            }
        }
    } in result['bool']['must']
Exemplo n.º 3
0
def test_tagsmatcher_with_both_tag_and_tags():
    """If both 'tag' and 'tags' params are used they should all become tags."""
    params = {'tag': 'foo', 'tags': 'bar'}

    result = query.TagsMatcher()(params)

    assert result == {
        'bool': {
            'must': [
                {
                    'match': {
                        'tags': {
                            'query': 'foo',
                            'operator': 'and'
                        }
                    }
                },
                {
                    'match': {
                        'tags': {
                            'query': 'bar',
                            'operator': 'and'
                        }
                    }
                },
            ]
        }
    }
Exemplo n.º 4
0
def test_tagsmatcher_aliases_tag_to_tags():
    """'tag' params should be transformed into 'tags' queries.

    'tag' is aliased to 'tags' because users often type tag instead of tags.

    """
    params = multidict.MultiDict()
    params.add('tag', 'foo')
    params.add('tag', 'bar')

    result = query.TagsMatcher()(params)

    assert result == {
        'bool': {
            'must': [
                {
                    'match': {
                        'tags': {
                            'query': 'foo',
                            'operator': 'and'
                        }
                    }
                },
                {
                    'match': {
                        'tags': {
                            'query': 'bar',
                            'operator': 'and'
                        }
                    }
                },
            ]
        }
    }
Exemplo n.º 5
0
Arquivo: core.py Projeto: openbizgit/h
 def make_builder():
     builder = query.Builder()
     builder.append_filter(query.AuthFilter(request, private=private))
     builder.append_filter(query.UriFilter())
     builder.append_filter(
         lambda _: nipsa.nipsa_filter(request.authenticated_userid))
     builder.append_filter(query.GroupFilter())
     builder.append_matcher(query.AnyMatcher())
     builder.append_matcher(query.TagsMatcher())
     return builder
Exemplo n.º 6
0
def default_querybuilder(request, private=True):
    builder = query.Builder()
    builder.append_filter(query.AuthFilter(request, private=private))
    builder.append_filter(query.UriFilter(request))
    builder.append_filter(query.GroupFilter())
    builder.append_matcher(query.AnyMatcher())
    builder.append_matcher(query.TagsMatcher())
    for factory in request.registry.get(FILTERS_KEY, []):
        builder.append_filter(factory(request))
    for factory in request.registry.get(MATCHERS_KEY, []):
        builder.append_matcher(factory(request))
    return builder