From 4be0f72bd5a88a6b03bb40a2e741fda67ec98627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Kr=C3=A1l?= Date: Tue, 17 Dec 2019 22:31:06 +0100 Subject: [PATCH] Special cases for doc-based APIs --- generate_api.py | 21 +++++++++++++++++++++ test_elasticsearch/test_client/__init__.py | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/generate_api.py b/generate_api.py index 4f4243b1..2c7aa9bc 100644 --- a/generate_api.py +++ b/generate_api.py @@ -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, diff --git a/test_elasticsearch/test_client/__init__.py b/test_elasticsearch/test_client/__init__.py index 4cd410a6..8e0c67ca 100644 --- a/test_elasticsearch/test_client/__init__.py +++ b/test_elasticsearch/test_client/__init__.py @@ -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")