def test_compile_with_match_deleted(): query = { 'type': 'exact', 'path': 'dummy.path', 'search_path': 'dummy.search.path', } record = { 'dummy': { 'path': 'foo', }, } result = compile(query, record, match_deleted=True) expected = { 'query': { 'bool': { 'should': [{ 'match': { 'dummy.search.path': 'foo', }, }], }, }, } assert expected == result
def test_compile_returns_none_if_empty_inner(): query = { 'type': 'exact', 'path': 'dummy.path', 'search_path': 'dummy.search.path', } record = {} assert compile(query, record) is None
def test_compile_with_collections(): query = { 'type': 'exact', 'path': 'dummy.path', 'search_path': 'dummy.search.path', } record = { 'dummy': { 'path': 'foo', }, } result = compile(query, record, collections=['Literature', 'HAL Hidden']) expected = { 'query': { 'bool': { 'must': { 'bool': { 'should': [{ 'match': { 'dummy.search.path': 'foo', }, }], }, }, 'filter': { 'bool': { 'should': [ { 'match': { '_collections': 'Literature', }, }, { 'match': { '_collections': 'HAL Hidden', }, } ], 'must_not': { 'match': { 'deleted': True, }, }, }, }, }, }, } assert expected == result
def test_compile_without_optional_args(): query = { 'type': 'exact', 'path': 'dummy.path', 'search_path': 'dummy.search.path', } record = { 'dummy': { 'path': 'foo', }, } result = compile(query, record) expected = { 'query': { 'bool': { 'must': { 'bool': { 'should': [{ 'match': { 'dummy.search.path': 'foo', }, }], }, }, 'filter': { 'bool': { 'must_not': { 'match': { 'deleted': True, }, }, }, }, }, }, } assert expected == result