Fix for object range content tests
Signed-off-by: anikeev-yadro <a.anikeev@yadro.com>
This commit is contained in:
parent
f70dc9d648
commit
f47a9d09ec
2 changed files with 20 additions and 6 deletions
|
@ -78,6 +78,9 @@ def get_file_hash(file_path: str, len: Optional[int] = None, offset: Optional[in
|
|||
elif len and offset:
|
||||
out.seek(offset, 0)
|
||||
file_hash.update(out.read(len))
|
||||
elif offset and not len:
|
||||
out.seek(offset, 0)
|
||||
file_hash.update(out.read())
|
||||
else:
|
||||
file_hash.update(out.read())
|
||||
return file_hash.hexdigest()
|
||||
|
@ -133,7 +136,9 @@ def split_file(file_path: str, parts: int) -> list[str]:
|
|||
return part_file_paths
|
||||
|
||||
|
||||
def get_file_content(file_path: str, content_len: Optional[int] = None, mode: str = "r") -> Any:
|
||||
def get_file_content(
|
||||
file_path: str, content_len: Optional[int] = None, mode: str = "r", offset: Optional[int] = None
|
||||
) -> Any:
|
||||
"""Returns content of specified file.
|
||||
|
||||
Args:
|
||||
|
@ -141,13 +146,20 @@ def get_file_content(file_path: str, content_len: Optional[int] = None, mode: st
|
|||
content_len: Limit of content length. If None, then entire file content is returned;
|
||||
otherwise only the first content_len bytes of the content are returned.
|
||||
mode: Mode of opening the file.
|
||||
offset: Position to start reading from.
|
||||
|
||||
Returns:
|
||||
Content of the specified file.
|
||||
"""
|
||||
with open(file_path, mode) as file:
|
||||
if content_len:
|
||||
if content_len and not offset:
|
||||
content = file.read(content_len)
|
||||
elif content_len and offset:
|
||||
file.seek(offset, 0)
|
||||
content = file.read(content_len)
|
||||
elif offset and not content_len:
|
||||
file.seek(offset, 0)
|
||||
content = file.read()
|
||||
else:
|
||||
content = file.read()
|
||||
|
||||
|
|
|
@ -45,8 +45,9 @@ def test_object_api(prepare_wallet_and_deposit, client_shell, request, object_si
|
|||
file_usr_header = {"key1": 1, "key2": "abc", "common_key": "common_value"}
|
||||
file_usr_header_oth = {"key1": 2, "common_key": "common_value"}
|
||||
common_header = {"common_key": "common_value"}
|
||||
range_offset = 0
|
||||
range_len = 10
|
||||
range_cut = f"0:{range_len}"
|
||||
range_cut = f"{range_offset}:{range_len}"
|
||||
file_path = generate_file(object_size)
|
||||
file_hash = get_file_hash(file_path)
|
||||
|
||||
|
@ -98,21 +99,22 @@ def test_object_api(prepare_wallet_and_deposit, client_shell, request, object_si
|
|||
**wallet_cid, oid=oids[0], shell=client_shell, range_cut=range_cut
|
||||
)
|
||||
assert (
|
||||
get_file_hash(file_path, range_len) == range_hash
|
||||
get_file_hash(file_path, range_len, range_offset) == range_hash
|
||||
), f"Expected range hash to match {range_cut} slice of file payload"
|
||||
|
||||
range_hash = get_range_hash(
|
||||
**wallet_cid, oid=oids[1], shell=client_shell, range_cut=range_cut
|
||||
)
|
||||
assert (
|
||||
get_file_hash(file_path, range_len) == range_hash
|
||||
get_file_hash(file_path, range_len, range_offset) == range_hash
|
||||
), f"Expected range hash to match {range_cut} slice of file payload"
|
||||
|
||||
_, range_content = get_range(
|
||||
**wallet_cid, oid=oids[1], shell=client_shell, range_cut=range_cut
|
||||
)
|
||||
assert (
|
||||
get_file_content(file_path, content_len=range_len, mode="rb") == range_content
|
||||
get_file_content(file_path, content_len=range_len, mode="rb", offset=range_offset)
|
||||
== range_content
|
||||
), f"Expected range content to match {range_cut} slice of file payload"
|
||||
|
||||
with allure.step("Search objects"):
|
||||
|
|
Loading…
Reference in a new issue