Skip to content

Commit 37d96c5

Browse files
Add global variable support to YAML test expression parser (#3196) (#3204)
(cherry picked from commit 42f1834) Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
1 parent c0b34de commit 37d96c5

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
@@ -409,16 +409,21 @@ def _resolve(self, value):
409409
return value
410410

411411
def _lookup(self, path):
412-
# fetch the possibly nested value from last_response
413-
value = self.last_response
414412
if path == "$body":
415-
return value
413+
return self.last_response
414+
if path.startswith("$"):
415+
value = None
416+
else:
417+
value = self.last_response
416418
path = path.replace(r"\.", "\1")
417419
for step in path.split("."):
418420
if not step:
419421
continue
420422
# We check body again to handle E.g. '$body.$backing_index.data_stream'
421-
if step.startswith("$body"):
423+
if step == "$body":
424+
assert value is None
425+
# fetch the possibly nested value from last_response
426+
value = self.last_response
422427
continue
423428
step = step.replace("\1", ".")
424429
step = self._resolve(step)
@@ -430,11 +435,15 @@ def _lookup(self, path):
430435
step = int(step)
431436
assert isinstance(value, list)
432437
assert len(value) > step
438+
value = value[step]
433439
elif step == "_arbitrary_key_":
434440
return list(value.keys())[0]
435-
else:
441+
elif isinstance(step, string_types) and isinstance(value, dict):
436442
assert step in value
437-
value = value[step]
443+
value = value[step]
444+
else:
445+
assert value is None
446+
value = step
438447
return value
439448

440449
def _feature_enabled(self, name):

0 commit comments

Comments
 (0)