Exemplo n.º 1
0
    def test_path_root_err(self, dbx):
        # verify invalid namespace return is_no_permission error
        dbxpr = dbx.with_path_root(PathRoot.namespace_id("1234567890"))
        with self.assertRaises(PathRootError) as cm:
            dbxpr.files_list_folder('')
        self.assertTrue(cm.exception.error.is_no_permission())

        dbxpr = dbx.with_path_root(PathRoot.root("1234567890"))
        with self.assertRaises(PathRootError) as cm:
            dbxpr.files_list_folder('')
        self.assertTrue(cm.exception.error.is_invalid_root())
Exemplo n.º 2
0
    def test_path_root_err(self, dbx):
        # verify invalid namespace return is_no_permission error
        dbxpr = dbx.with_path_root(PathRoot.namespace_id("1234567890"))
        with self.assertRaises(PathRootError) as cm:
            dbxpr.files_list_folder('')
        self.assertTrue(cm.exception.error.is_no_permission())

        dbxpr = dbx.with_path_root(PathRoot.root("1234567890"))
        with self.assertRaises(PathRootError) as cm:
            dbxpr.files_list_folder('')
        self.assertTrue(cm.exception.error.is_invalid_root())
Exemplo n.º 3
0
    def test_path_root_err(self, dbx_from_env):
        # verify invalid namespace return is_no_permission error
        dbxpr = dbx_from_env.with_path_root(
            PathRoot.namespace_id("1234567890"))
        with pytest.raises(PathRootError) as cm:
            dbxpr.files_list_folder('')
        assert cm.value.error.is_no_permission()

        dbxpr = dbx_from_env.with_path_root(PathRoot.root("1234567890"))
        with pytest.raises(PathRootError) as cm:
            dbxpr.files_list_folder('')
        assert cm.value.error.is_invalid_root()
Exemplo n.º 4
0
    def test_path_root(self, dbx):
        root_info = dbx.users_get_current_account().root_info
        root_ns = root_info.root_namespace_id
        home_ns = root_info.home_namespace_id

        # verify home mode
        dbxpr = dbx.with_path_root(PathRoot.home)
        dbxpr.files_list_folder('')

        # verify root mode
        dbxpr = dbx.with_path_root(PathRoot.root(root_ns))
        dbxpr.files_list_folder('')

        # verify namespace_id mode
        dbxpr = dbx.with_path_root(PathRoot.namespace_id(home_ns))
        dbxpr.files_list_folder('')
Exemplo n.º 5
0
    def test_with_path_root_constructor(self, dbx):
        # Verify valid mode types
        for path_root in (
            PathRoot.home,
            PathRoot.root("123"),
            PathRoot.namespace_id("123"),
        ):
            dbx_new = dbx.with_path_root(path_root)
            self.assertIsNot(dbx_new, dbx)

            expected = stone_serializers.json_encode(PathRoot_validator, path_root)
            self.assertEqual(dbx_new._headers.get(PATH_ROOT_HEADER), expected)

        # verify invalid mode raises ValueError
        with self.assertRaises(ValueError):
            dbx.with_path_root(None)
Exemplo n.º 6
0
    def __init__(self, **kwargs):
        """Initializes DropBoxInterface instance, creates dbx instance
        :param kwargs:
        """
        # try to find token from given kwargs arguments or from os environment
        self.token = kwargs.pop('dropbox_token', None)
        self.root = kwargs.pop('dropbox_root', None)

        if not self.token:
            self.token = os.environ.get('DROPBOX_TOKEN')
        if self.root is None:
            self.root = str2bool(os.environ.get('DROPBOX_ROOT'))
        if not self.root:
            self.root = False

        if not self.token:
            raise ValueError('Please specify dropbox app access key')

        self._encoding = 'utf8'
        self._mode = None
        self._current_path = None
        self._write_mode = None
        self.metadata = None
        self.path = None
        self.list_recursive = False
        self.include_folders = False

        self.dbx = dropbox.Dropbox(self.token)

        # namespace id starts from root
        if self.root:
            root_namespace_id = self.dbx.users_get_current_account().root_info.root_namespace_id
            self.dbx = self.dbx.with_path_root(PathRoot.namespace_id(root_namespace_id))
