##// END OF EJS Templates
fix(tests): added ability for test to get an up-to-date version mercurial.
fix(tests): added ability for test to get an up-to-date version mercurial.

File last commit:

r5608:6d33e504 default
r5653:11c8ab5c tip default
Show More
test_vcs.py
123 lines | 3.7 KiB | text/x-python | PythonLexer
core: updated copyright to 2024
r5608 # Copyright (C) 2010-2024 RhodeCode GmbH
project: added all source files and assets
r1 #
# 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.
"""
tests: fixed test suite for celery adoption
r5607
tests: improved vcs tests
r2613 import os
import tempfile
import shutil
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 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
pylons: remove pylons as dependency...
r2351 pytestmark = pytest.mark.usefixtures("baseapp")
project: added all source files and assets
r1
tests: improved vcs tests
r2613 def test_get_backend(backend):
repo_class = get_backend(backend.alias)
assert repo_class == backend.repo.scm_instance().__class__
project: added all source files and assets
r1
tests: improved vcs tests
r2613 def test_alias_detect(backend):
alias = backend.alias
path = backend.repo.scm_instance().path
project: added all source files and assets
r1
tests: improved vcs tests
r2613 new_backend = get_backend(alias)
repo = new_backend(path)
project: added all source files and assets
r1
tests: improved vcs tests
r2613 assert alias == repo.alias
project: added all source files and assets
r1
def test_wrong_alias():
tests: fixed test suite for celery adoption
r5607 alias = "wrong_alias"
project: added all source files and assets
r1 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
tests: improved vcs tests
r2613 def test_get_vcs_instance_by_path_empty_dir(request, tmpdir):
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 """
Test that ``get_vcs_instance_by_path`` returns None if a path is passed
to an empty directory.
"""
tests: improved vcs tests
r2613 empty_dir = str(tmpdir)
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
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.
"""
tests: fixed test suite for celery adoption
r5607 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)
tests: fixed test suite for celery adoption
r5607
Martin Bornhold
tests: Adapt tests to use the new get_vcs_instance function instead of removed get_repo.
r487 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
tests: improved vcs tests
r2613
tests: fixed test suite for celery adoption
r5607 @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, tmpdir, vcs_repo):
tests: improved vcs tests
r2613 """
Test that the arguments passed to ``get_vcs_instance_by_path`` are
forwarded to the vcs backend class.
"""
backend = mock.MagicMock()
get_backend_mock.return_value = backend
tests: fixed test suite for celery adoption
r5607 args = ["these-are-test-args", 0, True, None]
tests: improved vcs tests
r2613 repo = vcs_repo.path
get_vcs_instance(repo, *args)
backend.assert_called_with(*args, repo_path=repo)
tests: fixed test suite for celery adoption
r5607 @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, vcs_repo):
tests: improved vcs tests
r2613 """
Test that the keyword arguments passed to ``get_vcs_instance_by_path`` are
forwarded to the vcs backend class.
"""
backend = mock.MagicMock()
get_backend_mock.return_value = backend
tests: fixed test suite for celery adoption
r5607 kwargs = {"foo": "these-are-test-args", "bar": 0, "baz": True, "foobar": None}
tests: improved vcs tests
r2613 repo = vcs_repo.path
get_vcs_instance(repo, **kwargs)
backend.assert_called_with(repo_path=repo, **kwargs)