Skip to content

Commit

Permalink
Merge pull request #56 from flaxandteal/feature/skipped-shards
Browse files Browse the repository at this point in the history
Add shards skipped to search and count
  • Loading branch information
vrcmarcos authored Dec 31, 2020
2 parents f91029f + 7c8efed commit 90d5135
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
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

0 comments on commit 90d5135

Please sign in to comment.