Skip to content

Commit

Permalink
Make Dropbox listdir optionally recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
smrohrer committed Oct 28, 2023
1 parent fe7ecf4 commit 1e0ca7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions luigi/contrib/dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ def isdir(self, path):
raise e

@accept_trailing_slash_in_existing_dirpaths
def listdir(self, path, **kwargs):
def listdir(self, path, recursive=True, **kwargs):

Check warning on line 136 in luigi/contrib/dropbox.py

View check run for this annotation

Codecov / codecov/patch

luigi/contrib/dropbox.py#L136

Added line #L136 was not covered by tests
dirs = []
lister = self.conn.files_list_folder(path, recursive=True, **kwargs)
lister = self.conn.files_list_folder(path, recursive, **kwargs)

Check warning on line 138 in luigi/contrib/dropbox.py

View check run for this annotation

Codecov / codecov/patch

luigi/contrib/dropbox.py#L138

Added line #L138 was not covered by tests
dirs.extend(lister.entries)
while lister.has_more:
lister = self.conn.files_list_folder_continue(lister.cursor)
Expand Down
20 changes: 17 additions & 3 deletions test/contrib/dropbox_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,33 @@ def test_listdir_simple(self):
list_of_dirs = self.luigiconn.listdir(DROPBOX_TEST_PATH)
self.assertTrue('/' not in list_of_dirs)
self.assertTrue(DROPBOX_TEST_PATH in list_of_dirs)
self.assertTrue(DROPBOX_TEST_SIMPLE_FILE in list_of_dirs) # we verify recursivity
self.assertTrue(DROPBOX_TEST_SIMPLE_DIR in list_of_dirs)
self.assertTrue(DROPBOX_TEST_SIMPLE_FILE in list_of_dirs)
self.assertTrue(DROPBOX_TEST_FILE_IN_DIR in list_of_dirs) # we verify recursivity

def test_listdir_simple_with_one_slash(self):
list_of_dirs = self.luigiconn.listdir(DROPBOX_TEST_PATH + '/')
self.assertTrue('/' not in list_of_dirs)
self.assertTrue(DROPBOX_TEST_PATH in list_of_dirs)
self.assertTrue(DROPBOX_TEST_SIMPLE_FILE in list_of_dirs) # we verify recursivity
self.assertTrue(DROPBOX_TEST_SIMPLE_DIR in list_of_dirs)
self.assertTrue(DROPBOX_TEST_SIMPLE_FILE in list_of_dirs)
self.assertTrue(DROPBOX_TEST_FILE_IN_DIR in list_of_dirs) # we verify recursivity

def test_listdir_multiple(self):
list_of_dirs = self.luigiconn.listdir(DROPBOX_TEST_PATH, limit=2)
self.assertTrue('/' not in list_of_dirs)
self.assertTrue(DROPBOX_TEST_PATH in list_of_dirs)
self.assertTrue(DROPBOX_TEST_SIMPLE_FILE in list_of_dirs) # we verify recursivity
self.assertTrue(DROPBOX_TEST_SIMPLE_DIR in list_of_dirs)
self.assertTrue(DROPBOX_TEST_SIMPLE_FILE in list_of_dirs)
self.assertTrue(DROPBOX_TEST_FILE_IN_DIR in list_of_dirs) # we verify recursivity

def test_listdir_non_recursive(self):
list_of_dirs = self.luigiconn.listdir(DROPBOX_TEST_PATH, recursive=False)
self.assertTrue('/' not in list_of_dirs)
self.assertTrue(DROPBOX_TEST_PATH not in list_of_dirs)
self.assertTrue(DROPBOX_TEST_SIMPLE_DIR in list_of_dirs)
self.assertTrue(DROPBOX_TEST_SIMPLE_FILE in list_of_dirs)
self.assertTrue(DROPBOX_TEST_FILE_IN_DIR not in list_of_dirs)

def test_listdir_nonexisting(self):
with self.assertRaises(dropbox.exceptions.ApiError):
Expand Down

0 comments on commit 1e0ca7a

Please sign in to comment.