mirror of
https://github.com/haiwen/seahub.git
synced 2025-05-10 00:47:19 +00:00
update test
This commit is contained in:
parent
8f1c13e68b
commit
fece35af98
tests
api
seahub/base
@ -6,6 +6,7 @@ from seahub.test_utils import BaseTestCase
|
||||
|
||||
|
||||
class AdminWebSettingsTest(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.url = reverse('api-v2.1-web-settings')
|
||||
self.login_as(self.admin)
|
||||
@ -27,9 +28,9 @@ class AdminWebSettingsTest(BaseTestCase):
|
||||
self.assertEqual(200, resp.status_code)
|
||||
|
||||
json_resp = json.loads(resp.content)
|
||||
assert len(json_resp) == 30
|
||||
assert len(json_resp) == 29
|
||||
|
||||
@override_settings(ENABLE_SETTINGS_VIA_WEB = False)
|
||||
@override_settings(ENABLE_SETTINGS_VIA_WEB=False)
|
||||
def test_get_with_enable_settings(self):
|
||||
resp = self.client.get(self.url)
|
||||
self.assertEqual(404, resp.status_code)
|
||||
@ -37,7 +38,6 @@ class AdminWebSettingsTest(BaseTestCase):
|
||||
def test_update_web_settings_info(self):
|
||||
data = {
|
||||
"DISABLE_SYNC_WITH_ANY_FOLDER": False,
|
||||
"ENABLE_USER_CREATE_ORG_REPO": True,
|
||||
"SHARE_LINK_TOKEN_LENGTH": 20,
|
||||
"REPO_PASSWORD_MIN_LENGTH": 10,
|
||||
"REGISTRATION_SEND_MAIL": False,
|
||||
|
@ -1,15 +1,14 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
from seaserv import seafile_api, ccnet_threaded_rpc
|
||||
|
||||
from seahub.test_utils import BaseTestCase
|
||||
from mock import patch, MagicMock
|
||||
from seaserv import seafile_api
|
||||
from seahub.test_utils import BaseTestCase
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
class RepoPublicTest(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
from constance import config
|
||||
self.config = config
|
||||
@ -20,8 +19,6 @@ class RepoPublicTest(BaseTestCase):
|
||||
self.url = '/api2/shared-repos/%s/' % self.repo_id
|
||||
self.user_repo_url = '/api2/shared-repos/%s/' % self.repo.id
|
||||
|
||||
self.config.ENABLE_USER_CREATE_ORG_REPO = 1
|
||||
|
||||
def tearDown(self):
|
||||
self.remove_repo(self.repo_id)
|
||||
# clear cache between every test case to avoid config option cache issue
|
||||
@ -63,9 +60,6 @@ class RepoPublicTest(BaseTestCase):
|
||||
self.assertEqual(403, resp.status_code)
|
||||
|
||||
def test_admin_can_set_pub_repo_when_setting_disalbed(self):
|
||||
assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True
|
||||
self.config.ENABLE_USER_CREATE_ORG_REPO = False
|
||||
assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False
|
||||
|
||||
self.login_as(self.admin)
|
||||
|
||||
@ -75,9 +69,6 @@ class RepoPublicTest(BaseTestCase):
|
||||
assert 'success' in json_resp
|
||||
|
||||
def test_user_can_not_set_pub_repo_when_setting_disalbed(self):
|
||||
assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True
|
||||
self.config.ENABLE_USER_CREATE_ORG_REPO = False
|
||||
assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False
|
||||
|
||||
self.login_as(self.user)
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
import pytest
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
from mock import patch, MagicMock
|
||||
from seahub.test_utils import BaseTestCase
|
||||
from seaserv import seafile_api
|
||||
from mock import patch, MagicMock
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
class SharedRepoTest(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
from constance import config
|
||||
self.config = config
|
||||
@ -15,7 +16,6 @@ class SharedRepoTest(BaseTestCase):
|
||||
username=self.admin.username,
|
||||
passwd=None)
|
||||
self.shared_repo_url = '/api2/shared-repos/%s/?share_type=public&permission=rw'
|
||||
self.config.ENABLE_USER_CREATE_ORG_REPO = 1
|
||||
|
||||
def tearDown(self):
|
||||
self.remove_repo(self.repo_id)
|
||||
@ -48,9 +48,6 @@ class SharedRepoTest(BaseTestCase):
|
||||
self.assertEqual(403, resp.status_code)
|
||||
|
||||
def test_admin_can_set_pub_repo_when_setting_disalbed(self):
|
||||
assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True
|
||||
self.config.ENABLE_USER_CREATE_ORG_REPO = False
|
||||
assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False
|
||||
|
||||
self.login_as(self.admin)
|
||||
|
||||
@ -59,9 +56,6 @@ class SharedRepoTest(BaseTestCase):
|
||||
assert b"success" in resp.content
|
||||
|
||||
def test_user_can_not_set_pub_repo_when_setting_disalbed(self):
|
||||
assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True
|
||||
self.config.ENABLE_USER_CREATE_ORG_REPO = False
|
||||
assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False
|
||||
|
||||
self.login_as(self.user)
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
import copy
|
||||
from mock import patch
|
||||
from django.test import override_settings
|
||||
|
||||
from seahub.test_utils import BaseTestCase
|
||||
from seahub.base.accounts import User, RegistrationForm
|
||||
|
||||
from seahub.options.models import UserOptions
|
||||
from seahub.role_permissions.settings import ENABLED_ROLE_PERMISSIONS
|
||||
from django.urls import reverse
|
||||
from django.test import override_settings
|
||||
from mock import patch
|
||||
|
||||
|
||||
TEST_CAN_ADD_PUBLICK_REPO_TRUE = copy.deepcopy(ENABLED_ROLE_PERMISSIONS)
|
||||
@ -19,7 +18,9 @@ CLOUD_MODE_TRUE = True
|
||||
MULTI_TENANCY_TRUE = True
|
||||
MULTI_TENANCY_FALSE = False
|
||||
|
||||
|
||||
class UserTest(BaseTestCase):
|
||||
|
||||
def test_freeze_user(self):
|
||||
|
||||
u = User.objects.get(self.user.username)
|
||||
@ -39,11 +40,13 @@ class UserTest(BaseTestCase):
|
||||
|
||||
user = User.objects.get(email=test_email)
|
||||
user.delete()
|
||||
|
||||
|
||||
assert len(UserOptions.objects.filter(email=test_email)) == 0
|
||||
|
||||
|
||||
@override_settings(ENABLE_WIKI=True)
|
||||
class UserPermissionsTest(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
from constance import config
|
||||
self.config = config
|
||||
@ -76,31 +79,10 @@ class UserPermissionsTest(BaseTestCase):
|
||||
|
||||
def test_user_permissions_can_add_public_repo(self):
|
||||
# both have
|
||||
self.config.ENABLE_USER_CREATE_ORG_REPO = 1
|
||||
assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True
|
||||
with patch('seahub.role_permissions.utils.ENABLED_ROLE_PERMISSIONS', TEST_CAN_ADD_PUBLICK_REPO_TRUE):
|
||||
assert self.user.permissions._get_perm_by_roles('can_add_public_repo') is True
|
||||
assert self.user.permissions.can_add_public_repo() is True
|
||||
|
||||
# only have can_add_public_repo
|
||||
self.config.ENABLE_USER_CREATE_ORG_REPO = 0
|
||||
assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False
|
||||
with patch('seahub.role_permissions.utils.ENABLED_ROLE_PERMISSIONS', TEST_CAN_ADD_PUBLICK_REPO_TRUE):
|
||||
assert self.user.permissions._get_perm_by_roles('can_add_public_repo') is True
|
||||
assert self.user.permissions.can_add_public_repo() is False
|
||||
|
||||
# only have ENABLE_USER_CREATE_ORG_REPO
|
||||
self.config.ENABLE_USER_CREATE_ORG_REPO = 1
|
||||
assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True
|
||||
assert self.user.permissions._get_perm_by_roles('can_add_public_repo') is False
|
||||
assert self.user.permissions.can_add_public_repo() is False
|
||||
|
||||
# neither have
|
||||
self.config.ENABLE_USER_CREATE_ORG_REPO = 0
|
||||
assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False
|
||||
assert self.user.permissions._get_perm_by_roles('can_add_public_repo') is False
|
||||
assert self.user.permissions.can_add_public_repo() is False
|
||||
|
||||
def test_can_publish_repo_permission(self):
|
||||
# enableWIKI = True, and can_publish_repo = True
|
||||
assert self.user.permissions._get_perm_by_roles('can_publish_repo') is True
|
||||
@ -148,7 +130,6 @@ class RegistrationFormTest(BaseTestCase):
|
||||
def test_clean_email(self):
|
||||
form = self.form_class({'email': 'some_random_user@1.com',
|
||||
'password1': '123',
|
||||
'password2': '123',
|
||||
})
|
||||
'password2': '123'})
|
||||
assert form.is_valid() is True
|
||||
assert form.clean_email() == 'some_random_user@1.com'
|
||||
|
Loading…
Reference in New Issue
Block a user