• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python api.API类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: PublicAPITests

class PublicAPITests(TestCase):
    """Test public methods"""
    def __init__(self, *args, **kwargs):
        """Initialize once for all test functions in this TestCase"""
        super(PublicAPITests, self).__init__(*args, **kwargs)
        self.api = API()
        self.api.login(section='test')

    def test_get_storage_info(self):
        storage_info = self.api.get_storage_info()
        assert 'total' in storage_info
        assert 'used' in storage_info

    def test_task_count(self):
        task_count = self.api.task_count
        assert isinstance(task_count, int)
        assert task_count >= 0

    def test_task_quota(self):
        task_quota = self.api.task_quota
        assert isinstance(task_quota, int)

    def test_get_user_info(self):
        user_info = self.api.get_user_info()
        assert isinstance(user_info, dict)

    def test_user_id(self):
        user_id = self.api.user_id
        assert int(user_id)

    def test_username(self):
        username = self.api.username
        assert isinstance(username, str)
开发者ID:shichao-an,项目名称:115wangpan,代码行数:33,代码来源:test_api.py


示例2: DownloadTests

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,代码行数:26,代码来源:test_api.py


示例3: DownloadsDirectoryTests

class DownloadsDirectoryTests(TestCase):
    """
    Test tasks and files within the downloads directory
    """
    def setUp(self):
        # Initialize a new API instance
        self.api = API()
        self.api.login(section='test')
        # Clean up all files in the downloads directory
        downloads_directory = self.api.downloads_directory
        entries = downloads_directory.list()
        delete_entries(entries)

    def test_transferred_task_directories(self):
        """
        Test the task with an associated directory
        """
        filename = TEST_TORRENT2['filename']
        info_hash = TEST_TORRENT2['info_hash']
        assert self.api.add_task_bt(filename)
        tasks = self.api.get_tasks()
        # Get the target task as `task`
        task = None
        for _task in tasks:
            if _task.info_hash == info_hash:
                task = _task
                break
        assert task
        # Wait until the task is transferred
        # Task.reload() must be implemented before wait_task_transferred()
        # can be used here
        #wait_task_transferred(task)
        assert task.status_human == 'TRANSFERRED'
        task_directory = task.directory
        entries = task_directory.list()
        dirs = []
        files = []
        for entry in entries:
            if isinstance(entry, File):
                files.append(entry)
            elif isinstance(entry, Directory):
                dirs.append(entry)
        assert len(dirs) == 2
        assert len(files) == 1
        for directory in dirs:
            if directory.name == 'BK':
                assert directory.count == 11
                assert len(directory.list()) == 11
            if directory.name == 'MP3':
                assert directory.count == 2
                assert len(directory.list()) == 2

    def tearDown(self):
        # Clean up all tasks
        tasks = self.api.get_tasks()
        delete_entries(tasks)
        # Clean up all files in the downloads directory
        downloads_directory = self.api.downloads_directory
        entries = downloads_directory.list()
        delete_entries(entries)
开发者ID:shichao-an,项目名称:115wangpan,代码行数:60,代码来源:test_api.py


示例4: TestCookies

class TestCookies(TestCase):
    def setUp(self):
        if os.path.exists(TEST_COOKIE_FILE):
            os.remove(TEST_COOKIE_FILE)
        self.api = API(auto_logout=False, persistent=True,
                       cookies_filename=TEST_COOKIE_FILE)
        self.api.login(section='test')

    def test_cookies(self):
        self.api.__del__()
        self.api = API(auto_logout=False, persistent=True,
                       cookies_filename=TEST_COOKIE_FILE)
        assert self.api.has_logged_in
开发者ID:mba811,项目名称:115wangpan,代码行数:13,代码来源:test_api.py


示例5: URLTaskTests

