Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Dropbox listdir optionally recursive #3260

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused why the input path appears in the results during recursive=True, but not when recursive=False. Is that expected behavior for the underlying api call?

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
Loading