From ac6b1e95682b195dbef417f0b2224e5f54bf6c7e Mon Sep 17 00:00:00 2001 From: Maksim Gelbakhiani Date: Sun, 21 Jan 2024 19:05:05 +0100 Subject: [PATCH] Changed RE parsing added JSON parsing for Curl upload output fixes https://github.com/nspcc-dev/neofs-testlib/issues/83 Signed-off-by: Maksim Gelbakhiani --- .../resources/lib/python_keywords/http_gate.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/robot/resources/lib/python_keywords/http_gate.py b/robot/resources/lib/python_keywords/http_gate.py index 07cbbcbb7..488a745d9 100644 --- a/robot/resources/lib/python_keywords/http_gate.py +++ b/robot/resources/lib/python_keywords/http_gate.py @@ -1,4 +1,5 @@ import base64 +import json import logging import os import random @@ -240,11 +241,19 @@ def upload_via_http_gate_curl( assert match, f"Expected {output} to match {error_pattern}" return "" - oid_re = re.search(r'"object_id": "(.*)"', output) - if not oid_re: - raise AssertionError(f'Could not find "object_id" in {output}') - return oid_re.group(1) + json_match = re.search(r'{.*}', output, re.DOTALL | re.MULTILINE) + if not json_match: + raise AssertionError(f'Could not find JSON in {output}') + + json_str = json_match.group(0) + try: + response_json = json.loads(json_str) + except json.JSONDecodeError: + raise AssertionError(f'Invalid JSON response: {json_str}') + if 'object_id' not in response_json: + raise AssertionError(f'Could not find "object_id" in JSON response: {json_str}') + return response_json['object_id'] @allure.step("Get via HTTP Gate using Curl") def get_via_http_curl(cid: str, oid: str, endpoint: str) -> str: