Skip to content

Commit

Permalink
Changed RE parsing added JSON parsing for Curl upload output
Browse files Browse the repository at this point in the history
fixes nspcc-dev/neofs-testlib#83

Signed-off-by: Maksim Gelbakhiani <[email protected]>
  • Loading branch information
Maksim Gelbakhiani committed Jan 21, 2024
1 parent 1500420 commit ac6b1e9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions robot/resources/lib/python_keywords/http_gate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import json
import logging
import os
import random
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ac6b1e9

Please sign in to comment.