tests: Make test work with either http or pyro4 protocol.

This commit is contained in:
Martin Bornhold 2016-10-10 14:32:46 +02:00
parent add98db605
commit 2b09ada931

View file

@ -20,9 +20,6 @@
import mock
import pytest
import rhodecode.lib.vcs.client as client
from rhodecode.lib.middleware.error_handling import (
PylonsErrorHandlingMiddleware)
@pytest.mark.usefixtures('autologin_user', 'app')
@ -34,13 +31,26 @@ def test_vcs_available_returns_summary_page(app, backend):
@pytest.mark.usefixtures('autologin_user', 'app')
def test_vcs_unavailable_returns_vcs_error_page(app, backend):
def test_vcs_unavailable_returns_vcs_error_page(app, backend, app_settings):
import rhodecode
from rhodecode.lib.vcs.exceptions import VCSCommunicationError
# Depending on the used VCSServer protocol we have to patch a different
# RemoteRepo class to raise an exception. For the test it doesn't matter
# if http or pyro4 is used, it just requires the exception to be raised.
vcs_protocol = app_settings['vcs.server.protocol']
if vcs_protocol == 'http':
from rhodecode.lib.vcs.client_http import RemoteRepo
elif vcs_protocol == 'pyro4':
from rhodecode.lib.vcs.client import RemoteRepo
else:
pytest.fail('Unknown VCS server protocol: "{}"'.format(vcs_protocol))
url = '/{repo_name}'.format(repo_name=backend.repo.repo_name)
# Path the get proxy method to raise an exception instead of making a RPC
# call to the vcsserver.
with mock.patch.object(client, '_get_proxy_method') as p:
p.side_effect = client.exceptions.PyroVCSCommunicationError()
# Patch remote repo to raise an exception instead of making a RPC.
with mock.patch.object(RemoteRepo, '__getattr__') as remote_mock:
remote_mock.side_effect = VCSCommunicationError()
# Patch pylons error handling middleware to not re-raise exceptions.
with mock.patch.object(PylonsErrorHandlingMiddleware, 'reraise') as r:
r.return_value = False