Commit 0ff4cc72 authored by richardARPANET's avatar richardARPANET

wip

parent dc360ebe
......@@ -301,6 +301,10 @@ class Mega:
"""
Return file object from given filename
"""
def found(cloud_filename, search_filename):
return cloud_filename == search_filename
files = self.get_files()
if handle:
return files[handle]
......@@ -308,6 +312,12 @@ class Mega:
filename = path.name
parent_dir_name = path.parent.name
for file in list(files.items()):
try:
cloud_file_name = file[1]['a']['n']
cloud_file_parent_node_id = file[1]['p']
except (KeyError, TypeError):
logger.debug('Filename attribute not found, skipping %s', file)
continue
parent_node_id = None
if parent_dir_name:
parent_node_id = self.find_path_descriptor(
......@@ -315,22 +325,21 @@ class Mega:
)
if (
filename and parent_node_id and
file[1]['a'] and file[1]['a']['n'] == filename and
parent_node_id == file[1]['p']
found(cloud_file_name, filename) and
parent_node_id == cloud_file_parent_node_id
):
if (
exclude_deleted and
self._trash_folder_node_id == file[1]['p']
self._trash_folder_node_id == cloud_file_parent_node_id
):
continue
return file
if (
filename and
file[1]['a'] and file[1]['a']['n'] == filename
filename and found(cloud_file_name, filename)
):
if (
exclude_deleted and
self._trash_folder_node_id == file[1]['p']
self._trash_folder_node_id == cloud_file_parent_node_id
):
continue
return file
......
......@@ -20,7 +20,7 @@ def folder_name():
@pytest.fixture
def mega(folder_name):
mega_ = Mega()
mega_ = Mega({'verbose': True})
mega_.login(email=os.environ['EMAIL'], password=os.environ['PASS'])
created_nodes = mega_.create_folder(folder_name)
yield mega_
......@@ -154,6 +154,16 @@ class TestFind:
assert mega.find(path)
def test_find_file2(self, mega, folder_name):
folder = mega.find(folder_name)
dest_node_id = folder[1]['h']
mega.upload(
__file__, dest=dest_node_id, dest_filename='test.py'
)
path = f'{folder_name}/te*.py'
assert mega.find(path)
def test_path_not_found_returns_none(self, mega):
assert mega.find('not_found') is None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment