Compare commits

..

No commits in common. "extend-multipart-testsuite" and "master" have entirely different histories.

View file

@ -38,34 +38,34 @@ def get_via_http_gate(
""" """
This function gets given object from HTTP gate This function gets given object from HTTP gate
cid: container id to get object from cid: container id to get object from
oid: object id / object key oid: object ID
node: node to make request node: node to make request
request_path: (optional) http request, if ommited - use default [{endpoint}/get/{cid}/{oid}] request_path: (optional) http request, if ommited - use default [{endpoint}/get/{cid}/{oid}]
""" """
request = f"{node.http_gate.get_endpoint()}/get/{cid}/{oid}" # if `request_path` parameter omitted, use default
if request_path: if request_path is None:
request = f"{node.http_gate.get_endpoint()}/get/{cid}/{oid}"
else:
request = f"{node.http_gate.get_endpoint()}{request_path}" request = f"{node.http_gate.get_endpoint()}{request_path}"
response = requests.get(request, stream=True, timeout=timeout, verify=False) resp = requests.get(request, stream=True, timeout=timeout, verify=False)
if not response.ok: if not resp.ok:
raise Exception( raise Exception(
f"""Failed to get object via HTTP gate: f"""Failed to get object via HTTP gate:
request: {response.request.path_url}, request: {resp.request.path_url},
response: {response.text}, response: {resp.text},
headers: {response.headers}, headers: {resp.headers},
status code: {response.status_code} {response.reason}""" status code: {resp.status_code} {resp.reason}"""
) )
logger.info(f"Request: {request}") logger.info(f"Request: {request}")
_attach_allure_step(request, response.status_code) _attach_allure_step(request, resp.status_code)
test_file = TestFile(os.path.join(os.getcwd(), ASSETS_DIR, f"{cid}_{oid}")) test_file = TestFile(os.path.join(os.getcwd(), ASSETS_DIR, f"{cid}_{oid}"))
with open(test_file, "wb") as file: with open(test_file, "wb") as file:
for chunk in response.iter_content(chunk_size=8192): shutil.copyfileobj(resp.raw, file)
file.write(chunk)
return test_file return test_file
@ -117,12 +117,12 @@ def get_via_http_gate_by_attribute(
endpoint: http gate endpoint endpoint: http gate endpoint
request_path: (optional) http request path, if ommited - use default [{endpoint}/get_by_attribute/{Key}/{Value}] request_path: (optional) http request path, if ommited - use default [{endpoint}/get_by_attribute/{Key}/{Value}]
""" """
attr_name = list(attribute.keys())[0] attr_name = list(attribute.keys())[0]
attr_value = quote_plus(str(attribute.get(attr_name))) attr_value = quote_plus(str(attribute.get(attr_name)))
# if `request_path` parameter ommited, use default
request = f"{node.http_gate.get_endpoint()}/get_by_attribute/{cid}/{quote_plus(str(attr_name))}/{attr_value}" if request_path is None:
if request_path: request = f"{node.http_gate.get_endpoint()}/get_by_attribute/{cid}/{quote_plus(str(attr_name))}/{attr_value}"
else:
request = f"{node.http_gate.get_endpoint()}{request_path}" request = f"{node.http_gate.get_endpoint()}{request_path}"
resp = requests.get(request, stream=True, timeout=timeout, verify=False) resp = requests.get(request, stream=True, timeout=timeout, verify=False)
@ -357,9 +357,19 @@ def try_to_get_object_via_passed_request_and_expect_error(
) -> None: ) -> None:
try: try:
if attrs is None: if attrs is None:
get_via_http_gate(cid, oid, node, http_request_path) get_via_http_gate(
cid=cid,
oid=oid,
node=node,
request_path=http_request_path,
)
else: else:
get_via_http_gate_by_attribute(cid, attrs, node, http_request_path) get_via_http_gate_by_attribute(
cid=cid,
attribute=attrs,
node=node,
request_path=http_request_path,
)
raise AssertionError(f"Expected error on getting object with cid: {cid}") raise AssertionError(f"Expected error on getting object with cid: {cid}")
except Exception as err: except Exception as err:
match = error_pattern.casefold() in str(err).casefold() match = error_pattern.casefold() in str(err).casefold()