本文整理汇总了Python中u115.api.API.add_task_url方法的典型用法代码示例。如果您正苦于以下问题:Python API.add_task_url方法的具体用法?Python API.add_task_url怎么用?Python API.add_task_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类u115.api.API
的用法示例。
在下文中一共展示了API.add_task_url方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: URLTaskTests
# 需要导入模块: from u115.api import API [as 别名]
# 或者: from u115.api.API import add_task_url [as 别名]
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)
示例2: TaskTests
# 需要导入模块: from u115.api import API [as 别名]
# 或者: from u115.api.API import add_task_url [as 别名]
class TaskTests(TestCase):
"""Test general task interface"""
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_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
time.sleep(5)
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()
delete_entries(tasks)
示例3: TestAPI
# 需要导入模块: from u115.api import API [as 别名]
# 或者: from u115.api.API import add_task_url [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_login_logout(self):
credential = conf.get_credential('test')
username = credential['username']
password = credential['password']
if self.api.has_logged_in:
assert self.api.logout()
assert self.api.login(username, password)
def test_login_credentials(self):
if self.api.has_logged_in:
assert self.api.logout()
assert self.api.login(section='test')
def test_tasks_directories(self):
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 = 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()[1]
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_add_delete_task_bt(self):
h1 = TEST_TORRENT1['info_hash']
h2 = TEST_TORRENT2['info_hash']
tasks = self.api.get_tasks()
for task in tasks:
if task.info_hash == h1:
assert task.delete()
if task.info_hash == h2:
assert task.delete()
assert self.api.add_task_bt(TEST_TORRENT1['filename'])
u = self.api.add_task_bt(TEST_TORRENT2['filename'], select=True)
assert isinstance(u, Torrent)
files = u.files
file_count = u.file_count
files[0].unselect()
files[1].unselect()
assert len(u.selected_files) == file_count - 2
assert u.submit()
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_add_task_url(self):
'''
#.........这里部分代码省略.........