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


Python api.API类代码示例

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


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


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