From 42752953ecdd84a3247930ff8f411c80839d06fd Mon Sep 17 00:00:00 2001 From: Seth Michael Larson Date: Mon, 25 Jan 2021 08:44:39 -0600 Subject: [PATCH] [7.x] Implement 'contains' feature for REST API tests Co-authored-by: P. Sai Vinay <33659563+V1NAY8@users.noreply.github.com> --- test_elasticsearch/test_server/test_rest_api_spec.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test_elasticsearch/test_server/test_rest_api_spec.py b/test_elasticsearch/test_server/test_rest_api_spec.py index 8ab65b65..2feae0d8 100644 --- a/test_elasticsearch/test_server/test_rest_api_spec.py +++ b/test_elasticsearch/test_server/test_rest_api_spec.py @@ -50,6 +50,7 @@ IMPLEMENTED_FEATURES = { "default_shards", "warnings", "allowed_warnings", + "contains", } # broken YAML tests on some releases @@ -276,6 +277,14 @@ class YamlRunner: else: assert expected == value, "%r does not match %r" % (value, expected) + def run_contains(self, action): + for path, expected in action.items(): + value = self._lookup(path) # list[dict[str,str]] is returned + expected = self._resolve(expected) # dict[str, str] + + if expected not in value: + raise AssertionError("%s is not contained by %s" % (expected, value)) + def _resolve(self, value): # resolve variables if isinstance(value, string_types) and value.startswith("$"):