Skip to content

Commit

Permalink
Merge pull request #27 from mohantyashish109/fix_index_mock_for_es7
Browse files Browse the repository at this point in the history
Add default value to doc_type in index method as it is by default set to '_doc'
  • Loading branch information
vrcmarcos authored Oct 6, 2019
2 parents 987f8c0 + e576f2c commit 4df0f86
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion elasticmock/fake_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def info(self, params=None):

@query_params('consistency', 'op_type', 'parent', 'refresh', 'replication',
'routing', 'timeout', 'timestamp', 'ttl', 'version', 'version_type')
def index(self, index, doc_type, body, id=None, params=None):
def index(self, index, body, doc_type='_doc', id=None, params=None):
if index not in self.__documents_dict:
self.__documents_dict[index] = list()

Expand Down
8 changes: 8 additions & 0 deletions tests/test_elasticmock.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ def test_should_index_document(self):
self.assertEqual(1, data.get('_version'))
self.assertEqual(self.index_name, data.get('_index'))

def test_should_index_document_without_doc_type(self):
data = self.es.index(index=self.index_name, body=self.body)

self.assertEqual('_doc', data.get('_type'))
self.assertTrue(data.get('created'))
self.assertEqual(1, data.get('_version'))
self.assertEqual(self.index_name, data.get('_index'))

def test_should_raise_notfounderror_when_nonindexed_id_is_used(self):
with self.assertRaises(NotFoundError):
self.es.get(index=self.index_name, id='1')
Expand Down

0 comments on commit 4df0f86

Please sign in to comment.