class URLTaskTests(TestCase):
    def setUp(self):
        # Initialize a new API instance
        self.api = API()
        self.api.login(section='test')
        # Clean up all tasks
        tasks = self.api.get_tasks()
        delete_entries(tasks)

    def test_add_task_url_http(self):
        """
        `API.add_task_url(target_url=HTTP)`
        """
        url = TEST_TARGET_URL1['url']
        info_hash = TEST_TARGET_URL1['info_hash']
        assert self.api.add_task_url(url)
        wait_task_transferred(self.api.get_tasks, info_hash)
        tasks = self.api.get_tasks()
        is_task_created(tasks, info_hash, False)

    def test_add_task_url_magnet(self):
        """
        `API.add_task_url(target_url=MAGNET)`
        """
        url = TEST_TARGET_URL2['url']
        info_hash = TEST_TARGET_URL2['info_hash']
        assert self.api.add_task_url(url)
        wait_task_transferred(self.api.get_tasks, info_hash)
        tasks = self.api.get_tasks()
        is_task_created(tasks, info_hash)

    def tearDown(self):
        # Clean up all tasks
        tasks = self.api.get_tasks()
        delete_entries(tasks)
开发者ID:shichao-an,项目名称:115wangpan,代码行数:35,代码来源:test_api.py


示例6: AuthTests

class AuthTests(TestCase):
    """
    Test login and logout
    """
    def setUp(self):
        # Initialize a new API instance
        self.api = API()
        self.api.login(section='test')

    def test_login(self):
        assert self.api.login(section='test')

    def test_logout(self):
        assert self.api.logout()
        assert not self.api.has_logged_in
开发者ID:shichao-an,项目名称:115wangpan,代码行数:15,代码来源:test_api.py


示例7: setUp

 def setUp(self):
     # Initialize a new API instance
     self.api = API()
     self.api.login(section='test')
     # Clean up all tasks
     tasks = self.api.get_tasks()
     delete_entries(tasks)
开发者ID:shichao-an,项目名称:115wangpan,代码行数:7,代码来源:test_api.py


示例8: TaskTests

class TaskTests(TestCase):
    """Test general task interface"""
    def setUp(self):
        # Initialize a new API instance
        self.api = API()
        self.api.login(section='test')

    def test_get_tasks(self):
        filename1 = TEST_TORRENT1['filename']
        filename2 = TEST_TORRENT2['filename']
        url1 = TEST_TARGET_URL1['url']
        url2 = TEST_TARGET_URL2['url']
        # Test creation
        assert self.api.add_task_bt(filename1)
        assert self.api.add_task_bt(filename2)
        assert self.api.add_task_url(url1)
        assert self.api.add_task_url(url2)
        # Test count
        tasks = self.api.get_tasks()
        assert len(tasks) == 4
        tasks = self.api.get_tasks(3)
        assert len(tasks) == 3

    def test_task_attrs(self):
        filename1 = TEST_TORRENT1['filename']
        url1 = TEST_TARGET_URL1['url']
        assert self.api.add_task_bt(filename1)
        assert self.api.add_task_url(url1)
        tasks = self.api.get_tasks()
        for task in tasks:
            assert isinstance(task.add_time, datetime.datetime)
            assert isinstance(task.last_update, datetime.datetime)
            assert isinstance(task.left_time, int)
            assert task.name
            assert task.move in [0, 1, 2]
            assert task.peers >= 0
            assert task.percent_done >= 0
            assert task.size >= 0
            assert task.size_human
            assert isinstance(task.status, int)
            assert task.status_human

    def tearDown(self):
        # Clean up all tasks
        tasks = self.api.get_tasks()
        for task in tasks:
            task.delete()
开发者ID:mba811,项目名称:115wangpan,代码行数:47,代码来源:test_api.py


示例9: TestPrivateAPI

