test_hgpatches.py
124 lines
| 3.8 KiB
| text/x-python
|
PythonLexer
r130 | # RhodeCode VCSServer provides access to different vcs backends via network. | |||
r620 | # Copyright (C) 2014-2019 RhodeCode GmbH | |||
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 mock | ||||
import pytest | ||||
from vcsserver import hgcompat, hgpatches | ||||
LARGEFILES_CAPABILITY = 'largefiles=serve' | ||||
def test_patch_largefiles_capabilities_applies_patch( | ||||
patched_capabilities): | ||||
lfproto = hgcompat.largefiles.proto | ||||
hgpatches.patch_largefiles_capabilities() | ||||
r432 | assert lfproto._capabilities.func_name == '_dynamic_capabilities' | |||
r130 | ||||
def test_dynamic_capabilities_uses_original_function_if_not_enabled( | ||||
r432 | stub_repo, stub_proto, stub_ui, stub_extensions, patched_capabilities, | |||
orig_capabilities): | ||||
r130 | dynamic_capabilities = hgpatches._dynamic_capabilities_wrapper( | |||
hgcompat.largefiles.proto, stub_extensions) | ||||
r432 | caps = dynamic_capabilities(orig_capabilities, stub_repo, stub_proto) | |||
r130 | ||||
stub_extensions.assert_called_once_with(stub_ui) | ||||
assert LARGEFILES_CAPABILITY not in caps | ||||
def test_dynamic_capabilities_ignores_updated_capabilities( | ||||
r432 | stub_repo, stub_proto, stub_ui, stub_extensions, patched_capabilities, | |||
orig_capabilities): | ||||
r130 | stub_extensions.return_value = [('largefiles', mock.Mock())] | |||
dynamic_capabilities = hgpatches._dynamic_capabilities_wrapper( | ||||
hgcompat.largefiles.proto, stub_extensions) | ||||
# This happens when the extension is loaded for the first time, important | ||||
# to ensure that an updated function is correctly picked up. | ||||
r432 | hgcompat.largefiles.proto._capabilities = mock.Mock( | |||
r130 | side_effect=Exception('Must not be called')) | |||
r432 | dynamic_capabilities(orig_capabilities, stub_repo, stub_proto) | |||
r130 | ||||
def test_dynamic_capabilities_uses_largefiles_if_enabled( | ||||
r432 | stub_repo, stub_proto, stub_ui, stub_extensions, patched_capabilities, | |||
orig_capabilities): | ||||
r130 | stub_extensions.return_value = [('largefiles', mock.Mock())] | |||
dynamic_capabilities = hgpatches._dynamic_capabilities_wrapper( | ||||
hgcompat.largefiles.proto, stub_extensions) | ||||
r432 | caps = dynamic_capabilities(orig_capabilities, stub_repo, stub_proto) | |||
r130 | ||||
stub_extensions.assert_called_once_with(stub_ui) | ||||
assert LARGEFILES_CAPABILITY in caps | ||||
r320 | def test_hgsubversion_import(): | |||
from hgsubversion import svnrepo | ||||
assert svnrepo | ||||
r130 | @pytest.fixture | |||
def patched_capabilities(request): | ||||
""" | ||||
Patch in `capabilitiesorig` and restore both capability functions. | ||||
""" | ||||
lfproto = hgcompat.largefiles.proto | ||||
r432 | orig_capabilities = lfproto._capabilities | |||
r130 | ||||
@request.addfinalizer | ||||
def restore(): | ||||
r432 | lfproto._capabilities = orig_capabilities | |||
r130 | ||||
@pytest.fixture | ||||
def stub_repo(stub_ui): | ||||
repo = mock.Mock() | ||||
repo.ui = stub_ui | ||||
return repo | ||||
@pytest.fixture | ||||
def stub_proto(stub_ui): | ||||
proto = mock.Mock() | ||||
proto.ui = stub_ui | ||||
return proto | ||||
@pytest.fixture | ||||
r432 | def orig_capabilities(): | |||
from mercurial.wireprotov1server import wireprotocaps | ||||
def _capabilities(repo, proto): | ||||
return wireprotocaps | ||||
return _capabilities | ||||
@pytest.fixture | ||||
r130 | def stub_ui(): | |||
return hgcompat.ui.ui() | ||||
@pytest.fixture | ||||
def stub_extensions(): | ||||
extensions = mock.Mock(return_value=tuple()) | ||||
return extensions | ||||