Special cases for doc-based APIs
This commit is contained in:
@@ -102,6 +102,16 @@ OVERRIDE_TEMPLATES = {
|
||||
return False
|
||||
{% endblock %}
|
||||
""",
|
||||
"__init__.index": """
|
||||
{% extends "base" %}
|
||||
{% block request %}
|
||||
if doc_type is None:
|
||||
doc_type = "_doc"
|
||||
|
||||
|
||||
return self.transport.perform_request("POST" if id in SKIP_IN_PATH else "PUT", {% include "url" %}, params=params, body=body)
|
||||
{% endblock %}
|
||||
""",
|
||||
"__init__.scroll": """
|
||||
{% extends "base" %}
|
||||
{% block request %}
|
||||
@@ -130,6 +140,17 @@ OVERRIDE_TEMPLATES = {
|
||||
""",
|
||||
}
|
||||
|
||||
for op in ("get", "delete", "exists"):
|
||||
OVERRIDE_TEMPLATES[f"__init__.{op}"] = """
|
||||
{% extends "base" %}
|
||||
{% block request %}
|
||||
if doc_type is None:
|
||||
doc_type = "_doc"
|
||||
|
||||
{{ super()|trim }}
|
||||
{% endblock %}
|
||||
"""
|
||||
|
||||
jinja_env = Environment(
|
||||
loader=ChoiceLoader((DictLoader(OVERRIDE_TEMPLATES), DictLoader(BASE_TEMPLATES))),
|
||||
trim_blocks=True,
|
||||
|
||||
@@ -96,4 +96,4 @@ class TestClient(ElasticsearchTestCase):
|
||||
def test_index_uses_put_if_id_is_not_empty(self):
|
||||
self.client.index(index="my-index", id=0, body={})
|
||||
|
||||
self.assert_url_called("POST", "/my-index/_doc/0")
|
||||
self.assert_url_called("PUT", "/my-index/_doc/0")
|
||||
|
||||
Reference in New Issue
Block a user