1
0
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:
Ranjiwei
2025-08-15 15:26:32 +08:00
committed by GitHub
parent bc54f94390
commit c94ee33d2b
3 changed files with 15 additions and 17 deletions

View File

@@ -3,7 +3,6 @@
import requests import requests
import unittest import unittest
from contextlib import contextmanager from contextlib import contextmanager
from nose.tools import assert_equal, assert_in # pylint: disable=E0611
from urllib.parse import quote from urllib.parse import quote
from tests.common.common import USERNAME, PASSWORD, \ from tests.common.common import USERNAME, PASSWORD, \
@@ -83,13 +82,13 @@ class ApiTestBase(unittest.TestCase):
resp = requests.request(method, *args, **kwargs) resp = requests.request(method, *args, **kwargs)
if expected is not None: if expected is not None:
if hasattr(expected, '__iter__'): if hasattr(expected, '__iter__'):
assert_in(resp.status_code, expected, assert resp.status_code in expected, \
"Expected http status in %s, received %s" % (expected, "Expected http status in %s, received %s" % (expected,
resp.status_code)) resp.status_code)
else: else:
assert_equal(resp.status_code, expected, assert resp.status_code == expected, \
"Expected http status %s, received %s" % (expected, "Expected http status in %s, received %s" % (expected,
resp.status_code)) resp.status_code)
return resp return resp
def assertHasLen(self, lst, length): def assertHasLen(self, lst, length):
@@ -215,9 +214,9 @@ def get_auth_token(username, password):
'device_name': 'test', 'device_name': 'test',
} }
res = requests.post(TOKEN_URL, data=data) res = requests.post(TOKEN_URL, data=data)
assert_equal(res.status_code, 200) assert res.status_code == 200
token = res.json()['token'] token = res.json()['token']
assert_equal(len(token), 40) assert len(token) == 40
return token return token
class _Repo(object): class _Repo(object):

View File

@@ -8,7 +8,6 @@ import pytest
import urllib.request, urllib.parse, urllib.error import urllib.request, urllib.parse, urllib.error
from urllib.parse import urlencode, quote from urllib.parse import urlencode, quote
import urllib.parse import urllib.parse
from nose.tools import assert_in
from tests.common.utils import randstring, urljoin from tests.common.utils import randstring, urljoin
from tests.api.apitestbase import ApiTestBase from tests.api.apitestbase import ApiTestBase
@@ -54,7 +53,7 @@ class FilesApiTest(ApiTestBase):
u = urllib.parse.urlparse(furl) u = urllib.parse.urlparse(furl)
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', '')) parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data) 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('/') # get info of copied file in dst dir('/')
fdurl = repo.file_url + 'detail/?p=/%s' % quote(tmp_file) fdurl = repo.file_url + 'detail/?p=/%s' % quote(tmp_file)
@@ -72,7 +71,7 @@ class FilesApiTest(ApiTestBase):
u = urllib.parse.urlparse(furl) u = urllib.parse.urlparse(furl)
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', '')) parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data) 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 # 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 # 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) u = urllib.parse.urlparse(furl)
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', '')) parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data) 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 # then move file to dst dir
data = { data = {
@@ -95,7 +94,7 @@ class FilesApiTest(ApiTestBase):
u = urllib.parse.urlparse(furl) u = urllib.parse.urlparse(furl)
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', '')) parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data) 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): def test_copy_file(self):
@@ -121,7 +120,7 @@ class FilesApiTest(ApiTestBase):
u = urllib.parse.urlparse(furl) u = urllib.parse.urlparse(furl)
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', '')) parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data) 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('/') # get info of copied file in dst dir('/')
fdurl = repo.file_url + 'detail/?p=/%s' % quote(tmp_file) fdurl = repo.file_url + 'detail/?p=/%s' % quote(tmp_file)
@@ -139,7 +138,7 @@ class FilesApiTest(ApiTestBase):
u = urllib.parse.urlparse(furl) u = urllib.parse.urlparse(furl)
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', '')) parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data) 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 # 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 # 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) u = urllib.parse.urlparse(furl)
parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', '')) parsed_furl = urllib.parse.urlunparse((u.scheme, u.netloc, u.path, '', '', ''))
res = self.post(parsed_furl+ '?p=' + quote(file_path), data=data) 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): def test_download_file(self):
with self.get_tmp_repo() as repo: with self.get_tmp_repo() as repo:

View File

@@ -28,7 +28,7 @@ SEAHUB_TESTSDIR=$(python -c "import os; print(os.path.dirname(os.path.realpath('
SEAHUB_SRCDIR=$(dirname "${SEAHUB_TESTSDIR}") SEAHUB_SRCDIR=$(dirname "${SEAHUB_TESTSDIR}")
export SEAHUB_LOG_DIR='/tmp/logs' 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" cd "$SEAHUB_SRCDIR"
set +x set +x