diff --git a/kallithea/tests/functional/test_admin_permissions.py b/kallithea/tests/functional/test_admin_permissions.py --- a/kallithea/tests/functional/test_admin_permissions.py +++ b/kallithea/tests/functional/test_admin_permissions.py @@ -5,6 +5,9 @@ from kallithea.model.user import UserMod from kallithea.model.meta import Session from kallithea.tests.base import * +from kallithea.tests.test_context import test_context + + class TestAdminPermissionsController(TestController): def test_index(self): @@ -42,9 +45,10 @@ class TestAdminPermissionsController(Tes ## first add new_ip = '127.0.0.0/24' - user_model = UserModel() - ip_obj = user_model.add_extra_ip(default_user_id, new_ip) - Session().commit() + with test_context(self.app): + user_model = UserModel() + ip_obj = user_model.add_extra_ip(default_user_id, new_ip) + Session().commit() ## double check that add worked # IP permissions are cached, need to invalidate this cache explicitly diff --git a/kallithea/tests/functional/test_admin_users.py b/kallithea/tests/functional/test_admin_users.py --- a/kallithea/tests/functional/test_admin_users.py +++ b/kallithea/tests/functional/test_admin_users.py @@ -111,7 +111,8 @@ class TestAdminUsersController(TestContr 'email': email, '_authentication_token': self.authentication_token()}) - msg = validators.ValidUsername(False, {})._messages['system_invalid_username'] + with test_context(self.app): + msg = validators.ValidUsername(False, {})._messages['system_invalid_username'] msg = h.html_escape(msg % {'username': 'new_user'}) response.mustcontain("""%s""" % msg) response.mustcontain("""Please enter a value""") @@ -431,8 +432,9 @@ class TestAdminUsersController(TestContr user_id = user.user_id ip = '127.0.0.1/32' ip_range = '127.0.0.1 - 127.0.0.1' - new_ip = UserModel().add_extra_ip(user_id, ip) - Session().commit() + with test_context(self.app): + new_ip = UserModel().add_extra_ip(user_id, ip) + Session().commit() new_ip_id = new_ip.ip_id response = self.app.get(url('edit_user_ips', id=user_id)) @@ -517,20 +519,19 @@ class TestAdminUsersController(TestContr class TestAdminUsersController_unittest(TestController): """ Unit tests for the users controller """ - def test_get_user_or_raise_if_default(self, monkeypatch): - with test_context(self.app): - # flash complains about an non-existing session - def flash_mock(*args, **kwargs): - pass - monkeypatch.setattr(h, 'flash', flash_mock) + def test_get_user_or_raise_if_default(self, monkeypatch, test_context_fixture): + # flash complains about an non-existing session + def flash_mock(*args, **kwargs): + pass + monkeypatch.setattr(h, 'flash', flash_mock) - u = UsersController() - # a regular user should work correctly - user = User.get_by_username(TEST_USER_REGULAR_LOGIN) - assert u._get_user_or_raise_if_default(user.user_id) == user - # the default user should raise - with pytest.raises(HTTPNotFound): - u._get_user_or_raise_if_default(User.get_default_user().user_id) + u = UsersController() + # a regular user should work correctly + user = User.get_by_username(TEST_USER_REGULAR_LOGIN) + assert u._get_user_or_raise_if_default(user.user_id) == user + # the default user should raise + with pytest.raises(HTTPNotFound): + u._get_user_or_raise_if_default(User.get_default_user().user_id) class TestAdminUsersControllerForDefaultUser(TestController): diff --git a/kallithea/tests/functional/test_login.py b/kallithea/tests/functional/test_login.py --- a/kallithea/tests/functional/test_login.py +++ b/kallithea/tests/functional/test_login.py @@ -16,6 +16,8 @@ from kallithea.model.db import User, Not from kallithea.model.meta import Session from kallithea.model.user import UserModel +from kallithea.tests.test_context import test_context + fixture = Fixture() @@ -219,7 +221,8 @@ class TestLoginController(TestController 'firstname': 'test', 'lastname': 'test'}) - msg = validators.ValidUsername()._messages['username_exists'] + with test_context(self.app): + msg = validators.ValidUsername()._messages['username_exists'] msg = h.html_escape(msg % {'username': uname}) response.mustcontain(msg) @@ -232,7 +235,8 @@ class TestLoginController(TestController 'firstname': 'test', 'lastname': 'test'}) - msg = validators.UniqSystemEmail()()._messages['email_taken'] + with test_context(self.app): + msg = validators.UniqSystemEmail()()._messages['email_taken'] response.mustcontain(msg) def test_register_err_same_email_case_sensitive(self): @@ -243,7 +247,8 @@ class TestLoginController(TestController 'email': TEST_USER_ADMIN_EMAIL.title(), 'firstname': 'test', 'lastname': 'test'}) - msg = validators.UniqSystemEmail()()._messages['email_taken'] + with test_context(self.app): + msg = validators.UniqSystemEmail()()._messages['email_taken'] response.mustcontain(msg) def test_register_err_wrong_data(self): @@ -284,7 +289,8 @@ class TestLoginController(TestController 'lastname': 'test'}) response.mustcontain('An email address must contain a single @') - msg = validators.ValidUsername()._messages['username_exists'] + with test_context(self.app): + msg = validators.ValidUsername()._messages['username_exists'] msg = h.html_escape(msg % {'username': usr}) response.mustcontain(msg) @@ -297,7 +303,8 @@ class TestLoginController(TestController 'firstname': 'test', 'lastname': 'test'}) - msg = validators.ValidPassword()._messages['invalid_password'] + with test_context(self.app): + msg = validators.ValidPassword()._messages['invalid_password'] response.mustcontain(msg) def test_register_password_mismatch(self): @@ -308,7 +315,8 @@ class TestLoginController(TestController 'email': 'goodmailm@test.plxa', 'firstname': 'test', 'lastname': 'test'}) - msg = validators.ValidPasswordsMatch('password', 'password_confirmation')._messages['password_mismatch'] + with test_context(self.app): + msg = validators.ValidPasswordsMatch('password', 'password_confirmation')._messages['password_mismatch'] response.mustcontain(msg) def test_register_ok(self): diff --git a/kallithea/tests/functional/test_my_account.py b/kallithea/tests/functional/test_my_account.py --- a/kallithea/tests/functional/test_my_account.py +++ b/kallithea/tests/functional/test_my_account.py @@ -7,6 +7,8 @@ from kallithea.lib import helpers as h from kallithea.model.user import UserModel from kallithea.model.meta import Session +from kallithea.tests.test_context import test_context + fixture = Fixture() @@ -180,8 +182,9 @@ class TestMyAccountController(TestContro response.mustcontain('An email address must contain a single @') from kallithea.model import validators - msg = validators.ValidUsername(edit=False, old_data={}) \ - ._messages['username_exists'] + with test_context(self.app): + msg = validators.ValidUsername(edit=False, old_data={}) \ + ._messages['username_exists'] msg = h.html_escape(msg % {'username': TEST_USER_ADMIN_LOGIN}) response.mustcontain(msg) diff --git a/kallithea/tests/other/test_validators.py b/kallithea/tests/other/test_validators.py --- a/kallithea/tests/other/test_validators.py +++ b/kallithea/tests/other/test_validators.py @@ -15,6 +15,7 @@ from kallithea.tests.fixture import Fixt fixture = Fixture() +@pytest.mark.usefixtures("test_context_fixture") # apply fixture for all test methods class TestRepoGroups(TestController): def teardown_method(self, method):