mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 07:01:12 +00:00
Merge branch '5.0'
Conflicts: seahub/api2/urls.py seahub/api2/views.py seahub/group/templates/group/group_discuss.html seahub/options/models.py seahub/templates/repo_folder_perm.html seahub/templates/repo_share_manage.html seahub/templates/snippets/shared_link_js.html seahub/test_utils.py
This commit is contained in:
67
tests/api/test_file_revert.py
Normal file
67
tests/api/test_file_revert.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import os
|
||||
import json
|
||||
from seaserv import seafile_api
|
||||
from django.core.urlresolvers import reverse
|
||||
from seahub.test_utils import BaseTestCase
|
||||
|
||||
class FileRevertTest(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.repo_id = self.repo.id
|
||||
self.file_path = self.file
|
||||
self.parent_dir = os.path.dirname(self.file_path)
|
||||
self.file_name = os.path.basename(self.file_path)
|
||||
self.username = self.user.username
|
||||
|
||||
self.url = reverse('api2-file-revert', args=[self.repo_id])
|
||||
|
||||
def tearDown(self):
|
||||
self.remove_repo()
|
||||
|
||||
def delete_file(self):
|
||||
seafile_api.del_file(self.repo_id, self.parent_dir,
|
||||
self.file_name, self.username)
|
||||
|
||||
def get_trash_file_commit_id(self):
|
||||
deleted_file = seafile_api.get_deleted(self.repo_id, 0, '/', None)
|
||||
|
||||
return deleted_file[0].commit_id
|
||||
|
||||
def get_lib_file_name(self):
|
||||
|
||||
url = reverse('list_lib_dir', args=[self.repo_id])
|
||||
resp = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
json_resp = json.loads(resp.content)
|
||||
|
||||
if len(json_resp['dirent_list']) == 0:
|
||||
return None
|
||||
|
||||
return json_resp['dirent_list'][0]['obj_name']
|
||||
|
||||
def test_can_revert_file(self):
|
||||
self.login_as(self.user)
|
||||
|
||||
# check file exist when init
|
||||
assert self.get_lib_file_name() == self.file_name
|
||||
|
||||
# delete
|
||||
self.delete_file()
|
||||
|
||||
# check file not exist after delete
|
||||
assert self.get_lib_file_name() == None
|
||||
|
||||
# get commit_id of deleted file
|
||||
commit_id = self.get_trash_file_commit_id()
|
||||
|
||||
resp = self.client.put(self.url,
|
||||
"p=%s&commit_id=%s" % (self.file_path, commit_id),
|
||||
'application/x-www-form-urlencoded',
|
||||
)
|
||||
self.assertEqual(200, resp.status_code)
|
||||
|
||||
# check file has been reverted
|
||||
assert self.get_lib_file_name() == self.file_name
|
||||
|
||||
def test_can_revert_unicode_filename(self):
|
||||
# todo
|
||||
pass
|
Reference in New Issue
Block a user