##// END OF EJS Templates
deps: bumped to latest versions
deps: bumped to latest versions

File last commit:

r1080:fe9c3296 python3
r1083:c93897de python3
Show More
test_git.py
162 lines | 6.1 KiB | text/x-python | PythonLexer
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 # RhodeCode VCSServer provides access to different vcs backends via network.
code: update copyrights to 2020
r850 # Copyright (C) 2014-2020 RhodeCode GmbH
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 #
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# 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 General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import inspect
import pytest
import dulwich.errors
from mock import Mock, patch
core: move git/svn/hg into submodule
r1043 from vcsserver.remote import git
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
SAMPLE_REFS = {
'HEAD': 'fd627b9e0dd80b47be81af07c4a98518244ed2f7',
'refs/tags/v0.1.9': '341d28f0eec5ddf0b6b77871e13c2bbd6bec685c',
'refs/tags/v0.1.8': '74ebce002c088b8a5ecf40073db09375515ecd68',
'refs/tags/v0.1.1': 'e6ea6d16e2f26250124a1f4b4fe37a912f9d86a0',
'refs/tags/v0.1.3': '5a3a8fb005554692b16e21dee62bf02667d8dc3e',
}
@pytest.fixture
def git_remote():
"""
A GitRemote instance with a mock factory.
"""
factory = Mock()
remote = git.GitRemote(factory)
return remote
def test_discover_git_version(git_remote):
version = git_remote.discover_git_version()
assert version
class TestGitFetch(object):
python3: code change for py3 support...
r1048 def setup_method(self):
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 self.mock_repo = Mock()
factory = Mock()
factory.repo = Mock(return_value=self.mock_repo)
self.remote_git = git.GitRemote(factory)
def test_fetches_all_when_no_commit_ids_specified(self):
def side_effect(determine_wants, *args, **kwargs):
determine_wants(SAMPLE_REFS)
with patch('dulwich.client.LocalGitClient.fetch') as mock_fetch:
mock_fetch.side_effect = side_effect
caches: new cache implementation for remote functions
r739 self.remote_git.pull(wire={}, url='/tmp/', apply_refs=False)
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 determine_wants = self.mock_repo.object_store.determine_wants_all
determine_wants.assert_called_once_with(SAMPLE_REFS)
def test_fetches_specified_commits(self):
selected_refs = {
core: multiple changes for python3 found during test runs of rhodecode-ce release
r1080 'refs/tags/v0.1.8': b'74ebce002c088b8a5ecf40073db09375515ecd68',
'refs/tags/v0.1.3': b'5a3a8fb005554692b16e21dee62bf02667d8dc3e',
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 }
def side_effect(determine_wants, *args, **kwargs):
result = determine_wants(SAMPLE_REFS)
assert sorted(result) == sorted(selected_refs.values())
return result
with patch('dulwich.client.LocalGitClient.fetch') as mock_fetch:
mock_fetch.side_effect = side_effect
git: rename fetch into pull because this is what it actually does.
r550 self.remote_git.pull(
caches: new cache implementation for remote functions
r739 wire={}, url='/tmp/', apply_refs=False,
python3: another 2to3 pass
r1054 refs=list(selected_refs.keys()))
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 determine_wants = self.mock_repo.object_store.determine_wants_all
assert determine_wants.call_count == 0
def test_get_remote_refs(self):
factory = Mock()
remote_git = git.GitRemote(factory)
url = 'http://example.com/test/test.git'
sample_refs = {
'refs/tags/v0.1.8': '74ebce002c088b8a5ecf40073db09375515ecd68',
'refs/tags/v0.1.3': '5a3a8fb005554692b16e21dee62bf02667d8dc3e',
}
python3: code change for py3 support...
r1048 with patch('vcsserver.remote.git.Repo', create=False) as mock_repo:
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 mock_repo().get_refs.return_value = sample_refs
caches: new cache implementation for remote functions
r739 remote_refs = remote_git.get_remote_refs(wire={}, url=url)
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 mock_repo().get_refs.assert_called_once_with()
assert remote_refs == sample_refs
class TestReraiseSafeExceptions(object):
git: switched most git operations to libgit2
r725
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 def test_method_decorated_with_reraise_safe_exceptions(self):
factory = Mock()
git_remote = git.GitRemote(factory)
def fake_function():
return None
decorator = git.reraise_safe_exceptions(fake_function)
methods = inspect.getmembers(git_remote, predicate=inspect.ismethod)
for method_name, method in methods:
caches: small naming refactor to fix tests.
r964 if not method_name.startswith('_') and method_name not in ['vcsserver_invalidate_cache']:
py3: 2to3 run
r1044 assert method.__func__.__code__ == decorator.__code__
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
@pytest.mark.parametrize('side_effect, expected_type', [
(dulwich.errors.ChecksumMismatch('0000000', 'deadbeef'), 'lookup'),
(dulwich.errors.NotCommitError('deadbeef'), 'lookup'),
(dulwich.errors.MissingCommitError('deadbeef'), 'lookup'),
(dulwich.errors.ObjectMissing('deadbeef'), 'lookup'),
(dulwich.errors.HangupException(), 'error'),
(dulwich.errors.UnexpectedCommandError('test-cmd'), 'error'),
])
def test_safe_exceptions_reraised(self, side_effect, expected_type):
@git.reraise_safe_exceptions
def fake_method():
raise side_effect
with pytest.raises(Exception) as exc_info:
fake_method()
assert type(exc_info.value) == Exception
assert exc_info.value._vcs_kind == expected_type
class TestDulwichRepoWrapper(object):
def test_calls_close_on_delete(self):
isdir_patcher = patch('dulwich.repo.os.path.isdir', return_value=True)
python3: code change for py3 support...
r1048 with patch.object(git.Repo, 'close') as close_mock:
with isdir_patcher:
repo = git.Repo('/tmp/abcde')
assert repo is not None
repo.__del__()
# can't use del repo as in python3 this isn't always calling .__del__()
close_mock.assert_called_once_with()
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
class TestGitFactory(object):
def test_create_repo_returns_dulwich_wrapper(self):
caches: replaced beaker with dogpile cache.
r483
with patch('vcsserver.lib.rc_cache.region_meta.dogpile_cache_regions') as mock:
mock.side_effect = {'repo_objects': ''}
factory = git.GitFactory()
wire = {
'path': '/tmp/abcde'
}
isdir_patcher = patch('dulwich.repo.os.path.isdir', return_value=True)
with isdir_patcher:
result = factory._create_repo(wire, True)
assert isinstance(result, git.Repo)