예제 #1
0
def test_set_filters_reserved_params(param):
    from encoded.search import set_filters

    request = FakeRequest((
        (param, 'foo'),
    ))
    query = {
        'filter': {
            'and': {
                'filters': [],
            },
        },
    }
    result = {'filters': []}
    used_filters = set_filters(request, query, result)

    assert used_filters == {}
    assert query == {
        'filter': {
            'and': {
                'filters': [],
            },
        },
    }
    assert result == {
        'filters': [],
    }
예제 #2
0
def test_set_filters_searchTerm():
    from encoded.search import set_filters

    request = FakeRequest((
        ('searchTerm', 'value1'),
    ))
    query = {
        'filter': {
            'and': {
                'filters': [],
            },
        },
    }
    result = {'filters': []}
    used_filters = set_filters(request, query, result)

    assert used_filters == {}
    assert query == {
        'filter': {
            'and': {
                'filters': [],
            },
        },
    }
    assert result == {
        'filters': [
            {
                'field': 'searchTerm',
                'term': 'value1',
                'remove': '/search/?'
            }
        ]
    }
예제 #3
0
def test_set_filters_searchTerm():
    from encoded.search import set_filters

    request = FakeRequest((
        ('searchTerm', 'value1'),
    ))
    query = {
        'filter': {
            'and': {
                'filters': [],
            },
        },
    }
    result = {'filters': []}
    used_filters = set_filters(request, query, result)

    assert used_filters == {}
    assert query == {
        'filter': {
            'and': {
                'filters': [],
            },
        },
    }
    assert result == {
        'filters': [
            {
                'field': 'searchTerm',
                'term': 'value1',
                'remove': '/search/?'
            }
        ]
    }
예제 #4
0
def test_set_filters_reserved_params(param):
    from encoded.search import set_filters

    request = FakeRequest((
        (param, 'foo'),
    ))
    query = {
        'filter': {
            'and': {
                'filters': [],
            },
        },
    }
    result = {'filters': []}
    used_filters = set_filters(request, query, result)

    assert used_filters == {}
    assert query == {
        'filter': {
            'and': {
                'filters': [],
            },
        },
    }
    assert result == {
        'filters': [],
    }
예제 #5
0
def test_set_filters():
    from encoded.search import set_filters

    request = FakeRequest((('field1', 'value1'), ))
    query = {
        'filter': {
            'and': {
                'filters': [],
            },
        },
    }
    result = {'filters': []}
    used_filters = set_filters(request, query, result)

    assert used_filters == {'field1': ['value1']}
    assert query == {
        'filter': {
            'and': {
                'filters': [
                    {
                        'terms': {
                            'embedded.field1.raw': ['value1'],
                        },
                    },
                ],
            },
        },
    }
    assert result == {
        'filters': [{
            'field': 'field1',
            'term': 'value1',
            'remove': '/search/?'
        }]
    }
예제 #6
0
def test_set_filters_reserved_params(param):
    from encoded.search import set_filters

    request = FakeRequest((
        (param, 'foo'),
    ))
    query = {
        'query': {
            'query_string': {}
        },
        'post_filter': {
            'bool': {
                'must': [],
                'must_not': []
            }
        }
    }
    result = {'filters': []}
    used_filters = set_filters(request, query, result)

    assert used_filters == {}
    assert query == {
        'query': {
            'query_string': {}
        },
        'post_filter': {
            'bool': {
                'must': [],
                'must_not': []
            }
        }
    }
    assert result == {
        'filters': [],
    }
예제 #7
0
def test_set_filters_exists_missing():
    from encoded.search import set_filters

    request = FakeRequest((
        ('field1', '*'),
        ('field2!', '*'),
    ))
    query = {
        'filter': {
            'and': {
                'filters': [],
            },
        },
    }
    result = {'filters': []}
    used_filters = set_filters(request, query, result)

    assert used_filters == {
        'field1': ['*'],
        'field2!': ['*'],
    }
    assert query == {
        'filter': {
            'and': {
                'filters': [
                    {
                        'exists': {
                            'field': 'embedded.field1.raw',
                        },
                    },
                    {
                        'missing': {
                            'field': 'embedded.field2.raw',
                        }
                    }
                ],
            },
        },
    }
    assert result == {
        'filters': [
            {
                'field': 'field1',
                'term': '*',
                'remove': '/search/?field2%21=%2A',
            },
            {
                'field': 'field2!',
                'term': '*',
                'remove': '/search/?field1=%2A',
            }
        ],
    }
