Skip to content

Commit

Permalink
De-duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
ggediminass committed Dec 20, 2024
1 parent b2a97d3 commit e86618a
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions test/qa/lib/fileshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,29 +331,18 @@ def files_from_transfer_exist_in_filesystem(transfer_id: str, dir_list: list[Dir
Returns:
bool: True if all files in the transfer are found in `dir_list` based on their hashes; False otherwise.
"""
if ssh_client is not None:
transfers = ssh_client.exec_command("nordvpn fileshare list")
download_location = find_transfer_by_id(transfers, transfer_id).split()[-1]

files_in_transfer = [line.split()[0] for line in ssh_client.exec_command(f"nordvpn fileshare list {transfer_id}").split("\n") if "downloaded" in line]
for file in files_in_transfer:
try:
file_hash = ssh_client.io.get_file_hash(f"{download_location}/{file}")
assert any(file_hash in directory.filehashes for directory in dir_list)
except RuntimeError:
return False
else:
transfers = sh.nordvpn.fileshare.list(_tty_out=False)
download_location = find_transfer_by_id(transfers, transfer_id).split()[-1]

files_in_transfer = [line.split()[0] for line in sh.nordvpn.fileshare.list(transfer_id, tty_out=False).split("\n") if "downloaded" in line]
for file in files_in_transfer:
try:
hash_util = sh.Command(FILE_HASH_UTILITY)
file_hash = hash_util(f"{download_location}/{file}").strip().split()[0]
assert any(file_hash in directory.filehashes for directory in dir_list)
except RuntimeError:
return False
exec_command = CommandExecutor(ssh_client) if ssh_client is not None else CommandExecutor()

transfers = exec_command("nordvpn fileshare list")
download_location = find_transfer_by_id(transfers, transfer_id).split()[-1]

files_in_transfer = [line.split()[0] for line in exec_command(f"nordvpn fileshare list {transfer_id}").split("\n") if "downloaded" in line]
for file in files_in_transfer:
try:
file_hash = exec_command(f"{FILE_HASH_UTILITY} {download_location}/{file}").split()[0]
assert any(file_hash in directory.filehashes for directory in dir_list)
except: # noqa: E722
return False
return True


Expand Down

0 comments on commit e86618a

Please sign in to comment.