Changeset - 9f8a1212177e
[Not reviewed]
default
0 5 0
Thomas De Schampheleire - 9 years ago 2017-01-15 20:57:47
thomas.de.schampheleire@gmail.com
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).
5 files changed with 44 insertions and 27 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/functional/test_admin_permissions.py
Show inline comments
 
@@ -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
kallithea/tests/functional/test_admin_users.py
Show inline comments
 
@@ -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("""<span class="error-message">%s</span>""" % msg)
 
        response.mustcontain("""<span class="error-message">Please enter a value</span>""")
 
@@ -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):
kallithea/tests/functional/test_login.py
Show inline comments
 
@@ -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):
kallithea/tests/functional/test_my_account.py
Show inline comments
 
@@ -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)
 

	
kallithea/tests/other/test_validators.py
Show inline comments
 
@@ -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):
0 comments (0 inline, 0 general)