Changeset - 37d713674f63
[Not reviewed]
default
0 5 0
Thomas De Schampheleire - 10 years ago 2016-02-09 17:51:09
thomas.de.schampheleire@gmail.com
tests: move remove_all_notifications outside of BaseTestCase

In preparation of allowing real pytest-style test cases (instead of
unittest-style ones), some reorganization is needed in the base test
classes, for one because we want a transition period where pytest and
unittest style test cases can live alongside each other, and secondly
because the pytest style test classes cannot have an __init__ method.

The BaseTestCase class will not be reused for the pytest test cases, but
the remove_all_notifications method will. To avoid having to duplicate it,
and since it does not use any resources from the class (self), move the
method out of the BaseTestCase class to top-level, and export it in
kallithea.tests.
5 files changed with 13 insertions and 12 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/__init__.py
Show inline comments
 
@@ -69,7 +69,7 @@ __all__ = [
 
    'TEST_USER_REGULAR2_PASS', 'TEST_USER_REGULAR2_EMAIL', 'TEST_HG_REPO',
 
    'TEST_HG_REPO_CLONE', 'TEST_HG_REPO_PULL', 'TEST_GIT_REPO',
 
    'TEST_GIT_REPO_CLONE', 'TEST_GIT_REPO_PULL', 'HG_REMOTE_REPO',
 
    'GIT_REMOTE_REPO', 'SCM_TESTS',
 
    'GIT_REMOTE_REPO', 'SCM_TESTS', 'remove_all_notifications',
 
]
 

	
 
# Invoke websetup with the current config file
 
@@ -160,6 +160,14 @@ def init_stack(config=None):
 
    h = NullHandler()
 
    logging.getLogger("kallithea").addHandler(h)
 

	
 
def remove_all_notifications():
 
    Notification.query().delete()
 

	
 
    # Because query().delete() does not (by default) trigger cascades.
 
    # http://docs.sqlalchemy.org/en/rel_0_7/orm/collections.html#passive-deletes
 
    UserNotification.query().delete()
 

	
 
    Session().commit()
 

	
 
class BaseTestCase(unittest.TestCase):
 
    def __init__(self, *args, **kwargs):
 
@@ -167,14 +175,7 @@ class BaseTestCase(unittest.TestCase):
 
        init_stack(self.wsgiapp.config)
 
        unittest.TestCase.__init__(self, *args, **kwargs)
 

	
 
    def remove_all_notifications(self):
 
        Notification.query().delete()
 

	
 
        # Because query().delete() does not (by default) trigger cascades.
 
        # http://docs.sqlalchemy.org/en/rel_0_7/orm/collections.html#passive-deletes
 
        UserNotification.query().delete()
 

	
 
        Session().commit()
 

	
 

	
 
class TestController(BaseTestCase):
kallithea/tests/functional/test_admin_notifications.py
Show inline comments
 
@@ -9,7 +9,7 @@ from kallithea.lib import helpers as h
 

	
 
class TestNotificationsController(TestController):
 
    def setUp(self):
 
        self.remove_all_notifications()
 
        remove_all_notifications()
 

	
 
    def test_index(self):
 
        self.log_user()
kallithea/tests/functional/test_changeset_comments.py
Show inline comments
 
@@ -11,7 +11,7 @@ class TestChangeSetCommentsController(Te
 
            Session().delete(x)
 
        Session().commit()
 

	
 
        self.remove_all_notifications()
 
        remove_all_notifications()
 

	
 
    def test_create(self):
 
        self.log_user()
kallithea/tests/functional/test_login.py
Show inline comments
 
@@ -21,7 +21,7 @@ fixture = Fixture()
 

	
 
class TestLoginController(TestController):
 
    def setUp(self):
 
        self.remove_all_notifications()
 
        remove_all_notifications()
 
        self.assertEqual(Notification.query().all(), [])
 

	
 
    def test_index(self):
kallithea/tests/models/test_notifications.py
Show inline comments
 
@@ -35,7 +35,7 @@ class TestNotifications(BaseTestCase):
 
        super(TestNotifications, self).__init__(methodName=methodName)
 

	
 
    def setUp(self):
 
        self.remove_all_notifications()
 
        remove_all_notifications()
 
        self.assertEqual([], Notification.query().all())
 
        self.assertEqual([], UserNotification.query().all())
 

	
0 comments (0 inline, 0 general)