Exemplo n.º 7
0
    def test_path_root(self, dbx):
        root_info = dbx.users_get_current_account().root_info
        root_ns = root_info.root_namespace_id
        home_ns = root_info.home_namespace_id

        # verify home mode
        dbxpr = dbx.with_path_root(PathRoot.home)
        dbxpr.files_list_folder('')

        # verify root mode
        dbxpr = dbx.with_path_root(PathRoot.root(root_ns))
        dbxpr.files_list_folder('')

        # verify namespace_id mode
        dbxpr = dbx.with_path_root(PathRoot.namespace_id(home_ns))
        dbxpr.files_list_folder('')
Exemplo n.º 8
0
    def test_with_path_root_constructor(self, dbx):
        # Verify valid mode types
        for path_root in (
            PathRoot.home,
            PathRoot.root("123"),
            PathRoot.namespace_id("123"),
        ):
            dbx_new = dbx.with_path_root(path_root)
            self.assertIsNot(dbx_new, dbx)

            expected = stone_serializers.json_encode(PathRoot_validator, path_root)
            self.assertEqual(dbx_new._headers.get(PATH_ROOT_HEADER), expected)

        # verify invalid mode raises ValueError
        with self.assertRaises(ValueError):
            dbx.with_path_root(None)
Exemplo n.º 9
0
    def test_with_path_root_constructor(self, dbx_from_env):
        # Verify valid mode types
        for path_root in (
                PathRoot.home,
                PathRoot.root("123"),
                PathRoot.namespace_id("123"),
        ):
            dbx_new = dbx_from_env.with_path_root(path_root)
            assert dbx_new is not dbx_from_env

            expected = stone_serializers.json_encode(PathRoot_validator,
                                                     path_root)
            assert dbx_new._headers.get(PATH_ROOT_HEADER) == expected

        # verify invalid mode raises ValueError
        with pytest.raises(ValueError):
            dbx_from_env.with_path_root(None)
Exemplo n.º 10
0
    def test_as_user(self, dbxt):
        dbx_as_user = dbxt.as_user('1')
        path_root = PathRoot.root("123")

        dbx_new = dbx_as_user.with_path_root(path_root)

        self.assertIsInstance(dbx_new, Dropbox)
        self.assertEqual(dbx_new._headers.get(SELECT_USER_HEADER), '1')

        expected = stone_serializers.json_encode(PathRoot_validator, path_root)
        self.assertEqual(dbx_new._headers.get(PATH_ROOT_HEADER), expected)
Exemplo n.º 11
0
    def test_as_user(self, dbx_team_from_env):
        dbx_as_user = dbx_team_from_env.as_user('1')
        path_root = PathRoot.root("123")

        dbx_new = dbx_as_user.with_path_root(path_root)

        assert isinstance(dbx_new, Dropbox)
        assert dbx_new._headers.get(SELECT_USER_HEADER) == '1'

        expected = stone_serializers.json_encode(PathRoot_validator, path_root)
        assert dbx_new._headers.get(PATH_ROOT_HEADER) == expected
Exemplo n.º 12
0
        isinstance(entry, dropbox.files.FolderMetadata)
        ):
            current_state[entry.path_lower] = entry
        elif isinstance(entry, dropbox.files.DeletedMetadata):
            current_state.pop(entry.path_lower, None)
    return current_state

# Initialize Dropbox API
user_dbx = dropbox.Dropbox("ACCESS TOKEN")

# get the root_namspace_id for this account
user_info = user_dbx.users_get_current_account()
root_ns = user_info.root_info.root_namespace_id

# update API client instance with new path root
user_dbx = user_dbx.with_path_root(PathRoot.root(root_ns))

print("Collecting files...")
result = user_dbx.files_list_folder(path="", recursive=True)
files = process_entries({}, result.entries)

# check for and collect any additional entries
while result.has_more:
    print("Collecting additional files...")
    result = user_dbx.files_list_folder_continue(result.cursor)
    files = process_entries(files, result.entries)

for entry in files.values():
    # Folders can have various ACLs in place that may limit access. Check the
    # ACLs before attempting to directly access content within a given folder
    if isinstance(entry, dropbox.files.FolderMetadata) and entry.sharing_info: