diff --git a/tests/api/endpoints/test_shareable_groups.py b/tests/api/endpoints/test_shareable_groups.py index 882ccc223e..fc1a3f2d78 100644 --- a/tests/api/endpoints/test_shareable_groups.py +++ b/tests/api/endpoints/test_shareable_groups.py @@ -1,15 +1,20 @@ # Copyright (c) 2011-2016 Seafile Ltd. # -*- coding: utf-8 -*- import json +import pytest +pytestmark = pytest.mark.django_db + from django.core.urlresolvers import reverse from seahub.test_utils import BaseTestCase from tests.common.utils import randstring -from constance import config class ShareableGroupsTest(BaseTestCase): def setUp(self): + from constance import config + self.config = config + self.login_as(self.user) self.group_id = self.group.id self.group_name = self.group.group_name @@ -20,10 +25,11 @@ class ShareableGroupsTest(BaseTestCase): def tearDown(self): self.remove_group() self.remove_repo() + self.clear_cache() def test_can_get(self): - config.ENABLE_SHARE_TO_ALL_GROUPS = 1 + self.config.ENABLE_SHARE_TO_ALL_GROUPS = 1 admin_group_name = randstring(10) admin_group = self.create_group(group_name=admin_group_name, @@ -42,7 +48,7 @@ class ShareableGroupsTest(BaseTestCase): def test_can_get_with_disable_config(self): - config.ENABLE_SHARE_TO_ALL_GROUPS = 0 + self.config.ENABLE_SHARE_TO_ALL_GROUPS = 0 admin_group_name = randstring(10) admin_group = self.create_group(group_name=admin_group_name, diff --git a/tests/api/test_public_repo.py b/tests/api/test_public_repo.py index f6ba3bf073..86a5132f46 100644 --- a/tests/api/test_public_repo.py +++ b/tests/api/test_public_repo.py @@ -1,6 +1,8 @@ import json -from constance import config +import pytest +pytestmark = pytest.mark.django_db + from seaserv import seafile_api, ccnet_threaded_rpc from seahub.test_utils import BaseTestCase @@ -8,13 +10,16 @@ from seahub.test_utils import BaseTestCase class RepoPublicTest(BaseTestCase): def setUp(self): + from constance import config + self.config = config + self.repo_id = self.create_repo(name='test-admin-repo', desc='', username=self.admin.username, passwd=None) self.url = '/api2/shared-repos/%s/' % self.repo_id self.user_repo_url = '/api2/shared-repos/%s/' % self.repo.id - config.ENABLE_USER_CREATE_ORG_REPO = 1 + self.config.ENABLE_USER_CREATE_ORG_REPO = 1 def tearDown(self): self.remove_repo(self.repo_id) @@ -48,9 +53,9 @@ class RepoPublicTest(BaseTestCase): assert 'success' in json_resp def test_admin_can_set_pub_repo_when_setting_disalbed(self): - assert bool(config.ENABLE_USER_CREATE_ORG_REPO) is True - config.ENABLE_USER_CREATE_ORG_REPO = False - assert bool(config.ENABLE_USER_CREATE_ORG_REPO) is False + 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) @@ -60,9 +65,9 @@ class RepoPublicTest(BaseTestCase): assert 'success' in json_resp def test_user_can_not_set_pub_repo_when_setting_disalbed(self): - assert bool(config.ENABLE_USER_CREATE_ORG_REPO) is True - config.ENABLE_USER_CREATE_ORG_REPO = False - assert bool(config.ENABLE_USER_CREATE_ORG_REPO) is False + 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) diff --git a/tests/api/test_repo.py b/tests/api/test_repo.py index 7715c7b373..2186ba4634 100644 --- a/tests/api/test_repo.py +++ b/tests/api/test_repo.py @@ -2,7 +2,10 @@ """ import json from mock import patch -from constance import config + +import pytest +pytestmark = pytest.mark.django_db + from django.core.urlresolvers import reverse from django.template.defaultfilters import filesizeformat @@ -18,6 +21,9 @@ class RepoTest(BaseTestCase): self.url = reverse('api2-repos') self.repo_id = self.repo + from constance import config + self.config = config + def test_can_fetch(self): self.login_as(self.user) @@ -189,7 +195,7 @@ class RepoTest(BaseTestCase): self.remove_repo(share_repo.id) def test_can_get_share_group_repo(self): - config.ENABLE_SHARE_TO_ALL_GROUPS = True + self.config.ENABLE_SHARE_TO_ALL_GROUPS = True self.logout() self.login_as(self.admin) diff --git a/tests/api/test_repo_history_limit.py b/tests/api/test_repo_history_limit.py index 63aad6bf9e..4ed872e4d9 100644 --- a/tests/api/test_repo_history_limit.py +++ b/tests/api/test_repo_history_limit.py @@ -2,16 +2,20 @@ """ import json +import pytest +pytestmark = pytest.mark.django_db + from django.core.urlresolvers import reverse -from constance import config - from seahub.test_utils import BaseTestCase + class RepoTest(BaseTestCase): def setUp(self): self.user_repo_id = self.repo.id + from constance import config + self.config = config def tearDown(self): self.remove_repo() @@ -26,7 +30,7 @@ class RepoTest(BaseTestCase): def test_can_get_history_limit_if_setting_not_enabled(self): self.login_as(self.user) - config.ENABLE_REPO_HISTORY_SETTING = False + self.config.ENABLE_REPO_HISTORY_SETTING = False resp = self.client.get(reverse("api2-repo-history-limit", args=[self.user_repo_id])) json_resp = json.loads(resp.content) @@ -90,7 +94,7 @@ class RepoTest(BaseTestCase): def test_can_not_set_if_setting_not_enabled(self): self.login_as(self.user) - config.ENABLE_REPO_HISTORY_SETTING = False + self.config.ENABLE_REPO_HISTORY_SETTING = False url = reverse("api2-repo-history-limit", args=[self.user_repo_id]) data = 'keep_days=%s' % 6 diff --git a/tests/api/test_repos.py b/tests/api/test_repos.py index b701e1b84b..67766aa855 100644 --- a/tests/api/test_repos.py +++ b/tests/api/test_repos.py @@ -6,7 +6,8 @@ import json import time import pytest import uuid -from constance import config +import pytest +pytestmark = pytest.mark.django_db from django.core.urlresolvers import reverse from seaserv import seafile_api @@ -163,7 +164,11 @@ class NewReposApiTest(BaseTestCase): def setUp(self): self.clear_cache() self.login_as(self.admin) - config.ENABLE_ENCRYPTED_LIBRARY = True + + from constance import config + self.config = config + + self.config.ENABLE_ENCRYPTED_LIBRARY = True def test_create_encrypted_repo(self): """Test create an encrypted repo with the secure keys generated on client @@ -198,7 +203,7 @@ class NewReposApiTest(BaseTestCase): """Test create an encrypted repo with the secure keys generated on client side. """ - config.ENABLE_ENCRYPTED_LIBRARY = False + self.config.ENABLE_ENCRYPTED_LIBRARY = False repo_id = str(uuid.uuid4()) password = randstring(16) enc_version = 2 diff --git a/tests/api/test_shared_repo.py b/tests/api/test_shared_repo.py index f4c023a14c..85d629fe03 100644 --- a/tests/api/test_shared_repo.py +++ b/tests/api/test_shared_repo.py @@ -1,18 +1,21 @@ import json +import pytest +pytestmark = pytest.mark.django_db + from seahub.test_utils import BaseTestCase - -from constance import config - from seaserv import seafile_api, ccnet_threaded_rpc class SharedRepoTest(BaseTestCase): def setUp(self): + from constance import config + self.config = config + self.repo_id = self.create_repo(name='test-admin-repo', desc='', username=self.admin.username, passwd=None) self.shared_repo_url = '/api2/shared-repos/%s/?share_type=public&permission=rw' - config.ENABLE_USER_CREATE_ORG_REPO = 1 + self.config.ENABLE_USER_CREATE_ORG_REPO = 1 def tearDown(self): self.remove_repo(self.repo_id) @@ -35,9 +38,9 @@ class SharedRepoTest(BaseTestCase): assert "success" in resp.content def test_admin_can_set_pub_repo_when_setting_disalbed(self): - assert bool(config.ENABLE_USER_CREATE_ORG_REPO) is True - config.ENABLE_USER_CREATE_ORG_REPO = False - assert bool(config.ENABLE_USER_CREATE_ORG_REPO) is False + 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) @@ -46,9 +49,9 @@ class SharedRepoTest(BaseTestCase): assert "success" in resp.content def test_user_can_not_set_pub_repo_when_setting_disalbed(self): - assert bool(config.ENABLE_USER_CREATE_ORG_REPO) is True - config.ENABLE_USER_CREATE_ORG_REPO = False - assert bool(config.ENABLE_USER_CREATE_ORG_REPO) is False + 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) diff --git a/tests/api/test_shares.py b/tests/api/test_shares.py index 3a7b8ec03b..9d4605dc21 100644 --- a/tests/api/test_shares.py +++ b/tests/api/test_shares.py @@ -1,6 +1,7 @@ #coding: UTF-8 from django.core.cache import cache -from constance import config +import pytest +pytestmark = pytest.mark.django_db from seahub.share.models import FileShare, UploadLinkShare from seahub.test_utils import BaseTestCase @@ -11,12 +12,15 @@ 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 + from constance import config + self.config = config + + self.curr_passwd_len = self.config.SHARE_LINK_PASSWORD_MIN_LENGTH + self.config.SHARE_LINK_PASSWORD_MIN_LENGTH = 3 def tearDown(self): self.remove_repo() - config.SHARE_LINK_PASSWORD_MIN_LENGTH = self.curr_passwd_len + self.config.SHARE_LINK_PASSWORD_MIN_LENGTH = self.curr_passwd_len def test_create_file_shared_link_with_invalid_path(self): self.login_as(self.user) diff --git a/tests/seahub/auth/views/test_login.py b/tests/seahub/auth/views/test_login.py index cd3b6bbf73..ee16232a7c 100644 --- a/tests/seahub/auth/views/test_login.py +++ b/tests/seahub/auth/views/test_login.py @@ -3,7 +3,8 @@ from django.core.cache import cache from django.core.urlresolvers import reverse from django.utils.http import urlquote -from constance import config +import pytest +pytestmark = pytest.mark.django_db from seahub.base.accounts import User from seahub.auth.forms import AuthenticationForm, CaptchaAuthenticationForm @@ -118,8 +119,11 @@ class LoginCaptchaTest(BaseTestCase, LoginTestMixin): def setUp(self): self.clear_cache() # make sure cache is clean - config.LOGIN_ATTEMPT_LIMIT = 3 - config.FREEZE_USER_ON_LOGIN_FAILED = False + from constance import config + self.config = config + + self.config.LOGIN_ATTEMPT_LIMIT = 3 + self.config.FREEZE_USER_ON_LOGIN_FAILED = False def tearDown(self): self.clear_cache() @@ -185,8 +189,11 @@ class FreezeUserOnLoginFailedTest(BaseTestCase, LoginTestMixin): def setUp(self): self.clear_cache() # make sure cache is clean - config.LOGIN_ATTEMPT_LIMIT = 3 - config.FREEZE_USER_ON_LOGIN_FAILED = True + from constance import config + self.config = config + + self.config.LOGIN_ATTEMPT_LIMIT = 3 + self.config.FREEZE_USER_ON_LOGIN_FAILED = True self.tmp_user = self.create_user() @@ -195,7 +202,7 @@ class FreezeUserOnLoginFailedTest(BaseTestCase, LoginTestMixin): self.remove_user(self.tmp_user.username) def test_can_freeze(self): - assert bool(config.FREEZE_USER_ON_LOGIN_FAILED) is True + assert bool(self.config.FREEZE_USER_ON_LOGIN_FAILED) is True resp = self._login_page() assert isinstance(resp.context['form'], AuthenticationForm) is True diff --git a/tests/seahub/notifications/management/commands/test_notify_admins_on_virus.py b/tests/seahub/notifications/management/commands/test_notify_admins_on_virus.py index 8ba6ec21bf..8147a45e01 100644 --- a/tests/seahub/notifications/management/commands/test_notify_admins_on_virus.py +++ b/tests/seahub/notifications/management/commands/test_notify_admins_on_virus.py @@ -1,6 +1,6 @@ from django.core import mail from django.core.management import call_command -from django.conf.urls import patterns, url +from django.conf.urls import url from django.test import override_settings import seahub @@ -12,7 +12,6 @@ urlpatterns = seahub.urls.urlpatterns + [ url(r'^sys/virus_scan_records/$', sys_virus_scan_records, name='sys_virus_scan_records'), ] - @override_settings(ROOT_URLCONF=__name__) class CommandTest(BaseTestCase): diff --git a/tests/seahub/share/test_decorators.py b/tests/seahub/share/test_decorators.py index 31ff58fee6..931433c922 100644 --- a/tests/seahub/share/test_decorators.py +++ b/tests/seahub/share/test_decorators.py @@ -1,11 +1,11 @@ from mock import patch from django.core.cache import cache -from django.contrib.auth.models import AnonymousUser from django.http import HttpResponse, Http404 from django.test import override_settings from django.test.client import RequestFactory +from seahub.auth.models import AnonymousUser from seahub.test_utils import BaseTestCase from seahub.share.decorators import share_link_audit from seahub.share.models import FileShare diff --git a/tests/seahub/thirdpart/registration/test_models.py b/tests/seahub/thirdpart/registration/test_models.py index 03885ca0f1..7a92bd03a9 100644 --- a/tests/seahub/thirdpart/registration/test_models.py +++ b/tests/seahub/thirdpart/registration/test_models.py @@ -2,9 +2,11 @@ from django.core import mail from django.core.urlresolvers import reverse from django.test import override_settings +import pytest +pytestmark = pytest.mark.django_db + from seahub.test_utils import BaseTestCase from registration import signals -from constance import config class RegisterSignalMixin(object): @@ -19,11 +21,14 @@ class EmailAdminOnRegistrationTest(BaseTestCase, RegisterSignalMixin): """ def setUp(self): self.clear_cache() - self.old_config = config.ACTIVATE_AFTER_REGISTRATION - config.ACTIVATE_AFTER_REGISTRATION = True + from constance import config + self.config = config + + self.old_config = self.config.ACTIVATE_AFTER_REGISTRATION + self.config.ACTIVATE_AFTER_REGISTRATION = True def tearDown(self): - config.ACTIVATE_AFTER_REGISTRATION = self.old_config + self.config.ACTIVATE_AFTER_REGISTRATION = self.old_config @override_settings( NOTIFY_ADMIN_AFTER_REGISTRATION=True, @@ -44,25 +49,28 @@ class EmailAdminOnRegistrationTest2(BaseTestCase, RegisterSignalMixin): def setUp(self): self.clear_cache() - self.old_cfg1 = config.ENABLE_SIGNUP - self.old_cfg2 = config.ACTIVATE_AFTER_REGISTRATION - self.old_cfg3 = config.REGISTRATION_SEND_MAIL + from constance import config + self.config = config - config.ENABLE_SIGNUP = True + self.old_cfg1 = self.config.ENABLE_SIGNUP + self.old_cfg2 = self.config.ACTIVATE_AFTER_REGISTRATION + self.old_cfg3 = self.config.REGISTRATION_SEND_MAIL + + self.config.ENABLE_SIGNUP = True self.email = 'newuser@test.com' self.remove_user(self.email) def tearDown(self): - config.ENABLE_SIGNUP = self.old_cfg1 - config.ACTIVATE_AFTER_REGISTRATION = self.old_cfg2 - config.REGISTRATION_SEND_MAIL = self.old_cfg3 + self.config.ENABLE_SIGNUP = self.old_cfg1 + self.config.ACTIVATE_AFTER_REGISTRATION = self.old_cfg2 + self.config.REGISTRATION_SEND_MAIL = self.old_cfg3 def test_notify_admin_to_activate(self): - assert bool(config.ENABLE_SIGNUP) is True + assert bool(self.config.ENABLE_SIGNUP) is True self.assertEqual(len(mail.outbox), 0) - config.ACTIVATE_AFTER_REGISTRATION = False - config.REGISTRATION_SEND_MAIL = False + self.config.ACTIVATE_AFTER_REGISTRATION = False + self.config.REGISTRATION_SEND_MAIL = False self._send_signal() diff --git a/tests/seahub/two_factor/views/test_backup_tokens_view.py b/tests/seahub/two_factor/views/test_backup_tokens_view.py index dd599bb212..ae6f3288e9 100644 --- a/tests/seahub/two_factor/views/test_backup_tokens_view.py +++ b/tests/seahub/two_factor/views/test_backup_tokens_view.py @@ -1,5 +1,6 @@ from django.core.urlresolvers import reverse -from constance import config +import pytest +pytestmark = pytest.mark.django_db from seahub.two_factor.models import StaticDevice, user_has_device from seahub.test_utils import BaseTestCase @@ -9,13 +10,16 @@ class BackupTokensViewTest(BaseTestCase): def setUp(self): self.clear_cache() + from constance import config + self.config = config + self.login_as(self.user) self.url = reverse('two_factor:backup_tokens') - self.old_conf = config.ENABLE_TWO_FACTOR_AUTH - config.ENABLE_TWO_FACTOR_AUTH = True + self.old_conf = self.config.ENABLE_TWO_FACTOR_AUTH + self.config.ENABLE_TWO_FACTOR_AUTH = True def tearDown(self): - config.ENABLE_TWO_FACTOR_AUTH = self.old_conf + self.config.ENABLE_TWO_FACTOR_AUTH = self.old_conf def test_user_2fa_not_enabled(self): resp = self.client.get(self.url) diff --git a/tests/seahub/utils/test_get_conf_test_ext.py b/tests/seahub/utils/test_get_conf_test_ext.py index 9b7e849435..95d3f14ed9 100644 --- a/tests/seahub/utils/test_get_conf_test_ext.py +++ b/tests/seahub/utils/test_get_conf_test_ext.py @@ -1,4 +1,6 @@ -from constance import config +import pytest +pytestmark = pytest.mark.django_db + from django.conf import settings from seahub.utils import get_conf_text_ext @@ -9,12 +11,15 @@ class GetConfTextExtTest(BaseTestCase): def setUp(self): self.clear_cache() + from constance import config + self.config = config + def tearDown(self): self.clear_cache() def test_get(self): - assert config.TEXT_PREVIEW_EXT == settings.TEXT_PREVIEW_EXT + assert self.config.TEXT_PREVIEW_EXT == settings.TEXT_PREVIEW_EXT orig_preview_ext = settings.TEXT_PREVIEW_EXT - config.TEXT_PREVIEW_EXT = orig_preview_ext + ',az' + self.config.TEXT_PREVIEW_EXT = orig_preview_ext + ',az' assert 'az' in get_conf_text_ext() diff --git a/tests/seahub/views/file/test_send_file_access_msg.py b/tests/seahub/views/file/test_send_file_access_msg.py index 04248cf8e8..e3125a5286 100644 --- a/tests/seahub/views/file/test_send_file_access_msg.py +++ b/tests/seahub/views/file/test_send_file_access_msg.py @@ -1,6 +1,6 @@ -from django.contrib.auth.models import AnonymousUser from django.test.client import RequestFactory +from seahub.auth.models import AnonymousUser from seahub.test_utils import BaseTestCase from seahub.views.file import send_file_access_msg diff --git a/tests/seahub/views/init/test_libraries.py b/tests/seahub/views/init/test_libraries.py index a90bb3fc1a..a6ee4f4920 100644 --- a/tests/seahub/views/init/test_libraries.py +++ b/tests/seahub/views/init/test_libraries.py @@ -1,8 +1,8 @@ import json from django.core.urlresolvers import reverse - -from constance import config +import pytest +pytestmark = pytest.mark.django_db from seahub.options.models import UserOptions from seahub.test_utils import BaseTestCase @@ -10,6 +10,8 @@ from seahub.test_utils import BaseTestCase class LibrariesTest(BaseTestCase): def setUp(self): self.url = reverse('libraries') + from constance import config + self.config = config def test_user_guide(self): self.login_as(self.user) @@ -34,15 +36,15 @@ class LibrariesTest(BaseTestCase): # user self.login_as(self.user) - config.ENABLE_USER_CREATE_ORG_REPO = 1 - assert bool(config.ENABLE_USER_CREATE_ORG_REPO) is True + self.config.ENABLE_USER_CREATE_ORG_REPO = 1 + assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True resp = self.client.get(self.url) self.assertEqual(200, resp.status_code) assert resp.context['can_add_pub_repo'] is True - config.ENABLE_USER_CREATE_ORG_REPO = 0 - assert bool(config.ENABLE_USER_CREATE_ORG_REPO) is False + self.config.ENABLE_USER_CREATE_ORG_REPO = 0 + assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False resp = self.client.get(self.url) self.assertEqual(200, resp.status_code) @@ -54,15 +56,15 @@ class LibrariesTest(BaseTestCase): # admin self.login_as(self.admin) - config.ENABLE_USER_CREATE_ORG_REPO = 1 - assert bool(config.ENABLE_USER_CREATE_ORG_REPO) is True + self.config.ENABLE_USER_CREATE_ORG_REPO = 1 + assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is True resp = self.client.get(self.url) self.assertEqual(200, resp.status_code) assert resp.context['can_add_pub_repo'] is True - config.ENABLE_USER_CREATE_ORG_REPO = 0 - assert bool(config.ENABLE_USER_CREATE_ORG_REPO) is False + self.config.ENABLE_USER_CREATE_ORG_REPO = 0 + assert bool(self.config.ENABLE_USER_CREATE_ORG_REPO) is False resp = self.client.get(self.url) self.assertEqual(200, resp.status_code) diff --git a/tests/seahub/views/sysadmin/test_sys_sudo_mode.py b/tests/seahub/views/sysadmin/test_sys_sudo_mode.py index 5cc6063bf7..fea3e70ab4 100644 --- a/tests/seahub/views/sysadmin/test_sys_sudo_mode.py +++ b/tests/seahub/views/sysadmin/test_sys_sudo_mode.py @@ -1,6 +1,7 @@ from django.core.urlresolvers import reverse -from constance import config +import pytest +pytestmark = pytest.mark.django_db from seahub.test_utils import BaseTestCase @@ -8,15 +9,17 @@ from seahub.test_utils import BaseTestCase class SysSettingsTest(BaseTestCase): def setUp(self): self.clear_cache() # make sure cache is clean + from constance import config + self.config = config - self.old_config = config.LOGIN_ATTEMPT_LIMIT - config.LOGIN_ATTEMPT_LIMIT = 1 + self.old_config = self.config.LOGIN_ATTEMPT_LIMIT + self.config.LOGIN_ATTEMPT_LIMIT = 1 self.url = reverse('sys_sudo_mode') self.login_as(self.admin) def tearDown(self): - config.LOGIN_ATTEMPT_LIMIT = self.old_config + self.config.LOGIN_ATTEMPT_LIMIT = self.old_config self.clear_cache() def test_can_get(self): diff --git a/tests/seahub/views/sysadmin/test_sysadmin.py b/tests/seahub/views/sysadmin/test_sysadmin.py index 6d8c12c403..72645b6fc6 100644 --- a/tests/seahub/views/sysadmin/test_sysadmin.py +++ b/tests/seahub/views/sysadmin/test_sysadmin.py @@ -10,7 +10,8 @@ from seahub.options.models import (UserOptions, KEY_FORCE_PASSWD_CHANGE) from seahub.test_utils import BaseTestCase from seahub.utils.ms_excel import write_xls as real_write_xls -from constance import config +import pytest +pytestmark = pytest.mark.django_db from seaserv import ccnet_threaded_rpc @@ -167,6 +168,9 @@ class BatchAddUserTest(BaseTestCase): self.clear_cache() self.login_as(self.admin) + from constance import config + self.config = config + self.new_users = [] self.excel_file = os.path.join(os.getcwd(), 'tests/seahub/views/sysadmin/batch_add_user.xlsx') data_list = [] @@ -209,7 +213,7 @@ class BatchAddUserTest(BaseTestCase): assert User.objects.get(e) is not None def test_can_batch_add_when_pwd_change_required(self): - config.FORCE_PASSWORD_CHANGE = 1 + self.config.FORCE_PASSWORD_CHANGE = 1 for e in self.new_users: assert len(UserOptions.objects.filter( @@ -234,7 +238,7 @@ class BatchAddUserTest(BaseTestCase): assert UserOptions.objects.passwd_change_required(e) def test_can_batch_add_when_pwd_change_not_required(self): - config.FORCE_PASSWORD_CHANGE = 0 + self.config.FORCE_PASSWORD_CHANGE = 0 for e in self.new_users: assert len(UserOptions.objects.filter( diff --git a/tests/seahub/views/sysadmin/test_user_add.py b/tests/seahub/views/sysadmin/test_user_add.py index 0c3ea9640c..c6dbb6069e 100644 --- a/tests/seahub/views/sysadmin/test_user_add.py +++ b/tests/seahub/views/sysadmin/test_user_add.py @@ -1,5 +1,6 @@ from django.core.urlresolvers import reverse -from constance import config +import pytest +pytestmark = pytest.mark.django_db from seahub.options.models import (UserOptions, KEY_FORCE_PASSWD_CHANGE, VAL_FORCE_PASSWD_CHANGE) @@ -9,13 +10,15 @@ from seahub.test_utils import BaseTestCase class UserAddTest(BaseTestCase): def setUp(self): self.clear_cache() + from constance import config + self.config = config self.new_user = 'new_user@test.com' self.login_as(self.admin) self.remove_user(self.new_user) def test_can_add_when_pwd_change_required(self): - config.FORCE_PASSWORD_CHANGE = 1 + self.config.FORCE_PASSWORD_CHANGE = 1 assert len(UserOptions.objects.filter( email=self.new_user, option_key=KEY_FORCE_PASSWD_CHANGE)) == 0 @@ -34,7 +37,7 @@ class UserAddTest(BaseTestCase): option_key=KEY_FORCE_PASSWD_CHANGE).option_val == VAL_FORCE_PASSWD_CHANGE def test_can_add_when_pwd_change_not_required(self): - config.FORCE_PASSWORD_CHANGE = 0 + self.config.FORCE_PASSWORD_CHANGE = 0 assert len(UserOptions.objects.filter( email=self.new_user, option_key=KEY_FORCE_PASSWD_CHANGE)) == 0 diff --git a/tests/seahub/views/sysadmin/test_user_reset.py b/tests/seahub/views/sysadmin/test_user_reset.py index 2e9b0f35f7..0f2c35cb73 100644 --- a/tests/seahub/views/sysadmin/test_user_reset.py +++ b/tests/seahub/views/sysadmin/test_user_reset.py @@ -1,7 +1,8 @@ from mock import patch from django.core import mail from django.core.urlresolvers import reverse -from constance import config +import pytest +pytestmark = pytest.mark.django_db from seahub.base.accounts import User from seahub.options.models import (UserOptions, KEY_FORCE_PASSWD_CHANGE, @@ -13,6 +14,8 @@ from seahub.test_utils import BaseTestCase class UserResetTest(BaseTestCase): def setUp(self): self.clear_cache() + from constance import config + self.config = config self.login_as(self.admin) @@ -37,7 +40,7 @@ class UserResetTest(BaseTestCase): self.assertEqual(len(mail.outbox), 1) def test_can_reset_when_pwd_change_required(self): - config.FORCE_PASSWORD_CHANGE = 1 + self.config.FORCE_PASSWORD_CHANGE = 1 assert len(UserOptions.objects.filter( email=self.user.username, option_key=KEY_FORCE_PASSWD_CHANGE)) == 0 @@ -55,7 +58,7 @@ class UserResetTest(BaseTestCase): option_key=KEY_FORCE_PASSWD_CHANGE).option_val == VAL_FORCE_PASSWD_CHANGE def test_can_reset_when_pwd_change_not_required(self): - config.FORCE_PASSWORD_CHANGE = 0 + self.config.FORCE_PASSWORD_CHANGE = 0 assert len(UserOptions.objects.filter( email=self.user.username, option_key=KEY_FORCE_PASSWD_CHANGE)) == 0