1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-17 15:53:28 +00:00

[tests] Fix shared file tests

This commit is contained in:
zhengxie
2015-10-20 11:44:19 +08:00
parent 8fd9bebf45
commit df1ff9e0f6

View File

@@ -1,40 +1,22 @@
#coding: UTF-8 #coding: UTF-8
from django.core.cache import cache
from constance import config
from seahub.share.models import FileShare, UploadLinkShare from seahub.share.models import FileShare, UploadLinkShare
from seahub.test_utils import BaseTestCase from seahub.test_utils import BaseTestCase
from tests.common.utils import urljoin, randstring from tests.common.utils import randstring
from tests.api.apitestbase import ApiTestBase
from tests.api.urls import SHARED_LINKS_URL
#class SharesApiTest(ApiTestBase):
# def test_create_file_shared_link(self):
# with self.get_tmp_repo() as repo:
# fname, _ = self.create_file(repo)
# fsurl = urljoin(repo.file_url, 'shared-link')
# data = {
# 'type': 'f',
# 'p': '/' + fname,
# }
# res = self.put(fsurl, data=data, expected=201)
# self.assertRegexpMatches(res.headers['Location'], \
# r'http(.*)/f/(\w{10,10})/')
#
# res = self.get(SHARED_LINKS_URL).json()
# self.assertNotEmpty(res)
# for fileshare in res['fileshares']:
# self.assertIsNotNone(fileshare['username'])
# self.assertIsNotNone(fileshare['repo_id'])
# #self.assertIsNotNone(fileshare['ctime'])
# self.assertIsNotNone(fileshare['s_type'])
# self.assertIsNotNone(fileshare['token'])
# self.assertIsNotNone(fileshare['view_cnt'])
# self.assertIsNotNone(fileshare['path'])
#
#
class FileSharedLinkApiTest(BaseTestCase): class FileSharedLinkApiTest(BaseTestCase):
def setUp(self):
cache.clear()
self.curr_passwd_len = config.SHARE_LINK_PASSWORD_MIN_LENGTH
config.SHARE_LINK_PASSWORD_MIN_LENGTH = 3
def tearDown(self): def tearDown(self):
self.remove_repo() self.remove_repo()
config.SHARE_LINK_PASSWORD_MIN_LENGTH = self.curr_passwd_len
def test_create_file_shared_link_with_invalid_path(self): def test_create_file_shared_link_with_invalid_path(self):
self.login_as(self.user) self.login_as(self.user)
@@ -70,7 +52,7 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded',
) )
self.assertEqual(201, resp.status_code) self.assertEqual(201, resp.status_code)
self.assertRegexpMatches(resp._headers['location'][1], \ self.assertRegexpMatches(resp._headers['location'][1],
r'http(.*)/f/(\w{10,10})/') r'http(.*)/f/(\w{10,10})/')
token = resp._headers['location'][1].split('/')[-2] token = resp._headers['location'][1].split('/')[-2]
@@ -86,7 +68,7 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded',
) )
self.assertEqual(201, resp.status_code) self.assertEqual(201, resp.status_code)
self.assertRegexpMatches(resp._headers['location'][1], \ self.assertRegexpMatches(resp._headers['location'][1],
r'http(.*)/f/(\w{10,10})/') r'http(.*)/f/(\w{10,10})/')
token = resp._headers['location'][1].split('/')[-2] token = resp._headers['location'][1].split('/')[-2]
@@ -103,7 +85,7 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded',
) )
self.assertEqual(201, resp.status_code) self.assertEqual(201, resp.status_code)
self.assertRegexpMatches(resp._headers['location'][1], \ self.assertRegexpMatches(resp._headers['location'][1],
r'http(.*)/f/(\w{10,10})/') r'http(.*)/f/(\w{10,10})/')
token = resp._headers['location'][1].split('/')[-2] token = resp._headers['location'][1].split('/')[-2]
@@ -120,7 +102,7 @@ class FileSharedLinkApiTest(BaseTestCase):
'application/x-www-form-urlencoded', 'application/x-www-form-urlencoded',
) )
self.assertEqual(201, resp.status_code) self.assertEqual(201, resp.status_code)
self.assertRegexpMatches(resp._headers['location'][1], \ self.assertRegexpMatches(resp._headers['location'][1],
r'http(.*)/f/(\w{10,10})/') r'http(.*)/f/(\w{10,10})/')
token = resp._headers['location'][1].split('/')[-2] token = resp._headers['location'][1].split('/')[-2]
@@ -139,7 +121,7 @@ class FileSharedLinkApiTest(BaseTestCase):
) )
self.assertEqual(201, resp.status_code) self.assertEqual(201, resp.status_code)
self.dir_link_location = resp._headers['location'][1] self.dir_link_location = resp._headers['location'][1]
self.assertRegexpMatches(self.dir_link_location, \ self.assertRegexpMatches(self.dir_link_location,
r'http(.*)/d/(\w{10,10})/') r'http(.*)/d/(\w{10,10})/')
token = resp._headers['location'][1].split('/')[-2] token = resp._headers['location'][1].split('/')[-2]
@@ -156,7 +138,7 @@ class FileSharedLinkApiTest(BaseTestCase):
) )
self.assertEqual(201, resp.status_code) self.assertEqual(201, resp.status_code)
self.dir_link_location = resp._headers['location'][1] self.dir_link_location = resp._headers['location'][1]
self.assertRegexpMatches(self.dir_link_location, \ self.assertRegexpMatches(self.dir_link_location,
r'http(.*)/d/(\w{10,10})/') r'http(.*)/d/(\w{10,10})/')
token = resp._headers['location'][1].split('/')[-2] token = resp._headers['location'][1].split('/')[-2]
@@ -174,7 +156,7 @@ class FileSharedLinkApiTest(BaseTestCase):
) )
self.assertEqual(201, resp.status_code) self.assertEqual(201, resp.status_code)
self.dir_link_location = resp._headers['location'][1] self.dir_link_location = resp._headers['location'][1]
self.assertRegexpMatches(self.dir_link_location, \ self.assertRegexpMatches(self.dir_link_location,
r'http(.*)/d/(\w{10,10})/') r'http(.*)/d/(\w{10,10})/')
token = resp._headers['location'][1].split('/')[-2] token = resp._headers['location'][1].split('/')[-2]
@@ -192,7 +174,7 @@ class FileSharedLinkApiTest(BaseTestCase):
) )
self.assertEqual(201, resp.status_code) self.assertEqual(201, resp.status_code)
self.dir_link_location = resp._headers['location'][1] self.dir_link_location = resp._headers['location'][1]
self.assertRegexpMatches(self.dir_link_location, \ self.assertRegexpMatches(self.dir_link_location,
r'http(.*)/d/(\w{10,10})/') r'http(.*)/d/(\w{10,10})/')
token = resp._headers['location'][1].split('/')[-2] token = resp._headers['location'][1].split('/')[-2]
@@ -211,7 +193,7 @@ class FileSharedLinkApiTest(BaseTestCase):
) )
self.assertEqual(201, resp.status_code) self.assertEqual(201, resp.status_code)
self.dir_link_location = resp._headers['location'][1] self.dir_link_location = resp._headers['location'][1]
self.assertRegexpMatches(self.dir_link_location, \ self.assertRegexpMatches(self.dir_link_location,
r'http(.*)/u/d/(\w{10,10})/') r'http(.*)/u/d/(\w{10,10})/')
token = resp._headers['location'][1].split('/')[-2] token = resp._headers['location'][1].split('/')[-2]
@@ -228,7 +210,7 @@ class FileSharedLinkApiTest(BaseTestCase):
) )
self.assertEqual(201, resp.status_code) self.assertEqual(201, resp.status_code)
self.dir_link_location = resp._headers['location'][1] self.dir_link_location = resp._headers['location'][1]
self.assertRegexpMatches(self.dir_link_location, \ self.assertRegexpMatches(self.dir_link_location,
r'http(.*)/u/d/(\w{10,10})/') r'http(.*)/u/d/(\w{10,10})/')
token = resp._headers['location'][1].split('/')[-2] token = resp._headers['location'][1].split('/')[-2]
@@ -240,7 +222,8 @@ class SharedFileDetailApiTest(BaseTestCase):
def _add_file_shared_link_with_password(self): def _add_file_shared_link_with_password(self):
password = randstring(6) password = randstring(6)
uls = FileShare.objects.create_file_link(self.user.username, uls = FileShare.objects.create_file_link(self.user.username,
self.repo.id, self.file, password) self.repo.id, self.file,
password)
return (uls.token, password) return (uls.token, password)