Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow 'match_all' queries in FakeSearch #54

Merged
merged 1 commit into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions elasticmock/fake_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions tests/fake_elasticsearch/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down