Changeset - be1d20bfd2dd
[Not reviewed]
default
0 8 0
Thomas De Schampheleire - 10 years ago 2016-04-26 20:00:39
thomas.de.schampheleire@gmail.com
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.
8 files changed with 33 insertions and 39 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/models/test_changeset_status.py
Show inline comments
 
@@ -4,18 +4,18 @@ from kallithea.model.db import Changeset
 

	
 
class CSM(object): # ChangesetStatusMock
 

	
 
    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)]),
 
        ('approve_reject', CS.STATUS_REJECTED, [CSM(CS.STATUS_APPROVED), CSM(CS.STATUS_REJECTED)]),
 
        ('approve_underreview', CS.STATUS_UNDER_REVIEW, [CSM(CS.STATUS_APPROVED), CSM(CS.STATUS_UNDER_REVIEW)]),
 
        ('approve_notreviewed', CS.STATUS_UNDER_REVIEW, [CSM(CS.STATUS_APPROVED), CSM(CS.STATUS_NOT_REVIEWED)]),
kallithea/tests/models/test_diff_parsers.py
Show inline comments
 
@@ -268,15 +268,15 @@ DIFF_FIXTURES = {
 
          'binary': False,
 
          'ops': {RENAMED_FILENODE: 'file renamed from oh no to oh yes'}}),
 
    ],
 
}
 

	
 

	
 
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'
 
        if diff_fixture.startswith('git_'):
 
            vcs = 'git'
 
        diff_proc = DiffProcessor(diff, vcs=vcs)
kallithea/tests/models/test_notifications.py
Show inline comments
 
@@ -4,15 +4,15 @@ from kallithea.model.db import User, Not
 
from kallithea.model.user import UserModel
 

	
 
from kallithea.model.meta import Session
 
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',
 
                                        email=u'u1@example.com',
 
                                        firstname=u'u1', lastname=u'u1')
 
        Session().commit()
 
@@ -29,15 +29,12 @@ class TestNotifications(BaseTestCase):
 
                                        password=u'qweqwe',
 
                                        email=u'u3@example.com',
 
                                        firstname=u'u3', lastname=u'u3')
 
        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())
 

	
 
    def test_create_notification(self):
 
        usrs = [self.u1, self.u2]
kallithea/tests/models/test_permissions.py
Show inline comments
 
@@ -12,24 +12,22 @@ from kallithea.lib.auth import AuthUser
 
from kallithea.model.permission import PermissionModel
 

	
 

	
 
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'
 
        )
 
        self.u2 = UserModel().create_or_update(
 
            username=u'u2', password=u'qweqwe',
 
@@ -43,13 +41,13 @@ class TestPermissions(BaseTestCase):
 
        self.a1 = UserModel().create_or_update(
 
            username=u'a1', password=u'qweqwe',
 
            email=u'a1@example.com', firstname=u'a1', lastname=u'a1', admin=True
 
        )
 
        Session().commit()
 

	
 
    def tearDown(self):
 
    def teardown_method(self, method):
 
        if hasattr(self, 'test_repo'):
 
            RepoModel().delete(repo=self.test_repo)
 

	
 
        UserModel().delete(self.u1)
 
        UserModel().delete(self.u2)
 
        UserModel().delete(self.u3)
 
@@ -713,13 +711,13 @@ class TestPermissions(BaseTestCase):
 
        self._test_def_perm_equal(user=self.u1, change_factor=-1)
 

	
 
        #create missing one !
 
        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'),
 
        ('hg.create.repository', 'hg.create.none'),
 
        ('hg.fork.repository', 'hg.fork.none'),
 
        ('hg.register.manual_activate', 'hg.register.auto_activate',)
kallithea/tests/models/test_repo_groups.py
Show inline comments
 
@@ -30,20 +30,20 @@ def _update_repo(name, **kwargs):
 
    if not 'perms_updates' in kwargs:
 
        form_data['perms_updates'] = []
 
    r = RepoModel().update(name, **form_data)
 
    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):
 
        """
 
        Checks the path for existance !
 
        """
kallithea/tests/models/test_repos.py
Show inline comments
 
@@ -6,18 +6,15 @@ from kallithea.model.repo import RepoMod
 
from kallithea.model.db import Repository
 
from kallithea.lib.exceptions import AttachedForksError
 

	
 
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):
 
        repo = fixture.create_repo(name=u'test-repo-1')
 
        Session().commit()
 

	
 
@@ -31,12 +28,16 @@ class TestRepos(BaseTestCase):
 
        Session().commit()
 

	
 
        fixture.create_fork(repo.repo_name, u'test-repo-fork-1')
 
        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')
 
        Session().commit()
 

	
 
        fork = fixture.create_fork(repo.repo_name, u'test-repo-fork-1')
kallithea/tests/models/test_user_groups.py
Show inline comments
 
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
 
from kallithea.model.meta import Session
 

	
 

	
 
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
 
        ([], [u'regular'], [u'container'], [u'container'], [u'regular', u'container']),
 
        ([], [u'regular'], [], [u'container', u'container2'], [u'regular', u'container', u'container2']),
 
        ([], [u'regular'], [u'other'], [], [u'regular']),  # remove not used
kallithea/tests/models/test_users.py
Show inline comments
 
@@ -8,18 +8,19 @@ from kallithea.model.meta import Session
 
from kallithea.model.user_group import UserGroupModel
 
from kallithea.tests.fixture import Fixture
 

	
 
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):
 
        usr = UserModel().create_or_update(username=u'test_user',
 
                                           password=u'qweqwe',
 
                                           email=u'u232@example.com',
 
@@ -95,24 +96,21 @@ class TestUser(BaseTestCase):
 

	
 

	
 
        UserModel().delete(usr.user_id)
 
        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)
 

	
 
        UserModel().delete(self.u1)
 
        Session().commit()
0 comments (0 inline, 0 general)