class TestPrivateAPI(TestCase):
    def __init__(self, *args, **kwargs):
        super(TestPrivateAPI, self).__init__(*args, **kwargs)
        self.api = API()
        self.api.login(section='test')

    def test_req_offline_space(self):
        self.api._signatures = {}
        self.api._lixian_timestamp = None
        func = getattr(self.api, '_req_offline_space')
        func()
        assert 'offline_space' in self.api._signatures
        assert self.api._lixian_timestamp is not None

    def test_load_upload_url(self):
        url = self.api._load_upload_url()
        assert url
开发者ID:mba811,项目名称:115wangpan,代码行数:17,代码来源:test_api.py


示例10: CookiesTests

class CookiesTests(TestCase):
    """
    Test cookies
    """
    def setUp(self):
        if os.path.exists(TEST_COOKIE_FILE):
            os.remove(TEST_COOKIE_FILE)
        self.api = API(persistent=True,
                       cookies_filename=TEST_COOKIE_FILE)
        self.api.login(section='test')
        self.api.save_cookies()

    def test_cookies(self):
        self.api = API(persistent=True,
                       cookies_filename=TEST_COOKIE_FILE)
        assert self.api.has_logged_in

    def tearDown(self):
        if os.path.exists(TEST_COOKIE_FILE):
            os.remove(TEST_COOKIE_FILE)
开发者ID:shichao-an,项目名称:115wangpan,代码行数:20,代码来源:test_api.py


示例11: PrivateAPITests

class PrivateAPITests(TestCase):
    """
    Test private methods
    TODO: add more private methods for tests
    """
    def __init__(self, *args, **kwargs):
        super(PrivateAPITests, self).__init__(*args, **kwargs)
        self.api = API()
        self.api.login(section='test')

    def test_req_offline_space(self):
        self.api._signatures = {}
        self.api._lixian_timestamp = None
        func = getattr(self.api, '_req_offline_space')
        func()
        assert 'offline_space' in self.api._signatures
        assert self.api._lixian_timestamp is not None

    def test_load_upload_url(self):
        url = self.api._load_upload_url()
        assert url
开发者ID:shichao-an,项目名称:115wangpan,代码行数:21,代码来源:test_api.py


示例12: UploadTests

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,代码行数:21,代码来源:test_api.py


示例13: SearchTests

class SearchTests(TestCase):
    def setUp(self):
        # Initialize a new API instance
        self.api = API()
        self.api.login(section='test')
        # Clean up all files in the downloads directory
        downloads_directory = self.api.downloads_directory
        entries = downloads_directory.list()
        delete_entries(entries)
        # Create a task that is transferred
        filename = TEST_TORRENT2['filename']
        assert self.api.add_task_bt(filename)

    def test_search(self):
        keyword1 = '.jpg'
        count1 = 12
        result1 = self.api.search(keyword1)
        assert len(result1) == count1

        keyword2 = 'IMG_0004.jpg'
        count2 = 1
        result2 = self.api.search(keyword2)
        assert len(result2) == count2

        keyword3 = 'nothing'
        count3 = 0
        result3 = self.api.search(keyword3)
        assert len(result3) == count3

    def tearDown(self):
        # Clean up all tasks
        tasks = self.api.get_tasks()
        delete_entries(tasks)
        # Clean up all files in the downloads directory
        downloads_directory = self.api.downloads_directory
        entries = downloads_directory.list()
        delete_entries(entries)
开发者ID:shichao-an,项目名称:115wangpan,代码行数:37,代码来源:test_api.py


示例14: test_cookies

 def test_cookies(self):
     self.api = API(persistent=True,
                    cookies_filename=TEST_COOKIE_FILE)
     assert self.api.has_logged_in
开发者ID:shichao-an,项目名称:115wangpan,代码行数:4,代码来源:test_api.py


示例15: __init__

 def __init__(self, *args, **kwargs):
     super(TestAPI, self).__init__(*args, **kwargs)
     self.api = API()
     self.api.login(section='test')
开发者ID:mba811,项目名称:115wangpan,代码行数:4,代码来源:test_api.py