예제 #8
0
def test_set_filters_exists_missing():
    from encoded.search import set_filters

    request = FakeRequest((
        ('field1', '*'),
        ('field2!', '*'),
    ))
    query = {
        'filter': {
            'and': {
                'filters': [],
            },
        },
    }
    result = {'filters': []}
    used_filters = set_filters(request, query, result)

    assert used_filters == {
        'field1': ['*'],
        'field2!': ['*'],
    }
    assert query == {
        'filter': {
            'and': {
                'filters': [
                    {
                        'exists': {
                            'field': 'embedded.field1.raw',
                        },
                    },
                    {
                        'missing': {
                            'field': 'embedded.field2.raw',
                        }
                    }
                ],
            },
        },
    }
    assert result == {
        'filters': [
            {
                'field': 'field1',
                'term': '*',
                'remove': '/search/?field2%21=%2A',
            },
            {
                'field': 'field2!',
                'term': '*',
                'remove': '/search/?field1=%2A',
            }
        ],
    }
예제 #9
0
def test_set_filters_multivalued():
    from encoded.search import set_filters

    request = FakeRequest((
        ('field1', 'value1'),
        ('field1', 'value2'),
    ))
    query = {
        'query': {
            'query_string': {}
        },
        'post_filter': {
            'bool': {
                'must': [],
                'must_not': []
            }
        }
    }
    result = {'filters': []}
    used_filters = set_filters(request, query, result)

    assert used_filters == {'field1': ['value1', 'value2']}
    assert query == {
        'query': {
            'query_string': {}
        },
        'post_filter': {
            'bool': {
                'must': [
                    {
                        'terms': {
                            'embedded.field1': ['value1', 'value2']
                        }
                    }
                ],
                'must_not': []
            }
        }
    }
    assert result == {
        'filters': [
            {
                'field': 'field1',
                'term': 'value1',
                'remove': '/search/?field1=value2'
            },
            {
                'field': 'field1',
                'term': 'value2',
                'remove': '/search/?field1=value1'
            }
        ]
    }
예제 #10
0
def test_set_filters_audit():
    from encoded.search import set_filters

    request = FakeRequest((
        ('audit.foo', 'value1'),
    ))
    query = {
        'query': {
            'query_string': {}
        },
        'post_filter': {
            'bool': {
                'must': [],
                'must_not': []
            }
        }
    }
    result = {'filters': []}
    used_filters = set_filters(request, query, result)

    assert used_filters == {'audit.foo': ['value1']}
    assert query == {
        'query': {
            'query_string': {}
        },
        'post_filter': {
            'bool': {
                'must': [
                    {
                        'terms': {
                            'audit.foo': ['value1']
                        },
                    },
                ],
                'must_not': []
            }
        }
    }
    assert result == {
        'filters': [
            {
                'field': 'audit.foo',
                'term': 'value1',
                'remove': '/search/?'
            },
        ],
    }
예제 #11
0
def test_set_filters_multivalued():
    from encoded.search import set_filters

    request = FakeRequest((
        ('field1', 'value1'),
        ('field1', 'value2'),
    ))
    query = {
        'filter': {
            'and': {
                'filters': [],
            },
        },
    }
    result = {'filters': []}
    used_filters = set_filters(request, query, result)

    assert used_filters == {'field1': ['value1', 'value2']}
    assert query == {
        'filter': {
            'and': {
                'filters': [
                    {
                        'terms': {
                            'embedded.field1.raw': ['value1', 'value2'],
                        },
                    },
                ],
            },
        },
    }
    assert result == {
        'filters': [
            {
                'field': 'field1',
                'term': 'value1',
                'remove': '/search/?field1=value2'
            },
            {
                'field': 'field1',
                'term': 'value2',
                'remove': '/search/?field1=value1'
            }
        ]
    }
예제 #12
0
def test_set_filters_exists_missing():
    from encoded.search import set_filters

    request = FakeRequest((
        ('field1', '*'),
        ('field2!', '*'),
    ))
    query = {
        'query': {
            'query_string': {}
        },
        'post_filter': {
            'bool': {
                'must': [],
                'must_not': []
            }
        }
    }
    result = {'filters': []}
    used_filters = set_filters(request, query, result)

    assert used_filters == {
        'field1': ['*'],
        'field2!': ['*'],
    }

    assert query == {
        'query': {
            'query_string': {}
        },
        'post_filter': {
            'bool': {
                'must': [
                    {
                        'exists': {
                            'field': 'embedded.field1'
                        }
                    },
                ],
                'must_not': [
                    {
                        'exists': {
                            'field': 'embedded.field2'
                        }
                    }

                ]
            }
        }
    }

    assert result == {
        'filters': [
            {
                'field': 'field1',
                'term': '*',
                'remove': '/search/?field2%21=%2A',
            },
            {
                'field': 'field2!',
                'term': '*',
                'remove': '/search/?field1=%2A',
            }
        ],
    }