Compare commits
1 commit
master
...
extend-mul
Author | SHA1 | Date | |
---|---|---|---|
0479701258 |
1 changed files with 19 additions and 29 deletions
|
@ -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
|
oid: object id / object key
|
||||||
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}]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# if `request_path` parameter omitted, use default
|
request = f"{node.http_gate.get_endpoint()}/get/{cid}/{oid}"
|
||||||
if request_path is None:
|
if request_path:
|
||||||
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}"
|
||||||
|
|
||||||
resp = requests.get(request, stream=True, timeout=timeout, verify=False)
|
response = requests.get(request, stream=True, timeout=timeout, verify=False)
|
||||||
|
|
||||||
if not resp.ok:
|
if not response.ok:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"""Failed to get object via HTTP gate:
|
f"""Failed to get object via HTTP gate:
|
||||||
request: {resp.request.path_url},
|
request: {response.request.path_url},
|
||||||
response: {resp.text},
|
response: {response.text},
|
||||||
headers: {resp.headers},
|
headers: {response.headers},
|
||||||
status code: {resp.status_code} {resp.reason}"""
|
status code: {response.status_code} {response.reason}"""
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info(f"Request: {request}")
|
logger.info(f"Request: {request}")
|
||||||
_attach_allure_step(request, resp.status_code)
|
_attach_allure_step(request, response.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:
|
||||||
shutil.copyfileobj(resp.raw, file)
|
for chunk in response.iter_content(chunk_size=8192):
|
||||||
|
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
|
|
||||||
if request_path is None:
|
request = f"{node.http_gate.get_endpoint()}/get_by_attribute/{cid}/{quote_plus(str(attr_name))}/{attr_value}"
|
||||||
request = f"{node.http_gate.get_endpoint()}/get_by_attribute/{cid}/{quote_plus(str(attr_name))}/{attr_value}"
|
if request_path:
|
||||||
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,19 +357,9 @@ 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(
|
get_via_http_gate(cid, oid, node, http_request_path)
|
||||||
cid=cid,
|
|
||||||
oid=oid,
|
|
||||||
node=node,
|
|
||||||
request_path=http_request_path,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
get_via_http_gate_by_attribute(
|
get_via_http_gate_by_attribute(cid, attrs, node, http_request_path)
|
||||||
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()
|
||||||
|
|
Loading…
Reference in a new issue