Special cases for doc-based APIs

This commit is contained in:
Honza Král
2019-12-17 22:31:06 +01:00
committed by Honza Král
parent 592372bc52
commit 4be0f72bd5
2 changed files with 22 additions and 1 deletions
+21
View File
@@ -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,
+1 -1
View File
@@ -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")