示例16: TestAPI

class TestAPI(TestCase):
    def __init__(self, *args, **kwargs):
        super(TestAPI, self).__init__(*args, **kwargs)
        self.api = API()
        self.api.login(section='test')

    def test_storage_info(self):
        res = self.api.get_storage_info()
        assert 'total' in res
        assert 'used' in res

        res = self.api.get_storage_info(human=True)
        assert 'total' in res
        assert 'used' in res

    def test_tasks_directories(self):
        time.sleep(5)  # Avoid 'Task is being transferred'
        task_count = self.api.task_count
        tasks = self.api.get_tasks(LARGE_COUNT)
        self.assertEqual(len(tasks), task_count)
        tasks = self.api.get_tasks(SMALL_COUNT)
        self.assertEqual(len(tasks), SMALL_COUNT)
        t = None
        for tt in tasks:
            if isinstance(tt, Directory):
                t = tt
                break
        else:
            return
        t = tasks[0]
        dd = self.api.downloads_directory
        if t.status_human == 'TRANSFERRED':
            d = t.directory
            p = t.parent
            assert d.parent is p
            assert p.cid == dd.cid
            assert t.count == len(t.list(LARGE_COUNT))
        for t in tasks:
            if t.info_hash == TEST_TORRENT2['info_hash']:
                td = t.directory
                entries = td.list()
                for entry in entries:
                    if isinstance(entry, Directory):
                        entry.list()
                    elif isinstance(entry, File):
                        assert entry.url

    def test_delete_file(self):
        tasks = self.api.get_tasks()
        for t in tasks:
            if t.info_hash == TEST_TORRENT2['info_hash']:
                # Delete file
                try:
                    d1 = t.directory
                except TaskError:
                    time.sleep(20)
                try:
                    d1 = t.directory
                except TaskError:
                    return
                d1_count = d1.count
                d2 = d1.list()[0]
                d2_count = d2.count
                files = d2.list()
                f1 = files[0]
                assert f1.delete()
                d2.reload()
                assert d2.count == d2_count - 1
                # Sleep to avoid JobError
                time.sleep(2)
                assert d2.delete()
                d1.reload()
                assert d1.count == d1_count - 1

    def test_search(self):
        """Directory is assumed to have more than 40 torrent files"""
        keyword = 'torrent'
        s1 = self.api.search(keyword)
        assert len(s1) == 30
        s2 = self.api.search(keyword, 10)
        assert len(s2) == 10
        s3 = self.api.search(keyword, 40)
        assert len(s3) == 40
开发者ID:mba811,项目名称:115wangpan,代码行数:83,代码来源:test_api.py


示例17: setUp

 def setUp(self):
     if os.path.exists(TEST_COOKIE_FILE):
         os.remove(TEST_COOKIE_FILE)
     self.api = API(auto_logout=False, persistent=True,
                    cookies_filename=TEST_COOKIE_FILE)
     self.api.login(section='test')
开发者ID:mba811,项目名称:115wangpan,代码行数:6,代码来源:test_api.py


示例18: __init__

 def __init__(self, *args, **kwargs):
     """Initialize once for all test functions in this TestCase"""
     super(PublicAPITests, self).__init__(*args, **kwargs)
     self.api = API()
     self.api.login(section='test')
开发者ID:shichao-an,项目名称:115wangpan,代码行数:5,代码来源:test_api.py


示例19: test_cookies

 def test_cookies(self):
     self.api.__del__()
     self.api = API(auto_logout=False, persistent=True,
                    cookies_filename=TEST_COOKIE_FILE)
     assert self.api.has_logged_in
开发者ID:mba811,项目名称:115wangpan,代码行数:5,代码来源:test_api.py


示例20: FileTests

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,代码行数:77,代码来源:test_api.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.websafe_decode函数代码示例发布时间:2022-05-27
下一篇:
Python u.load函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap