mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-22 11:57:34 +00:00
fix-unitest-for-python3.12 (#8141)
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
import requests
|
||||
import unittest
|
||||
from contextlib import contextmanager
|
||||
from nose.tools import assert_equal, assert_in # pylint: disable=E0611
|
||||
from urllib.parse import quote
|
||||
|
||||
from tests.common.common import USERNAME, PASSWORD, \
|
||||
@@ -83,13 +82,13 @@ class ApiTestBase(unittest.TestCase):
|
||||
resp = requests.request(method, *args, **kwargs)
|
||||
if expected is not None:
|
||||
if hasattr(expected, '__iter__'):
|
||||
assert_in(resp.status_code, expected,
|
||||
assert resp.status_code in expected, \
|
||||
"Expected http status in %s, received %s" % (expected,
|
||||
resp.status_code))
|
||||
resp.status_code)
|
||||
else:
|
||||
assert_equal(resp.status_code, expected,
|
||||
"Expected http status %s, received %s" % (expected,
|
||||
resp.status_code))
|
||||
assert resp.status_code == expected, \
|
||||
"Expected http status in %s, received %s" % (expected,
|
||||
resp.status_code)
|
||||
return resp
|
||||
|
||||
def assertHasLen(self, lst, length):
|
||||
@@ -215,9 +214,9 @@ def get_auth_token(username, password):
|
||||
'device_name': 'test',
|
||||
}
|
||||
res = requests.post(TOKEN_URL, data=data)
|
||||
assert_equal(res.status_code, 200)
|
||||
assert res.status_code == 200
|
||||
token = res.json()['token']
|
||||
assert_equal(len(token), 40)
|
||||
assert len(token) == 40
|
||||
return token
|
||||
|
||||
class _Repo(object):
|
||||
|
@@ -8,7 +8,6 @@ import pytest
|
||||
import urllib.request, urllib.parse, urllib.error
|
||||
from urllib.parse import urlencode, quote
|
||||
import urllib.parse
|
||||
from nose.tools import assert_in
|
||||
|
||||
from tests.common.utils import randstring, urljoin
|
||||
from tests.api.apitestbase import ApiTestBase
|
||||
@@ -54,7 +53,7 @@ class FilesApiTest(ApiTestBase):
|
||||
u = urllib.parse.urlparse(furl)
|
||||
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
assert_in(tmp_file, res.text)
|
||||
assert tmp_file in res.text
|
||||
|
||||
# get info of copied file in dst dir('/')
|
||||
fdurl = repo.file_url + 'detail/?p=/%s' % quote(tmp_file)
|
||||
@@ -72,7 +71,7 @@ class FilesApiTest(ApiTestBase):
|
||||
u = urllib.parse.urlparse(furl)
|
||||
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
assert_in('tmp_file (1).txt', res.text)
|
||||
assert 'tmp_file (1).txt' in res.text
|
||||
|
||||
# copy tmp file from sub folder(dpath) to dst dir('/') again
|
||||
# for test can rename file if a file with the same name is dst dir
|
||||
@@ -84,7 +83,7 @@ class FilesApiTest(ApiTestBase):
|
||||
u = urllib.parse.urlparse(furl)
|
||||
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
assert_in('tmp_file (2).txt', res.text)
|
||||
assert 'tmp_file (2).txt' in res.text
|
||||
|
||||
# then move file to dst dir
|
||||
data = {
|
||||
@@ -95,7 +94,7 @@ class FilesApiTest(ApiTestBase):
|
||||
u = urllib.parse.urlparse(furl)
|
||||
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
assert_in('tmp_file%20%283%29.txt', res.text)
|
||||
assert 'tmp_file%20%283%29.txt' in res.text
|
||||
|
||||
|
||||
def test_copy_file(self):
|
||||
@@ -121,7 +120,7 @@ class FilesApiTest(ApiTestBase):
|
||||
u = urllib.parse.urlparse(furl)
|
||||
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
assert_in(tmp_file, res.text)
|
||||
assert tmp_file in res.text
|
||||
|
||||
# get info of copied file in dst dir('/')
|
||||
fdurl = repo.file_url + 'detail/?p=/%s' % quote(tmp_file)
|
||||
@@ -139,7 +138,7 @@ class FilesApiTest(ApiTestBase):
|
||||
u = urllib.parse.urlparse(furl)
|
||||
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
assert_in('tmp_file (1).txt', res.text)
|
||||
assert 'tmp_file (1).txt' in res.text
|
||||
|
||||
# copy tmp file from sub folder(dpath) to dst dir('/') again
|
||||
# for test can rename file if a file with the same name is dst dir
|
||||
@@ -151,7 +150,7 @@ class FilesApiTest(ApiTestBase):
|
||||
u = urllib.parse.urlparse(furl)
|
||||
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
|
||||
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data)
|
||||
assert_in('tmp_file (2).txt', res.text)
|
||||
assert 'tmp_file (2).txt' in res.text
|
||||
|
||||
def test_download_file(self):
|
||||
with self.get_tmp_repo() as repo:
|
||||
|
@@ -28,7 +28,7 @@ SEAHUB_TESTSDIR=$(python -c "import os; print(os.path.dirname(os.path.realpath('
|
||||
SEAHUB_SRCDIR=$(dirname "${SEAHUB_TESTSDIR}")
|
||||
|
||||
export SEAHUB_LOG_DIR='/tmp/logs'
|
||||
export PYTHONPATH="/usr/local/lib/python3.10/site-packages:/usr/local/lib/python3.10/dist-packages:/usr/lib/python3.10/site-packages:/usr/lib/python3.10/dist-packages:${SEAHUB_SRCDIR}/thirdpart:${PYTHONPATH}"
|
||||
export PYTHONPATH="/usr/local/lib/python3.12/site-packages:/usr/local/lib/python3.12/dist-packages:/usr/lib/python3.12/site-packages:/usr/lib/python3.12/dist-packages:${SEAHUB_SRCDIR}/thirdpart:${PYTHONPATH}"
|
||||
cd "$SEAHUB_SRCDIR"
|
||||
set +x
|
||||
|
||||
|
Reference in New Issue
Block a user