forked from TrueCloudLab/frostfs-testlib
Compare commits
No commits in common. "extend-multipart-testsuite" and "master" have entirely different histories.
extend-mul
...
master
1 changed files with 29 additions and 19 deletions
|
@ -38,34 +38,34 @@ def get_via_http_gate(
|
|||
"""
|
||||
This function gets given object from HTTP gate
|
||||
cid: container id to get object from
|
||||
oid: object id / object key
|
||||
oid: object ID
|
||||
node: node to make request
|
||||
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:
|
||||
# if `request_path` parameter omitted, use default
|
||||
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}"
|
||||
|
||||
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(
|
||||
f"""Failed to get object via HTTP gate:
|
||||
request: {response.request.path_url},
|
||||
response: {response.text},
|
||||
headers: {response.headers},
|
||||
status code: {response.status_code} {response.reason}"""
|
||||
request: {resp.request.path_url},
|
||||
response: {resp.text},
|
||||
headers: {resp.headers},
|
||||
status code: {resp.status_code} {resp.reason}"""
|
||||
)
|
||||
|
||||
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}"))
|
||||
with open(test_file, "wb") as file:
|
||||
for chunk in response.iter_content(chunk_size=8192):
|
||||
file.write(chunk)
|
||||
|
||||
shutil.copyfileobj(resp.raw, file)
|
||||
return test_file
|
||||
|
||||
|
||||
|
@ -117,12 +117,12 @@ def get_via_http_gate_by_attribute(
|
|||
endpoint: http gate endpoint
|
||||
request_path: (optional) http request path, if ommited - use default [{endpoint}/get_by_attribute/{Key}/{Value}]
|
||||
"""
|
||||
|
||||
attr_name = list(attribute.keys())[0]
|
||||
attr_value = quote_plus(str(attribute.get(attr_name)))
|
||||
|
||||
request = f"{node.http_gate.get_endpoint()}/get_by_attribute/{cid}/{quote_plus(str(attr_name))}/{attr_value}"
|
||||
if request_path:
|
||||
# if `request_path` parameter ommited, use default
|
||||
if request_path is None:
|
||||
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}"
|
||||
|
||||
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:
|
||||
try:
|
||||
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:
|
||||
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}")
|
||||
except Exception as err:
|
||||
match = error_pattern.casefold() in str(err).casefold()
|
||||
|
|
Loading…
Reference in a new issue