@@ -252,7 +252,8 @@ class Elasticsearch(object):
|
|||||||
for param in (index, doc_type, body):
|
for param in (index, doc_type, body):
|
||||||
if param in SKIP_IN_PATH:
|
if param in SKIP_IN_PATH:
|
||||||
raise ValueError("Empty value passed for a required argument.")
|
raise ValueError("Empty value passed for a required argument.")
|
||||||
_, data = self.transport.perform_request('PUT' if id else 'POST',
|
method = 'POST' if id in SKIP_IN_PATH else 'PUT'
|
||||||
|
_, data = self.transport.perform_request(method,
|
||||||
_make_path(index, doc_type, id), params=params, body=body)
|
_make_path(index, doc_type, id), params=params, body=body)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|||||||
@@ -68,3 +68,13 @@ class TestClient(ElasticsearchTestCase):
|
|||||||
def test_repr_truncates_host_to_10(self):
|
def test_repr_truncates_host_to_10(self):
|
||||||
hosts = [{"host": "es" + str(i)} for i in range(20)]
|
hosts = [{"host": "es" + str(i)} for i in range(20)]
|
||||||
self.assertNotIn("es5", repr(Elasticsearch(hosts)))
|
self.assertNotIn("es5", repr(Elasticsearch(hosts)))
|
||||||
|
|
||||||
|
def test_index_uses_post_if_id_is_empty(self):
|
||||||
|
self.client.index(index='my-index', doc_type='test-doc', id='', body={})
|
||||||
|
|
||||||
|
self.assert_url_called('POST', '/my-index/test-doc')
|
||||||
|
|
||||||
|
def test_index_uses_put_if_id_is_not_empty(self):
|
||||||
|
self.client.index(index='my-index', doc_type='test-doc', id=0, body={})
|
||||||
|
|
||||||
|
self.assert_url_called('PUT', '/my-index/test-doc/0')
|
||||||
|
|||||||
Reference in New Issue
Block a user