Exemplo n.º 1
0
def test_filters_correctly_identifies_the_hash():
    a = aggs.A('filters',
               filters={
                   'group_a': {
                       'term': {
                           'group': 'a'
                       }
                   },
                   'group_b': {
                       'term': {
                           'group': 'b'
                       }
                   }
               })

    assert {
        'filters': {
            'filters': {
                'group_a': {
                    'term': {
                        'group': 'a'
                    }
                },
                'group_b': {
                    'term': {
                        'group': 'b'
                    }
                }
            }
        }
    } == a.to_dict()
    assert a.filters.group_a == filter.F('term', group='a')
Exemplo n.º 2
0
def test_function_score_to_dict():
    q = query.Q('function_score',
                query=query.Q('match', title='python'),
                functions=[
                    query.SF('random'),
                    query.SF('field_value_factor',
                             field='comment_count',
                             filter=filter.F('term', tags='python'))
                ])

    d = {
        'function_score': {
            'query': {
                'match': {
                    'title': 'python'
                }
            },
            'functions': [{
                'random': {}
            }, {
                'filter': {
                    'term': {
                        'tags': 'python'
                    }
                },
                'field_value_factor': {
                    'field': 'comment_count',
                }
            }],
        }
    }
    assert d == q.to_dict()
Exemplo n.º 3
0
def test_filter_aggregation_with_nested_aggs():
    a = aggs.Filter(filter.F('term', f=42))
    a.bucket('testing', 'terms', field='tags')

    assert {
        'filter': {
            'term': {
                'f': 42
            }
        },
        'aggs': {
            'testing': {
                'terms': {
                    'field': 'tags'
                }
            }
        }
    } == a.to_dict()
Exemplo n.º 4
0
def test_filter_aggregation_as_nested_agg():
    a = aggs.Terms(field='tags')
    a.bucket('filtered', 'filter', filter.F('term', f=42))

    assert {
        'terms': {
            'field': 'tags'
        },
        'aggs': {
            'filtered': {
                'filter': {
                    'term': {
                        'f': 42
                    }
                },
            }
        }
    } == a.to_dict()
Exemplo n.º 5
0
def test_function_score_with_no_function_is_boost_factor():
    q = query.Q(
        'function_score',
        functions=[query.SF({
            'weight': 20,
            'filter': filter.F('term', f=42)
        })])

    assert {
        'function_score': {
            'functions': [{
                'filter': {
                    'term': {
                        'f': 42
                    }
                },
                'weight': 20
            }]
        }
    } == q.to_dict()
Exemplo n.º 6
0
 def _get_colombia_filter(self):
     if self.allow_colombia and self.request.REGION == mkt.regions.COL:
         return None
     co_filter = es_filter.Term(tags=COLOMBIA_WEBSITE)
     return es_filter.F(es_filter.Bool(must_not=[co_filter]), )
Exemplo n.º 7
0
def test_filter_can_be_instantiated_using_positional_args():
    a = aggs.Filter(filter.F('term', f=42))

    assert {'filter': {'term': {'f': 42}}} == a.to_dict()

    assert a == aggs.A('filter', filter.F('term', f=42))
Exemplo n.º 8
0
def test_and_can_be_created_with_a_list():
    f = filter.F('and', [filter.F('term', field='value')])

    assert isinstance(f, filter.And)
    assert f.filters == [filter.F('term', field='value')]
    assert f == filter.And([filter.F('term', field='value')])
Exemplo n.º 9
0
def test_query_can_use_positional_arg():
    f = filter.F('query', Q('match_all'))

    assert f.query == Q('match_all')
    assert {'query': {'match_all': {}}} == f.to_dict()
Exemplo n.º 10
0
def test_not_doesnt_have_to_wrap_filter():
    f = filter.F('not', term={'field': 'value'})

    assert isinstance(f, filter.Not)
    assert f.filter == filter.F('term', field='value')
    assert f == filter.Not(filter.F('term', field='value'))
Exemplo n.º 11
0
def test_other_filters_must_use_kwargs():
    with raises(ValueError):
        filter.F('bool', [filter.F('term', field='value')])
Exemplo n.º 12
0
def test_repr():
    f = filter.F('terms', **{'some.path': 'value'})

    assert "Terms(some__path='value')" == repr(f)
Exemplo n.º 13
0
def test_empty_F_is_match_all():
    f = filter.F()

    assert isinstance(f, filter.MatchAll)
    assert filter.MatchAll() == f
Exemplo n.º 14
0
def test_and_can_be_created_from_list():
    f = filter.F({'and': [{'term': {'f': 'v'}}, {'term': {'f2': 42}}]})

    assert f == filter.And([filter.F('term', f='v'), filter.F('term', f2=42)])