mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-25 06:33:48 +00:00
@@ -1,12 +1,18 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
from mock import patch
|
||||||
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from seahub.test_utils import BaseTestCase
|
from seahub.test_utils import BaseTestCase
|
||||||
from tests.common.utils import randstring
|
from seahub.institutions.models import Institution
|
||||||
from seahub.institutions.models import Institution, InstitutionAdmin
|
|
||||||
from seahub.profile.models import Profile
|
from seahub.profile.models import Profile
|
||||||
|
|
||||||
|
try:
|
||||||
|
from seahub.settings import LOCAL_PRO_DEV_ENV
|
||||||
|
except ImportError:
|
||||||
|
LOCAL_PRO_DEV_ENV = False
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -25,8 +31,14 @@ class AdminInstitutionUsersTest(BaseTestCase):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
||||||
|
@patch('seahub.api2.endpoints.admin.institution_users.IsProVersion')
|
||||||
|
def test_can_get(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
def test_can_get(self):
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
inst = self._add_institution('int1')
|
inst = self._add_institution('int1')
|
||||||
url = reverse('api-v2.1-admin-institution-users', args=[inst.id])
|
url = reverse('api-v2.1-admin-institution-users', args=[inst.id])
|
||||||
@@ -38,7 +50,14 @@ class AdminInstitutionUsersTest(BaseTestCase):
|
|||||||
|
|
||||||
inst.delete()
|
inst.delete()
|
||||||
|
|
||||||
def test_no_permission(self):
|
@patch('seahub.api2.endpoints.admin.institution_users.IsProVersion')
|
||||||
|
def test_no_permission(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.logout()
|
self.logout()
|
||||||
self.login_as(self.admin_no_other_permission)
|
self.login_as(self.admin_no_other_permission)
|
||||||
inst = self._add_institution('int1')
|
inst = self._add_institution('int1')
|
||||||
@@ -47,7 +66,14 @@ class AdminInstitutionUsersTest(BaseTestCase):
|
|||||||
|
|
||||||
self.assertEqual(403, resp.status_code)
|
self.assertEqual(403, resp.status_code)
|
||||||
|
|
||||||
def test_can_create(self):
|
@patch('seahub.api2.endpoints.admin.institution_users.IsProVersion')
|
||||||
|
def test_can_create(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
inst = self._add_institution('int1')
|
inst = self._add_institution('int1')
|
||||||
url = reverse('api-v2.1-admin-institution-users', args=[inst.id])
|
url = reverse('api-v2.1-admin-institution-users', args=[inst.id])
|
||||||
@@ -85,7 +111,14 @@ class AdminInstitutionUserTest(BaseTestCase):
|
|||||||
profile.institution = inst_name
|
profile.institution = inst_name
|
||||||
profile.save()
|
profile.save()
|
||||||
|
|
||||||
def test_can_update(self):
|
@patch('seahub.api2.endpoints.admin.institution_users.IsProVersion')
|
||||||
|
def test_can_update(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
inst = self._add_institution('int1')
|
inst = self._add_institution('int1')
|
||||||
self._add_user_in_institution(self.user.email, inst.name)
|
self._add_user_in_institution(self.user.email, inst.name)
|
||||||
@@ -100,7 +133,14 @@ class AdminInstitutionUserTest(BaseTestCase):
|
|||||||
|
|
||||||
inst.delete()
|
inst.delete()
|
||||||
|
|
||||||
def test_can_delete(self):
|
@patch('seahub.api2.endpoints.admin.institution_users.IsProVersion')
|
||||||
|
def test_can_delete(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
inst = self._add_institution('int1')
|
inst = self._add_institution('int1')
|
||||||
self._add_user_in_institution(self.user.email, inst.name)
|
self._add_user_in_institution(self.user.email, inst.name)
|
||||||
|
@@ -1,11 +1,18 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
from mock import patch
|
||||||
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from seahub.test_utils import BaseTestCase
|
from seahub.test_utils import BaseTestCase
|
||||||
from tests.common.utils import randstring
|
from tests.common.utils import randstring
|
||||||
from seahub.institutions.models import Institution
|
from seahub.institutions.models import Institution
|
||||||
|
|
||||||
|
try:
|
||||||
|
from seahub.settings import LOCAL_PRO_DEV_ENV
|
||||||
|
except ImportError:
|
||||||
|
LOCAL_PRO_DEV_ENV = False
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -24,7 +31,14 @@ class InstitutionsTest(BaseTestCase):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
||||||
def test_can_get(self):
|
@patch('seahub.api2.endpoints.admin.institutions.IsProVersion')
|
||||||
|
def test_can_get(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
inst = self._add_institution('int1')
|
inst = self._add_institution('int1')
|
||||||
url = reverse('api-v2.1-admin-institutions')
|
url = reverse('api-v2.1-admin-institutions')
|
||||||
@@ -37,7 +51,14 @@ class InstitutionsTest(BaseTestCase):
|
|||||||
|
|
||||||
inst.delete()
|
inst.delete()
|
||||||
|
|
||||||
def test_no_permission(self):
|
@patch('seahub.api2.endpoints.admin.institutions.IsProVersion')
|
||||||
|
def test_no_permission(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.logout()
|
self.logout()
|
||||||
self.login_as(self.admin_no_other_permission)
|
self.login_as(self.admin_no_other_permission)
|
||||||
inst = self._add_institution('int1')
|
inst = self._add_institution('int1')
|
||||||
@@ -47,7 +68,14 @@ class InstitutionsTest(BaseTestCase):
|
|||||||
self.assertEqual(403, resp.status_code)
|
self.assertEqual(403, resp.status_code)
|
||||||
inst.delete()
|
inst.delete()
|
||||||
|
|
||||||
def test_can_create(self):
|
@patch('seahub.api2.endpoints.admin.institutions.IsProVersion')
|
||||||
|
def test_can_create(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
url = reverse('api-v2.1-admin-institutions')
|
url = reverse('api-v2.1-admin-institutions')
|
||||||
|
|
||||||
@@ -79,7 +107,14 @@ class InstitutionTest(BaseTestCase):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
||||||
def test_can_get(self):
|
@patch('seahub.api2.endpoints.admin.institutions.IsProVersion')
|
||||||
|
def test_can_get(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
institution_name = randstring(10)
|
institution_name = randstring(10)
|
||||||
inst = self._add_institution(institution_name)
|
inst = self._add_institution(institution_name)
|
||||||
@@ -93,7 +128,14 @@ class InstitutionTest(BaseTestCase):
|
|||||||
|
|
||||||
inst.delete()
|
inst.delete()
|
||||||
|
|
||||||
def test_can_update(self):
|
@patch('seahub.api2.endpoints.admin.institutions.IsProVersion')
|
||||||
|
def test_can_update(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
institution_name = randstring(10)
|
institution_name = randstring(10)
|
||||||
inst = self._add_institution(institution_name)
|
inst = self._add_institution(institution_name)
|
||||||
@@ -108,8 +150,14 @@ class InstitutionTest(BaseTestCase):
|
|||||||
|
|
||||||
inst.delete()
|
inst.delete()
|
||||||
|
|
||||||
|
@patch('seahub.api2.endpoints.admin.institutions.IsProVersion')
|
||||||
|
def test_can_delete(self, mock_is_pro_version):
|
||||||
|
|
||||||
|
if not LOCAL_PRO_DEV_ENV:
|
||||||
|
return
|
||||||
|
|
||||||
|
mock_is_pro_version.return_value = True
|
||||||
|
|
||||||
def test_can_delete(self):
|
|
||||||
self.login_as(self.admin)
|
self.login_as(self.admin)
|
||||||
institution_name = randstring(10)
|
institution_name = randstring(10)
|
||||||
inst = self._add_institution(institution_name)
|
inst = self._add_institution(institution_name)
|
||||||
|
Reference in New Issue
Block a user