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 default value to doc_type in index method as it is by default set to '_doc' #27

Merged
merged 2 commits into from
Oct 6, 2019
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: 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