Mercurial > kallithea
changeset 6568:9f8a1212177e
tests: use test_context for tests needing internationalization (bis)
Commit 8e3137064ab6 already introduced the use of test_context to cover
internationalization in the test suite, instead of setting it up globally.
When making changes related to formencode internationalization, a new batch
of internationalization errors popped up and a commit was made to fix them.
However, after some later refactoring, it looked as if the commit was not
needed anymore.
In Turbogears context, it was indeed not necessary as long as we still had
some places that used the dummy formencode.api._ rather than a real version
of _ (ugettext).
After cleaning up that forgotten import, the test internationalization
errors popped up again. Hence, we need to reapply the earlier commit (with
some changes).
author | Thomas De Schampheleire <thomas.de.schampheleire@gmail.com> |
---|---|
date | Sun, 15 Jan 2017 20:57:47 +0100 |
parents | 3c469080bb2a |
children | e1ab82613133 |
files | kallithea/tests/functional/test_admin_permissions.py kallithea/tests/functional/test_admin_users.py kallithea/tests/functional/test_login.py kallithea/tests/functional/test_my_account.py kallithea/tests/other/test_validators.py |
diffstat | 5 files changed, 44 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/tests/functional/test_admin_permissions.py Thu Apr 06 03:33:51 2017 +0200 +++ b/kallithea/tests/functional/test_admin_permissions.py Sun Jan 15 20:57:47 2017 +0100 @@ -5,6 +5,9 @@ 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 @@ ## 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
--- a/kallithea/tests/functional/test_admin_users.py Thu Apr 06 03:33:51 2017 +0200 +++ b/kallithea/tests/functional/test_admin_users.py Sun Jan 15 20:57:47 2017 +0100 @@ -111,7 +111,8 @@ '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("""<span class="error-message">%s</span>""" % msg) response.mustcontain("""<span class="error-message">Please enter a value</span>""") @@ -431,8 +432,9 @@ 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_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):
--- a/kallithea/tests/functional/test_login.py Thu Apr 06 03:33:51 2017 +0200 +++ b/kallithea/tests/functional/test_login.py Sun Jan 15 20:57:47 2017 +0100 @@ -16,6 +16,8 @@ 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 @@ '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 @@ '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 @@ '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 @@ '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 @@ '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 @@ '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):
--- a/kallithea/tests/functional/test_my_account.py Thu Apr 06 03:33:51 2017 +0200 +++ b/kallithea/tests/functional/test_my_account.py Sun Jan 15 20:57:47 2017 +0100 @@ -7,6 +7,8 @@ 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 @@ 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)
--- a/kallithea/tests/other/test_validators.py Thu Apr 06 03:33:51 2017 +0200 +++ b/kallithea/tests/other/test_validators.py Sun Jan 15 20:57:47 2017 +0100 @@ -15,6 +15,7 @@ fixture = Fixture() +@pytest.mark.usefixtures("test_context_fixture") # apply fixture for all test methods class TestRepoGroups(TestController): def teardown_method(self, method):