Changeset - 4077ea3ff4f2
[Not reviewed]
default
0 1 0
Thomas De Schampheleire - 8 years ago 2018-03-16 21:32:01
thomas.de_schampheleire@nokia.com
tests: vcs: split off repo creation helpers

test_changesets.py needs to create a repository, and is currently
duplicating some of the base setup code.

Instead, split out the setup_class method to allow reuse.

Note that the repo_path variable previously registered to 'self' is not
actually used by anyone, and moreover is not actually necessary as the path
can be obtained via the repo object too. Therefore, just make it a local
variable.
1 file changed with 12 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/vcs/base.py
Show inline comments
 
@@ -11,26 +11,24 @@ from kallithea.lib.vcs.nodes import File
 

	
 
from kallithea.tests.vcs.conf import get_new_dir
 

	
 

	
 
class _BackendTestMixin(object):
 
    """
 
    This is a backend independent test case class which should be created
 
    with ``type`` method.
 

	
 
    It is required to set following attributes at subclass:
 

	
 
    - ``backend_alias``: alias of used backend (see ``vcs.BACKENDS``)
 
    - ``repo_path``: path to the repository which would be created for set of
 
      tests
 
    - ``recreate_repo_per_test``: If set to ``False``, repo would NOT be created
 
      before every single test. Defaults to ``True``.
 
    """
 
    recreate_repo_per_test = True
 

	
 
    @classmethod
 
    def get_backend(cls):
 
        return vcs.get_backend(cls.backend_alias)
 

	
 
    @classmethod
 
    def _get_commits(cls):
 
        commits = [
 
@@ -54,32 +52,41 @@ class _BackendTestMixin(object):
 
                'changed': [
 
                    FileNode('foobar', 'Foobar I'),
 
                ],
 
                'removed': [],
 
            },
 
        ]
 
        return commits
 

	
 
    @classmethod
 
    def setup_class(cls):
 
        Backend = cls.get_backend()
 
        cls.backend_class = Backend
 
        cls.repo_path = get_new_dir(str(time.time()))
 
        cls.repo = Backend(cls.repo_path, create=True)
 
        cls.setup_repo(Backend)
 

	
 
    @classmethod
 
    def setup_empty_repo(cls, backend):
 
        repo_path = get_new_dir(str(time.time()))
 
        repo = backend(repo_path, create=True)
 
        return repo
 

	
 
    @classmethod
 
    def setup_repo(cls, backend):
 
        cls.repo = cls.setup_empty_repo(backend)
 
        cls.imc = cls.repo.in_memory_changeset
 
        cls.default_branch = cls.repo.DEFAULT_BRANCH_NAME
 

	
 
        for commit in cls._get_commits():
 
            for node in commit.get('added', []):
 
                cls.imc.add(FileNode(node.path, content=node.content))
 
            for node in commit.get('changed', []):
 
                cls.imc.change(FileNode(node.path, content=node.content))
 
            for node in commit.get('removed', []):
 
                cls.imc.remove(FileNode(node.path))
 

	
 
            cls.tip = cls.imc.commit(message=unicode(commit['message']),
 
                                     author=unicode(commit['author']),
 
                                     date=commit['date'])
 

	
 
    def setup_method(self, method):
 
        if getattr(self, 'recreate_repo_per_test', False):
 
            self.__class__.setup_class()
 
            self.setup_repo(self.backend_class)
0 comments (0 inline, 0 general)