diff --git a/rhodecode/tests/__init__.py b/rhodecode/tests/__init__.py --- a/rhodecode/tests/__init__.py +++ b/rhodecode/tests/__init__.py @@ -35,6 +35,7 @@ import pylons import pylons.test from pylons import config, url from pylons.i18n.translation import _get_translator +from pylons.util import ContextObj from routes.util import URLGenerator from webtest import TestApp @@ -55,7 +56,7 @@ log = logging.getLogger(__name__) __all__ = [ 'parameterized', 'environ', 'url', 'get_new_dir', 'TestController', - 'SkipTest', 'ldap_lib_installed', + 'SkipTest', 'ldap_lib_installed', 'BaseTestCase', 'init_stack', 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', 'HG_FORK', 'GIT_FORK', 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS', 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS', @@ -144,23 +145,31 @@ def get_new_dir(title): return get_normalized_path(path) -class TestController(TestCase): +def init_stack(config=None): + if not config: + config = pylons.test.pylonsapp.config + url._push_object(URLGenerator(config['routes.map'], environ)) + pylons.app_globals._push_object(config['pylons.app_globals']) + pylons.config._push_object(config) + pylons.tmpl_context._push_object(ContextObj()) + # Initialize a translator for tests that utilize i18n + translator = _get_translator(pylons.config.get('lang')) + pylons.translator._push_object(translator) + + +class BaseTestCase(TestCase): + def __init__(self, *args, **kwargs): + self.wsgiapp = pylons.test.pylonsapp + init_stack(self.wsgiapp.config) + TestCase.__init__(self, *args, **kwargs) + + +class TestController(BaseTestCase): def __init__(self, *args, **kwargs): - wsgiapp = pylons.test.pylonsapp - config = wsgiapp.config - - self.app = TestApp(wsgiapp) - url._push_object(URLGenerator(config['routes.map'], environ)) - pylons.app_globals._push_object(config['pylons.app_globals']) - pylons.config._push_object(config) - - # Initialize a translator for tests that utilize i18n - translator = _get_translator(pylons.config.get('lang')) - pylons.translator._push_object(translator) - + BaseTestCase.__init__(self, *args, **kwargs) + self.app = TestApp(self.wsgiapp) self.index_location = config['app_conf']['index_dir'] - TestCase.__init__(self, *args, **kwargs) def log_user(self, username=TEST_USER_ADMIN_LOGIN, password=TEST_USER_ADMIN_PASS): diff --git a/rhodecode/tests/models/common.py b/rhodecode/tests/models/common.py --- a/rhodecode/tests/models/common.py +++ b/rhodecode/tests/models/common.py @@ -1,6 +1,3 @@ -import os -import unittest -import functools from rhodecode.tests import * from rhodecode.tests.fixture import Fixture diff --git a/rhodecode/tests/models/test_diff_parsers.py b/rhodecode/tests/models/test_diff_parsers.py --- a/rhodecode/tests/models/test_diff_parsers.py +++ b/rhodecode/tests/models/test_diff_parsers.py @@ -1,6 +1,5 @@ from __future__ import with_statement import os -import unittest from rhodecode.tests import * from rhodecode.lib.diffs import DiffProcessor, NEW_FILENODE, DEL_FILENODE, \ MOD_FILENODE, RENAMED_FILENODE, CHMOD_FILENODE, BIN_FILENODE @@ -236,7 +235,7 @@ DIFF_FIXTURES = { } -class DiffLibTest(unittest.TestCase): +class DiffLibTest(BaseTestCase): @parameterized.expand([(x,) for x in DIFF_FIXTURES]) def test_diff(self, diff_fixture): diff --git a/rhodecode/tests/models/test_notifications.py b/rhodecode/tests/models/test_notifications.py --- a/rhodecode/tests/models/test_notifications.py +++ b/rhodecode/tests/models/test_notifications.py @@ -1,5 +1,3 @@ -import os -import unittest from rhodecode.tests import * from rhodecode.model.db import User, Notification, UserNotification @@ -9,7 +7,7 @@ from rhodecode.model.meta import Session from rhodecode.model.notification import NotificationModel -class TestNotifications(unittest.TestCase): +class TestNotifications(BaseTestCase): def __init__(self, methodName='runTest'): Session.remove() diff --git a/rhodecode/tests/models/test_permissions.py b/rhodecode/tests/models/test_permissions.py --- a/rhodecode/tests/models/test_permissions.py +++ b/rhodecode/tests/models/test_permissions.py @@ -1,5 +1,3 @@ -import os -import unittest from rhodecode.tests import * from rhodecode.tests.fixture import Fixture from rhodecode.model.repos_group import ReposGroupModel @@ -17,7 +15,7 @@ from rhodecode.model.permission import P fixture = Fixture() -class TestPermissions(unittest.TestCase): +class TestPermissions(BaseTestCase): def __init__(self, methodName='runTest'): super(TestPermissions, self).__init__(methodName=methodName) diff --git a/rhodecode/tests/models/test_repos.py b/rhodecode/tests/models/test_repos.py --- a/rhodecode/tests/models/test_repos.py +++ b/rhodecode/tests/models/test_repos.py @@ -1,5 +1,3 @@ -import os -import unittest from rhodecode.tests import * from rhodecode.model.meta import Session @@ -11,7 +9,7 @@ from rhodecode.lib.exceptions import Att fixture = Fixture() -class TestRepos(unittest.TestCase): +class TestRepos(BaseTestCase): def setUp(self): pass diff --git a/rhodecode/tests/models/test_repos_groups.py b/rhodecode/tests/models/test_repos_groups.py --- a/rhodecode/tests/models/test_repos_groups.py +++ b/rhodecode/tests/models/test_repos_groups.py @@ -1,5 +1,4 @@ import os -import unittest from sqlalchemy.exc import IntegrityError from rhodecode.tests import * @@ -34,7 +33,7 @@ def _update_repo(name, **kwargs): return r -class TestReposGroups(unittest.TestCase): +class TestReposGroups(BaseTestCase): def setUp(self): self.g1 = fixture.create_group('test1', skip_if_exists=True) diff --git a/rhodecode/tests/models/test_user_permissions_on_groups.py b/rhodecode/tests/models/test_user_permissions_on_groups.py --- a/rhodecode/tests/models/test_user_permissions_on_groups.py +++ b/rhodecode/tests/models/test_user_permissions_on_groups.py @@ -1,5 +1,3 @@ -import os -import unittest import functools from rhodecode.tests import * @@ -10,7 +8,6 @@ from rhodecode.model.meta import Session from nose.tools import with_setup from rhodecode.tests.models.common import _create_project_tree, check_tree_perms, \ _get_perms, _check_expected_count, expected_count, _destroy_project_tree -from rhodecode.model.repo import RepoModel test_u1_id = None diff --git a/rhodecode/tests/models/test_users.py b/rhodecode/tests/models/test_users.py --- a/rhodecode/tests/models/test_users.py +++ b/rhodecode/tests/models/test_users.py @@ -1,4 +1,3 @@ -import unittest from rhodecode.tests import * from rhodecode.model.db import User, UserGroup, UserGroupMember, UserEmailMap,\ @@ -12,7 +11,7 @@ from rhodecode.tests.fixture import Fixt fixture = Fixture() -class TestUser(unittest.TestCase): +class TestUser(BaseTestCase): def __init__(self, methodName='runTest'): Session.remove() super(TestUser, self).__init__(methodName=methodName) @@ -87,7 +86,7 @@ class TestUser(unittest.TestCase): Session().commit() -class TestUsers(unittest.TestCase): +class TestUsers(BaseTestCase): def __init__(self, methodName='runTest'): super(TestUsers, self).__init__(methodName=methodName) diff --git a/rhodecode/tests/models/test_users_group_permissions_on_groups.py b/rhodecode/tests/models/test_users_group_permissions_on_groups.py --- a/rhodecode/tests/models/test_users_group_permissions_on_groups.py +++ b/rhodecode/tests/models/test_users_group_permissions_on_groups.py @@ -1,5 +1,3 @@ -import os -import unittest import functools from rhodecode.tests import * diff --git a/rhodecode/tests/other/test_libs.py b/rhodecode/tests/other/test_libs.py --- a/rhodecode/tests/other/test_libs.py +++ b/rhodecode/tests/other/test_libs.py @@ -23,7 +23,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . from __future__ import with_statement -import unittest import datetime import hashlib import mock @@ -64,7 +63,7 @@ TEST_URLS += [ ] -class TestLibs(unittest.TestCase): +class TestLibs(BaseTestCase): @parameterized.expand(TEST_URLS) def test_uri_filter(self, test_url, expected, expected_creds): diff --git a/rhodecode/tests/other/test_validators.py b/rhodecode/tests/other/test_validators.py --- a/rhodecode/tests/other/test_validators.py +++ b/rhodecode/tests/other/test_validators.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -import unittest import formencode from rhodecode.tests import * @@ -16,7 +15,7 @@ from rhodecode.tests.fixture import Fixt fixture = Fixture() -class TestReposGroups(unittest.TestCase): +class TestReposGroups(BaseTestCase): def setUp(self): pass diff --git a/rhodecode/tests/other/test_vcs_operations.py b/rhodecode/tests/other/test_vcs_operations.py --- a/rhodecode/tests/other/test_vcs_operations.py +++ b/rhodecode/tests/other/test_vcs_operations.py @@ -151,7 +151,7 @@ def set_anonymous_access(enable=True): # TESTS #============================================================================== -class TestVCSOperations(unittest.TestCase): +class TestVCSOperations(BaseTestCase): @classmethod def setup_class(cls):