当前位置: 首页>>代码示例>>Python>>正文


Python API.upload方法代码示例

本文整理汇总了Python中u115.api.API.upload方法的典型用法代码示例。如果您正苦于以下问题:Python API.upload方法的具体用法?Python API.upload怎么用?Python API.upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在u115.api.API的用法示例。


在下文中一共展示了API.upload方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DownloadTests

# 需要导入模块: from u115.api import API [as 别名]
# 或者: from u115.api.API import upload [as 别名]
class DownloadTests(TestCase):
    """
    Test download
    TODO: add more tests with different download argument
    """
    def setUp(self):
        # Initialize a new API instance
        self.api = API()
        self.api.login(section='test')
        if os.path.exists(TEST_DOWNLOAD_FILE):
            os.remove(TEST_DOWNLOAD_FILE)

    def test_download(self):
        # Clean up all files in the downloads directory
        downloads_directory = self.api.downloads_directory
        entries = downloads_directory.list()
        delete_entries(entries)
        # Upload a file
        uploaded_file = self.api.upload(TEST_UPLOAD_FILE)
        assert isinstance(uploaded_file, File)
        time.sleep(5)
        entries = downloads_directory.list()
        assert entries
        entry = entries[0]
        entry.download(path=pjoin(DOWNLOADS_DIR))
        delete_entries(entries)
开发者ID:duyamin,项目名称:115wangpan,代码行数:28,代码来源:test_api.py

示例2: UploadTests

# 需要导入模块: from u115.api import API [as 别名]
# 或者: from u115.api.API import upload [as 别名]
class UploadTests(TestCase):
    """Test upload"""
    def setUp(self):
        # Initialize a new API instance
        self.api = API()
        self.api.login(section='test')

    def test_upload_downloads_directory(self):
        """Upload to downloads directory (default)"""
        # Clean up all files in the downloads directory
        downloads_directory = self.api.downloads_directory
        entries = downloads_directory.list()
        delete_entries(entries)
        uploaded_file = self.api.upload(TEST_UPLOAD_FILE)
        assert isinstance(uploaded_file, File)
        time.sleep(5)
        entries = downloads_directory.list()
        assert entries
        entry = entries[0]
        assert entry.fid == uploaded_file.fid
        delete_entries(entries)
开发者ID:shichao-an,项目名称:115wangpan,代码行数:23,代码来源:test_api.py

示例3: FileTests

# 需要导入模块: from u115.api import API [as 别名]
# 或者: from u115.api.API import upload [as 别名]
class FileTests(TestCase):
    """Test file manipulation in downloads directory"""
    def setUp(self):
        # Initialize a new API instance
        self.api = API()
        self.api.login(section='test')

    def test_move_files(self):
        """Move files from downloads directory to its parent directory"""
        # Clean up all files in the downloads directory
        downloads_directory = self.api.downloads_directory
        entries = downloads_directory.list()
        delete_entries(entries)
        uploaded_file = self.api.upload(TEST_UPLOAD_FILE)
        assert isinstance(uploaded_file, File)
        time.sleep(5)
        entries = downloads_directory.list()
        assert entries
        entry = entries[0]
        assert entry.fid == uploaded_file.fid
        dest_dir = downloads_directory.parent
        assert self.api.move([entry], dest_dir)
        old_entry = entry
        assert old_entry.cid == dest_dir.cid
        for entry in dest_dir.list():
            if isinstance(entry, File):
                assert entry.fid == old_entry.fid
                break
        else:
            assert False
        # Test moving directories
        dir1 = self.api.mkdir(downloads_directory, TEST_EDIT_FILENAME)
        assert self.api.move([dir1], dest_dir)
        old_dir1 = dir1
        assert old_dir1.pid == dest_dir.cid
        for entry in dest_dir.list():
            if isinstance(entry, Directory):
                if entry != downloads_directory:
                    assert entry == old_dir1
                    break
        else:
            assert False
        entries = [
            entry for entry in dest_dir.list()
            if entry != downloads_directory
        ]
        delete_entries(entries)

    def test_edit_files(self):
        """Move files from downloads directory to its parent directory"""
        # Clean up all files in the downloads directory
        downloads_directory = self.api.downloads_directory
        entries = downloads_directory.list()
        delete_entries(entries)
        uploaded_file = self.api.upload(TEST_UPLOAD_FILE)
        assert isinstance(uploaded_file, File)
        time.sleep(5)
        entries = downloads_directory.list()
        assert entries
        entry = entries[0]
        assert entry.fid == uploaded_file.fid
        assert self.api.edit(entry, TEST_EDIT_FILENAME)
        edited_entry = downloads_directory.list()[0]
        assert edited_entry.name == TEST_EDIT_FILENAME

    def test_mkdir(self):
        # Clean up all files in the downloads directory
        downloads_directory = self.api.downloads_directory
        entries = downloads_directory.list()
        delete_entries(entries)
        new_dir = self.api.mkdir(downloads_directory, TEST_NEW_DIRNAME)
        assert new_dir.name == TEST_NEW_DIRNAME
        assert new_dir.parent == downloads_directory
        new_dir2 = downloads_directory.list()[0]
        assert new_dir2 == new_dir
        entries = downloads_directory.list()
        delete_entries(entries)
开发者ID:shichao-an,项目名称:115wangpan,代码行数:79,代码来源:test_api.py


注:本文中的u115.api.API.upload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。