# HG changeset patch # User Thomas De Schampheleire # Date 1461693639 -7200 # Node ID be1d20bfd2ddffd837c844d8aa1b428433025ee8 # Parent 91b89797a775ccd68c9710967532d4813779b317 pytest migration: model: convert all tests to TestControllerPytest The model tests were based on BaseTestCase which does not exist currently for pytest-style tests. Nevertheless, there seems to be no advantage of directly subclassing BaseTestCase over subclassing TestControllerPytest. Thus, keep things simple and use TestControllerPytest. diff -r 91b89797a775 -r be1d20bfd2dd kallithea/tests/models/test_changeset_status.py --- a/kallithea/tests/models/test_changeset_status.py Tue Mar 15 17:55:19 2016 +0100 +++ b/kallithea/tests/models/test_changeset_status.py Tue Apr 26 20:00:39 2016 +0200 @@ -7,12 +7,12 @@ def __init__(self, status): self.status = status -class TestChangesetStatusCalculation(BaseTestCase): +class TestChangesetStatusCalculation(TestControllerPytest): - def setUp(self): + def setup_method(self, method): self.m = ChangesetStatusModel() - @parameterized.expand([ + @parametrize('name,expected_result,statuses', [ ('empty list', CS.STATUS_UNDER_REVIEW, []), ('approve', CS.STATUS_APPROVED, [CSM(CS.STATUS_APPROVED)]), ('approve2', CS.STATUS_APPROVED, [CSM(CS.STATUS_APPROVED), CSM(CS.STATUS_APPROVED)]), diff -r 91b89797a775 -r be1d20bfd2dd kallithea/tests/models/test_diff_parsers.py --- a/kallithea/tests/models/test_diff_parsers.py Tue Mar 15 17:55:19 2016 +0100 +++ b/kallithea/tests/models/test_diff_parsers.py Tue Apr 26 20:00:39 2016 +0200 @@ -271,9 +271,9 @@ } -class DiffLibTest(BaseTestCase): +class TestDiffLib(TestControllerPytest): - @parameterized.expand([(x,) for x in DIFF_FIXTURES]) + @parametrize('diff_fixture', DIFF_FIXTURES) def test_diff(self, diff_fixture): diff = fixture.load_resource(diff_fixture, strip=False) vcs = 'hg' diff -r 91b89797a775 -r be1d20bfd2dd kallithea/tests/models/test_notifications.py --- a/kallithea/tests/models/test_notifications.py Tue Mar 15 17:55:19 2016 +0100 +++ b/kallithea/tests/models/test_notifications.py Tue Apr 26 20:00:39 2016 +0200 @@ -7,9 +7,9 @@ from kallithea.model.notification import NotificationModel -class TestNotifications(BaseTestCase): +class TestNotifications(TestControllerPytest): - def __init__(self, methodName='runTest'): + def setup_method(self, method): Session.remove() self.u1 = UserModel().create_or_update(username=u'u1', password=u'qweqwe', @@ -32,9 +32,6 @@ Session().commit() self.u3 = self.u3.user_id - super(TestNotifications, self).__init__(methodName=methodName) - - def setUp(self): remove_all_notifications() self.assertEqual([], Notification.query().all()) self.assertEqual([], UserNotification.query().all()) diff -r 91b89797a775 -r be1d20bfd2dd kallithea/tests/models/test_permissions.py --- a/kallithea/tests/models/test_permissions.py Tue Mar 15 17:55:19 2016 +0100 +++ b/kallithea/tests/models/test_permissions.py Tue Apr 26 20:00:39 2016 +0200 @@ -15,18 +15,16 @@ fixture = Fixture() -class TestPermissions(BaseTestCase): - def __init__(self, methodName='runTest'): - super(TestPermissions, self).__init__(methodName=methodName) +class TestPermissions(TestControllerPytest): @classmethod - def setUpClass(cls): + def setup_class(cls): #recreate default user to get a clean start PermissionModel().create_default_permissions(user=User.DEFAULT_USER, force=True) Session().commit() - def setUp(self): + def setup_method(self, method): self.u1 = UserModel().create_or_update( username=u'u1', password=u'qweqwe', email=u'u1@example.com', firstname=u'u1', lastname=u'u1' @@ -46,7 +44,7 @@ ) Session().commit() - def tearDown(self): + def teardown_method(self, method): if hasattr(self, 'test_repo'): RepoModel().delete(repo=self.test_repo) @@ -716,7 +714,7 @@ PermissionModel().create_default_permissions(user=self.u1) self._test_def_perm_equal(user=self.u1) - @parameterized.expand([ + @parametrize('perm,modify_to', [ ('repository.read', 'repository.none'), ('group.read', 'group.none'), ('usergroup.read', 'usergroup.none'), diff -r 91b89797a775 -r be1d20bfd2dd kallithea/tests/models/test_repo_groups.py --- a/kallithea/tests/models/test_repo_groups.py Tue Mar 15 17:55:19 2016 +0100 +++ b/kallithea/tests/models/test_repo_groups.py Tue Apr 26 20:00:39 2016 +0200 @@ -33,14 +33,14 @@ return r -class TestRepoGroups(BaseTestCase): +class TestRepoGroups(TestControllerPytest): - def setUp(self): + def setup_method(self, method): self.g1 = fixture.create_repo_group(u'test1', skip_if_exists=True) self.g2 = fixture.create_repo_group(u'test2', skip_if_exists=True) self.g3 = fixture.create_repo_group(u'test3', skip_if_exists=True) - def tearDown(self): + def teardown_method(self, method): Session.remove() def __check_path(self, *path): diff -r 91b89797a775 -r be1d20bfd2dd kallithea/tests/models/test_repos.py --- a/kallithea/tests/models/test_repos.py Tue Mar 15 17:55:19 2016 +0100 +++ b/kallithea/tests/models/test_repos.py Tue Apr 26 20:00:39 2016 +0200 @@ -9,12 +9,9 @@ fixture = Fixture() -class TestRepos(BaseTestCase): +class TestRepos(TestControllerPytest): - def setUp(self): - pass - - def tearDown(self): + def teardown_method(self, method): Session.remove() def test_remove_repo(self): @@ -34,6 +31,10 @@ Session().commit() self.assertRaises(AttachedForksError, lambda: RepoModel().delete(repo=repo)) + # cleanup + RepoModel().delete(repo=u'test-repo-fork-1') + RepoModel().delete(repo=u'test-repo-1') + Session().commit() def test_remove_repo_delete_forks(self): repo = fixture.create_repo(name=u'test-repo-1') diff -r 91b89797a775 -r be1d20bfd2dd kallithea/tests/models/test_user_groups.py --- a/kallithea/tests/models/test_user_groups.py Tue Mar 15 17:55:19 2016 +0100 +++ b/kallithea/tests/models/test_user_groups.py Tue Apr 26 20:00:39 2016 +0200 @@ -1,6 +1,6 @@ from kallithea.model.db import User -from kallithea.tests import BaseTestCase, parameterized, TEST_USER_REGULAR_LOGIN +from kallithea.tests import * from kallithea.tests.fixture import Fixture from kallithea.model.user_group import UserGroupModel @@ -10,15 +10,15 @@ fixture = Fixture() -class TestUserGroups(BaseTestCase): +class TestUserGroups(TestControllerPytest): - def tearDown(self): + def teardown_method(self, method): # delete all groups for gr in UserGroupModel.get_all(): fixture.destroy_user_group(gr) Session().commit() - @parameterized.expand([ + @parametrize('pre_existing,regular_should_be,external_should_be,groups,expected', [ ([], [], [], [], []), ([], [u'regular'], [], [], [u'regular']), # no changes of regular ([u'some_other'], [], [], [u'some_other'], []), # not added to regular group diff -r 91b89797a775 -r be1d20bfd2dd kallithea/tests/models/test_users.py --- a/kallithea/tests/models/test_users.py Tue Mar 15 17:55:19 2016 +0100 +++ b/kallithea/tests/models/test_users.py Tue Apr 26 20:00:39 2016 +0200 @@ -11,12 +11,13 @@ fixture = Fixture() -class TestUser(BaseTestCase): - def __init__(self, methodName='runTest'): +class TestUser(TestControllerPytest): + + @classmethod + def setup_class(cls): Session.remove() - super(TestUser, self).__init__(methodName=methodName) - def tearDown(self): + def teardown_method(self, method): Session.remove() def test_create_and_remove(self): @@ -98,18 +99,15 @@ Session().commit() -class TestUsers(BaseTestCase): +class TestUsers(TestControllerPytest): - def __init__(self, methodName='runTest'): - super(TestUsers, self).__init__(methodName=methodName) - - def setUp(self): + def setup_method(self, method): self.u1 = UserModel().create_or_update(username=u'u1', password=u'qweqwe', email=u'u1@example.com', firstname=u'u1', lastname=u'u1') - def tearDown(self): + def teardown_method(self, method): perm = Permission.query().all() for p in perm: UserModel().revoke_perm(self.u1, p)