Skip to content

Commit b6e460b

Browse files
Add global variable support to YAML test expression parser
1 parent 1a0dae5 commit b6e460b

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

test_elasticsearch/test_server/test_rest_api_spec.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,16 +411,21 @@ def _resolve(self, value):
411411
return value
412412

413413
def _lookup(self, path):
414-
# fetch the possibly nested value from last_response
415-
value = self.last_response
416414
if path == "$body":
417-
return value
415+
return self.last_response
416+
if path.startswith("$"):
417+
value = None
418+
else:
419+
value = self.last_response
418420
path = path.replace(r"\.", "\1")
419421
for step in path.split("."):
420422
if not step:
421423
continue
422424
# We check body again to handle E.g. '$body.$backing_index.data_stream'
423-
if step.startswith("$body"):
425+
if step == "$body":
426+
assert value is None
427+
# fetch the possibly nested value from last_response
428+
value = self.last_response
424429
continue
425430
step = step.replace("\1", ".")
426431
step = self._resolve(step)
@@ -432,11 +437,15 @@ def _lookup(self, path):
432437
step = int(step)
433438
assert isinstance(value, list)
434439
assert len(value) > step
440+
value = value[step]
435441
elif step == "_arbitrary_key_":
436442
return list(value.keys())[0]
437-
else:
443+
elif isinstance(step, string_types) and isinstance(value, dict):
438444
assert step in value
439-
value = value[step]
445+
value = value[step]
446+
else:
447+
assert value is None
448+
value = step
440449
return value
441450

442451
def _feature_enabled(self, name):

0 commit comments

Comments
 (0)