本文整理汇总了Python中u115.api.API.move方法的典型用法代码示例。如果您正苦于以下问题:Python API.move方法的具体用法?Python API.move怎么用?Python API.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类u115.api.API
的用法示例。
在下文中一共展示了API.move方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FileTests
# 需要导入模块: from u115.api import API [as 别名]
# 或者: from u115.api.API import move [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)