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


Python API.search方法代码示例

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


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

示例1: SearchTests

# 需要导入模块: from u115.api import API [as 别名]
# 或者: from u115.api.API import search [as 别名]
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,代码行数:39,代码来源:test_api.py

示例2: TestAPI

# 需要导入模块: from u115.api import API [as 别名]
# 或者: from u115.api.API import search [as 别名]
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,代码行数:85,代码来源:test_api.py


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