def test_execute_free(self, free): """Dispatch the query of type free.""" query = {'type': 'free', 'match': 'titles.title', 'query': 'foo.bar.baz'} record = Record(self.data) execute(query, record) free.assert_called_with(match='titles.title', values=['foo bar'], query='foo.bar.baz')
def test_execute_not_implemented(self): """Raise for other types.""" query = {'type': 'foobar', 'match': 'titles.title'} record = Record(self.data) with pytest.raises(NotImplementedQuery) as excinfo: execute(query, record) self.assertIn('type foobar', str(excinfo.value))
def test_execute_exact(self, exact): """Dispatch the query of type exact.""" query = {'type': 'exact', 'match': 'titles.title'} record = Record(self.data) execute(query, record) exact.assert_called_with(match='titles.title', values=['foo bar'])
def test_execute_fuzzy(self, fuzzy): """Dispatch the query of type fuzzy.""" query = {'type': 'fuzzy', 'match': 'titles.title'} record = Record(self.data) execute(query, record) fuzzy.assert_called_with(match='titles.title', values=['foo bar'])
def test_execute_missing_data_in_key(app): """Handle no data in key of record""" with app.app_context(): query = {'type': 'exact', 'match': 'title'} index = "records" doc_type = "record" record = Record({'title': None}) assert execute(index, doc_type, query, record) == []
def test_execute_missing_data(app): """Handle missing data in record.""" with app.app_context(): query = {'type': 'exact', 'match': 'title'} index = "records" doc_type = "record" record = Record({}) assert execute(index, doc_type, query, record) == []
def test_execute_missing_type(app, simple_record): """Handle things when bad query type is passed.""" with app.app_context(): query = {'type': 'banana', 'match': 'title'} index = "records" doc_type = "record" record = Record(simple_record) with pytest.raises(NotImplementedQuery): result = execute(index, doc_type, query, record)
def test_execute_free(app, simple_record, mocker): """Dispatch the query of type free.""" mocker.patch('invenio_matcher.engine.search', empty_search_result) with app.app_context(): query = {'type': 'free', 'match': 'title'} index = "records" doc_type = "record" record = Record(simple_record) expected = [] result = execute(index, doc_type, query, record) assert result == expected
def test_invalid_execute(self): query = {'type': 'invalid'} with pytest.raises(InvalidQuery): execute(query, {}, 'records', 'record')