Mercurial > kallithea
changeset 5707:37d713674f63
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.
author | Thomas De Schampheleire <thomas.de.schampheleire@gmail.com> |
---|---|
date | Tue, 09 Feb 2016 17:51:09 +0100 |
parents | ff1bd1b60736 |
children | 2cc8d876d1c8 |
files | kallithea/tests/__init__.py kallithea/tests/functional/test_admin_notifications.py kallithea/tests/functional/test_changeset_comments.py kallithea/tests/functional/test_login.py kallithea/tests/models/test_notifications.py |
diffstat | 5 files changed, 13 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/tests/__init__.py Tue Feb 09 17:54:22 2016 +0100 +++ b/kallithea/tests/__init__.py Tue Feb 09 17:51:09 2016 +0100 @@ -69,7 +69,7 @@ '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 @@ 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 @@ 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):
--- a/kallithea/tests/functional/test_admin_notifications.py Tue Feb 09 17:54:22 2016 +0100 +++ b/kallithea/tests/functional/test_admin_notifications.py Tue Feb 09 17:51:09 2016 +0100 @@ -9,7 +9,7 @@ class TestNotificationsController(TestController): def setUp(self): - self.remove_all_notifications() + remove_all_notifications() def test_index(self): self.log_user()
--- a/kallithea/tests/functional/test_changeset_comments.py Tue Feb 09 17:54:22 2016 +0100 +++ b/kallithea/tests/functional/test_changeset_comments.py Tue Feb 09 17:51:09 2016 +0100 @@ -11,7 +11,7 @@ Session().delete(x) Session().commit() - self.remove_all_notifications() + remove_all_notifications() def test_create(self): self.log_user()
--- a/kallithea/tests/functional/test_login.py Tue Feb 09 17:54:22 2016 +0100 +++ b/kallithea/tests/functional/test_login.py Tue Feb 09 17:51:09 2016 +0100 @@ -21,7 +21,7 @@ class TestLoginController(TestController): def setUp(self): - self.remove_all_notifications() + remove_all_notifications() self.assertEqual(Notification.query().all(), []) def test_index(self):
--- a/kallithea/tests/models/test_notifications.py Tue Feb 09 17:54:22 2016 +0100 +++ b/kallithea/tests/models/test_notifications.py Tue Feb 09 17:51:09 2016 +0100 @@ -35,7 +35,7 @@ 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())