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

Add shards skipped to search and count #56

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 @@ -343,6 +343,7 @@ def count(self, index=None, doc_type=None, body=None, params=None, headers=None)
'count': i,
'_shards': {
'successful': 1,
'skipped': 0,
'failed': 0,
'total': 1
}
Expand Down Expand Up @@ -394,6 +395,7 @@ def search(self, index=None, doc_type=None, body=None, params=None, headers=None
'_shards': {
# Simulate indexes with 1 shard each
'successful': len(searchable_indexes),
'skipped': 0,
'failed': 0,
'total': len(searchable_indexes)
},
Expand Down
5 changes: 5 additions & 0 deletions tests/fake_elasticsearch/test_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def test_should_count_with_empty_doc_types(self):
count = self.es.count(doc_type=[])
self.assertEqual(1, count.get('count'))

def test_should_return_skipped_shards(self):
self.es.index(index='index', doc_type=DOC_TYPE, body={'data': 'test'})
count = self.es.count(doc_type=[])
self.assertEqual(0, count.get('_shards').get('skipped'))

def test_should_count_with_doc_types(self):
self.es.index(index='index', doc_type=DOC_TYPE, body={'data': 'test1'})
self.es.index(index='index', doc_type='different-doc-type', body={'data': 'test2'})
Expand Down
4 changes: 4 additions & 0 deletions tests/fake_elasticsearch/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def test_should_return_hits_hits_even_when_no_result(self):
self.assertEqual(0, search.get('hits').get('total'))
self.assertListEqual([], search.get('hits').get('hits'))

def test_should_return_skipped_shards(self):
search = self.es.search()
self.assertEqual(0, search.get('_shards').get('skipped'))

def test_should_return_all_documents(self):
index_quantity = 10
for i in range(0, index_quantity):
Expand Down