From 23530b551b66924f27874b2aa4068a6deb30d11a Mon Sep 17 00:00:00 2001 From: Jan Kislinger Date: Tue, 29 Dec 2020 14:39:48 +0100 Subject: [PATCH] allow 'match_all' queries in FakeSearch --- elasticmock/fake_elasticsearch.py | 2 ++ tests/fake_elasticsearch/test_search.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/elasticmock/fake_elasticsearch.py b/elasticmock/fake_elasticsearch.py index 98e5a6e..f9980e8 100644 --- a/elasticmock/fake_elasticsearch.py +++ b/elasticmock/fake_elasticsearch.py @@ -62,6 +62,8 @@ def evaluate(self, document): def _evaluate_for_query_type(self, document): if self.type == QueryType.MATCH: return self._evaluate_for_match_query_type(document) + elif self.type == QueryType.MATCH_ALL: + return True elif self.type == QueryType.TERM: return self._evaluate_for_term_query_type(document) elif self.type == QueryType.TERMS: diff --git a/tests/fake_elasticsearch/test_search.py b/tests/fake_elasticsearch/test_search.py index 74079fe..df67f22 100644 --- a/tests/fake_elasticsearch/test_search.py +++ b/tests/fake_elasticsearch/test_search.py @@ -24,6 +24,14 @@ def test_should_return_all_documents(self): search = self.es.search() self.assertEqual(index_quantity, search.get('hits').get('total')) + def test_should_return_all_documents_match_all(self): + index_quantity = 10 + for i in range(0, index_quantity): + self.es.index(index='index_{0}'.format(i), doc_type=DOC_TYPE, body={'data': 'test_{0}'.format(i)}) + + search = self.es.search(body={'query': {'match_all': {}}}) + self.assertEqual(index_quantity, search.get('hits').get('total')) + def test_should_return_only_indexed_documents_on_index(self): index_quantity = 2 for i in range(0, index_quantity):