Changeset - 8e3137064ab6
[Not reviewed]
default
0 4 0
Thomas De Schampheleire - 9 years ago 2016-11-22 09:04:45
thomas.de.schampheleire@gmail.com
tests: use test_context for tests needing internationalization

Instead of relying on the top-level handling of the translator, use the
newly introduced test_context.
4 files changed with 23 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/functional/test_admin_notifications.py
Show inline comments
 
@@ -6,6 +6,7 @@ from kallithea.model.notification import
 
from kallithea.model.meta import Session
 
from kallithea.lib import helpers as h
 

	
 
from kallithea.tests.test_context import test_context
 

	
 
class TestNotificationsController(TestController):
 
    def setup_method(self, method):
 
@@ -24,10 +25,12 @@ class TestNotificationsController(TestCo
 
        response = self.app.get(url('notifications'))
 
        response.mustcontain('<div class="table">No notifications here yet</div>')
 

	
 
        with test_context(self.app):
 
        cur_user = self._get_logged_user()
 
        notif = NotificationModel().create(created_by=u1, subject=u'test_notification_1',
 
                                           body=u'notification_1', recipients=[cur_user])
 
        Session().commit()
 

	
 
        response = self.app.get(url('notifications'))
 
        response.mustcontain('id="notification_%s"' % notif.notification_id)
 

	
 
@@ -35,6 +38,7 @@ class TestNotificationsController(TestCo
 
        self.log_user()
 
        cur_user = self._get_logged_user()
 

	
 
        with test_context(self.app):
 
        u1 = create_test_user(dict(username='u1', password='qweqwe',
 
                                   email='u1@example.com',
 
                                   firstname=u'u1', lastname=u'u1',
 
@@ -70,6 +74,7 @@ class TestNotificationsController(TestCo
 

	
 
    def test_show(self, create_test_user):
 
        self.log_user()
 
        with test_context(self.app):
 
        cur_user = self._get_logged_user()
 
        u1 = create_test_user(dict(username='u1', password='qweqwe',
 
                                   email='u1@example.com',
 
@@ -96,9 +101,11 @@ class TestNotificationsController(TestCo
 

	
 
    def test_description_with_age(self):
 
        self.log_user()
 
        with test_context(self.app):
 
        cur_user = self._get_logged_user()
 
        subject = u'test'
 
        notify_body = u'hi there'
 

	
 
        notification = NotificationModel().create(created_by = cur_user,
 
                                                  subject    = subject,
 
                                                  body       = notify_body)
 
@@ -111,6 +118,7 @@ class TestNotificationsController(TestCo
 

	
 
    def test_description_with_datetime(self):
 
        self.log_user()
 
        with test_context(self.app):
 
        cur_user = self._get_logged_user()
 
        subject = u'test'
 
        notify_body = u'hi there'
 
@@ -126,6 +134,7 @@ class TestNotificationsController(TestCo
 

	
 
    def test_mark_all_read(self, create_test_user):
 
        self.log_user()
 
        with test_context(self.app):
 
        u0 = self._get_logged_user()
 
        u1 = create_test_user(dict(username='u1', password='qweqwe',
 
                                   email='u1@example.com',
kallithea/tests/functional/test_admin_users.py
Show inline comments
 
@@ -17,6 +17,7 @@ from sqlalchemy.orm.exc import NoResultF
 
import pytest
 
from kallithea.tests.base import *
 
from kallithea.tests.fixture import Fixture
 
from kallithea.tests.test_context import test_context
 
from kallithea.controllers.admin.users import UsersController
 
from kallithea.model.db import User, Permission, UserIpMap, UserApiKeys
 
from kallithea.lib.auth import check_password
 
@@ -513,10 +514,11 @@ class TestAdminUsersController(TestContr
 
        response.mustcontain(no=[api_key])
 

	
 

	
 
class TestAdminUsersController_unittest(object):
 
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
kallithea/tests/models/test_notifications.py
Show inline comments
 
@@ -14,6 +14,7 @@ from kallithea.model.notification import
 
import kallithea.lib.celerylib
 
import kallithea.lib.celerylib.tasks
 

	
 
from kallithea.tests.test_context import test_context
 

	
 
class TestNotifications(TestController):
 

	
 
@@ -45,6 +46,7 @@ class TestNotifications(TestController):
 
        assert [] == UserNotification.query().all()
 

	
 
    def test_create_notification(self):
 
        with test_context(self.app):
 
        usrs = [self.u1, self.u2]
 
        def send_email(recipients, subject, body='', html_body='', headers=None, author=None):
 
            assert recipients == ['u2@example.com']
 
@@ -73,6 +75,7 @@ class TestNotifications(TestController):
 
        assert set([x.user_id for x in unotification]) == set(usrs)
 

	
 
    def test_user_notifications(self):
 
        with test_context(self.app):
 
        notification1 = NotificationModel().create(created_by=self.u1,
 
                                            subject=u'subj', body=u'hi there1',
 
                                            recipients=[self.u3])
 
@@ -86,6 +89,7 @@ class TestNotifications(TestController):
 
        assert sorted([x.notification for x in u3.notifications]) == sorted([notification2, notification1])
 

	
 
    def test_delete_notifications(self):
 
        with test_context(self.app):
 
        notification = NotificationModel().create(created_by=self.u1,
 
                                           subject=u'title', body=u'hi there3',
 
                                    recipients=[self.u3, self.u1, self.u2])
 
@@ -104,6 +108,7 @@ class TestNotifications(TestController):
 
        assert un == []
 

	
 
    def test_delete_association(self):
 
        with test_context(self.app):
 
        notification = NotificationModel().create(created_by=self.u1,
 
                                           subject=u'title', body=u'hi there3',
 
                                    recipients=[self.u3, self.u1, self.u2])
 
@@ -147,6 +152,7 @@ class TestNotifications(TestController):
 
        assert u2notification != None
 

	
 
    def test_notification_counter(self):
 
        with test_context(self.app):
 
        NotificationModel().create(created_by=self.u1,
 
                            subject=u'title', body=u'hi there_delete',
 
                            recipients=[self.u3, self.u1])
 
@@ -184,6 +190,7 @@ class TestNotifications(TestController):
 
            l.append(html_body)
 
            l.append('<hr/>\n')
 

	
 
        with test_context(self.app):
 
        with mock.patch.object(kallithea.lib.celerylib.tasks, 'send_email', send_email):
 
            pr_kwargs = dict(
 
                pr_nice_id='#7',
kallithea/tests/other/test_libs.py
Show inline comments
 
@@ -31,6 +31,7 @@ import mock
 
from kallithea.tests.base import *
 
from kallithea.lib.utils2 import AttributeDict
 
from kallithea.model.db import Repository
 
from kallithea.tests.test_context import test_context
 

	
 
proto = 'http'
 
TEST_URLS = [
 
@@ -154,6 +155,7 @@ class TestLibs(TestController):
 
    def test_age(self, age_args, expected):
 
        from kallithea.lib.utils2 import age
 
        from dateutil import relativedelta
 
        with test_context(self.app):
 
        n = datetime.datetime(year=2012, month=5, day=17)
 
        delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs)
 
        assert age(n + delt(**age_args), now=n) == expected
 
@@ -178,6 +180,7 @@ class TestLibs(TestController):
 
    def test_age_short(self, age_args, expected):
 
        from kallithea.lib.utils2 import age
 
        from dateutil import relativedelta
 
        with test_context(self.app):
 
        n = datetime.datetime(year=2012, month=5, day=17)
 
        delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs)
 
        assert age(n + delt(**age_args), show_short_version=True, now=n) == expected
 
@@ -196,6 +199,7 @@ class TestLibs(TestController):
 
    def test_age_in_future(self, age_args, expected):
 
        from kallithea.lib.utils2 import age
 
        from dateutil import relativedelta
 
        with test_context(self.app):
 
        n = datetime.datetime(year=2012, month=5, day=17)
 
        delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs)
 
        assert age(n + delt(**age_args), now=n) == expected
0 comments (0 inline, 0 general)