Skip to content

Commit

Permalink
Fix #34
Browse files Browse the repository at this point in the history
  • Loading branch information
vrcmarcos committed Feb 17, 2020
1 parent 30c9d8d commit 2036581
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions elasticmock/fake_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def index(self, index, body, doc_type='_doc', id=None, params=None):

if id is None:
id = get_random_id()
else:
doc = self.get(index, id, doc_type)
elif self.exists(index, doc_type, id, params=params):
doc = self.get(index, id, doc_type, params=params)
version = doc['_version'] + 1
delete_response = self.delete(index, doc_type, id)
self.delete(index, doc_type, id)

self.__documents_dict[index].append({
'_type': doc_type,
Expand All @@ -75,7 +75,7 @@ def index(self, index, body, doc_type='_doc', id=None, params=None):

@query_params('consistency', 'op_type', 'parent', 'refresh', 'replication',
'routing', 'timeout', 'timestamp', 'ttl', 'version', 'version_type')
def bulk(self, body, params=None):
def bulk(self, body, index=None, doc_type=None, params=None):
version = 1
items = []

Expand Down
10 changes: 8 additions & 2 deletions tests/test_elasticmock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import json
import unittest
from datetime import datetime

import elasticsearch
from elasticsearch.exceptions import NotFoundError

Expand All @@ -15,7 +17,11 @@ def setUp(self):
self.es = elasticsearch.Elasticsearch(hosts=[{'host': 'localhost', 'port': 9200}])
self.index_name = 'test_index'
self.doc_type = 'doc-Type'
self.body = {'string': 'content', 'id': 1}
self.body = {
'author': 'kimchy',
'text': 'Elasticsearch: cool. bonsai cool.',
'timestamp': datetime.now(),
}
self.updated_body = {'string': 'content-updated', 'id': 1}

def test_should_create_fake_elasticsearch_instance(self):
Expand All @@ -32,7 +38,7 @@ def test_should_index_document(self):
def test_should_bulk_index_documents(self):
action = {'index': {'_index': self.index_name, '_type': self.doc_type}}
action_json = json.dumps(action)
body_json = json.dumps(self.body)
body_json = json.dumps(self.body, default=str)
num_of_documents = 10

lines = []
Expand Down

0 comments on commit 2036581

Please sign in to comment.