##// END OF EJS Templates
tests: Add a ``db`` fixture that initializes the database....
tests: Add a ``db`` fixture that initializes the database. This is quite useful if tests only need the database and not the whole app. Then only this fixture is needed instead of the full blown pylonsapp/app fixtures.

File last commit:

r487:f0165f76 default
r914:cf699af2 default
Show More
test_vcs.py
144 lines | 4.0 KiB | text/x-python | PythonLexer
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
# Copyright (C) 2010-2016 RhodeCode GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
"""
Tests for main module's methods.
"""
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 import mock
project: added all source files and assets
r1 import os
import shutil
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 import tempfile
project: added all source files and assets
r1
import pytest
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 from rhodecode.lib.vcs import VCSError, get_backend, get_vcs_instance
project: added all source files and assets
r1 from rhodecode.lib.vcs.backends.hg import MercurialRepository
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 from rhodecode.tests import TEST_HG_REPO, TEST_GIT_REPO
project: added all source files and assets
r1
pytestmark = pytest.mark.usefixtures("pylonsapp")
def test_get_backend():
hg = get_backend('hg')
assert hg == MercurialRepository
def test_alias_detect_hg():
alias = 'hg'
path = TEST_HG_REPO
backend = get_backend(alias)
repo = backend(path)
assert 'hg' == repo.alias
def test_alias_detect_git():
alias = 'git'
path = TEST_GIT_REPO
backend = get_backend(alias)
repo = backend(path)
assert 'git' == repo.alias
def test_wrong_alias():
alias = 'wrong_alias'
with pytest.raises(VCSError):
get_backend(alias)
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 def test_get_vcs_instance_by_path(vcs_repo):
repo = get_vcs_instance(vcs_repo.path)
project: added all source files and assets
r1
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 assert repo.__class__ == vcs_repo.__class__
assert repo.path == vcs_repo.path
assert repo.alias == vcs_repo.alias
assert repo.name == vcs_repo.name
project: added all source files and assets
r1
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 @mock.patch('rhodecode.lib.vcs.backends.get_scm')
@mock.patch('rhodecode.lib.vcs.backends.get_backend')
def test_get_vcs_instance_by_path_args_passed(
get_backend_mock, get_scm_mock):
"""
Test that the arguments passed to ``get_vcs_instance_by_path`` are
forewarded to the vcs backend class.
"""
backend = mock.MagicMock()
get_backend_mock.return_value = backend
args = ['these-are-test-args', 0, True, None]
get_vcs_instance(TEST_HG_REPO, *args)
project: added all source files and assets
r1
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 backend.assert_called_with(*args, repo_path=TEST_HG_REPO)
project: added all source files and assets
r1
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 @mock.patch('rhodecode.lib.vcs.backends.get_scm')
@mock.patch('rhodecode.lib.vcs.backends.get_backend')
def test_get_vcs_instance_by_path_kwargs_passed(
get_backend_mock, get_scm_mock):
"""
Test that the keyword arguments passed to ``get_vcs_instance_by_path`` are
forewarded to the vcs backend class.
"""
backend = mock.MagicMock()
get_backend_mock.return_value = backend
kwargs = {
'foo': 'these-are-test-args',
'bar': 0,
'baz': True,
'foobar': None
}
get_vcs_instance(TEST_HG_REPO, **kwargs)
project: added all source files and assets
r1
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 backend.assert_called_with(repo_path=TEST_HG_REPO, **kwargs)
project: added all source files and assets
r1
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 def test_get_vcs_instance_by_path_err(request):
"""
Test that ``get_vcs_instance_by_path`` returns None if a path is passed
to an empty directory.
"""
empty_dir = tempfile.mkdtemp(prefix='pytest-empty-dir-')
project: added all source files and assets
r1
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 def fin():
shutil.rmtree(empty_dir)
request.addfinalizer(fin)
repo = get_vcs_instance(empty_dir)
assert repo is None
project: added all source files and assets
r1
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 def test_get_vcs_instance_by_path_multiple_repos(request):
"""
Test that ``get_vcs_instance_by_path`` returns None if a path is passed
to a directory with multiple repositories.
"""
empty_dir = tempfile.mkdtemp(prefix='pytest-empty-dir-')
os.mkdir(os.path.join(empty_dir, '.git'))
os.mkdir(os.path.join(empty_dir, '.hg'))
project: added all source files and assets
r1
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 def fin():
shutil.rmtree(empty_dir)
request.addfinalizer(fin)
project: added all source files and assets
r1
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 repo = get_vcs_instance(empty_dir)
assert repo is None