##// END OF EJS Templates
tests: Add a way to deactivate exception re-raising in tests.
Martin Bornhold -
r947:eb8b2333 default
parent child Browse files
Show More
@@ -20,7 +20,6 b''
20 20
21 21
22 22 import logging
23
24 23 from pyramid import httpexceptions
25 24 from pyramid.httpexceptions import HTTPError, HTTPInternalServerError
26 25 from pyramid.threadlocal import get_current_request
@@ -40,7 +39,7 b' class PylonsErrorHandlingMiddleware(obje'
40 39 def __init__(self, app, error_view, reraise=False):
41 40 self.app = app
42 41 self.error_view = error_view
43 self.reraise = reraise
42 self._reraise = reraise
44 43
45 44 def __call__(self, environ, start_response):
46 45 # We need to use the pyramid request here instead of creating a custom
@@ -63,6 +62,9 b' class PylonsErrorHandlingMiddleware(obje'
63 62 return (self.is_http_error(response) and not
64 63 self.is_vcs_response(response))
65 64
65 def reraise(self):
66 return self._reraise
67
66 68 def handle_request(self, request):
67 69 """
68 70 Calls the underlying WSGI app (typically the old RhodeCode pylons app)
@@ -83,7 +85,7 b' class PylonsErrorHandlingMiddleware(obje'
83 85 except Exception as e:
84 86 log.exception(e)
85 87
86 if self.reraise:
88 if self.reraise():
87 89 raise
88 90
89 91 if isinstance(e, VCSCommunicationError):
@@ -20,8 +20,10 b''
20 20
21 21 import mock
22 22 import pytest
23 import rhodecode
24 23 import rhodecode.lib.vcs.client as client
24 from rhodecode.lib.middleware.error_handling import (
25 PylonsErrorHandlingMiddleware)
26
25 27
26 28 @pytest.mark.usefixtures('autologin_user', 'app')
27 29 def test_vcs_available_returns_summary_page(app, backend):
@@ -35,13 +37,14 b' def test_vcs_available_returns_summary_p'
35 37 def test_vcs_unavailable_returns_vcs_error_page(app, backend):
36 38 url = '/{repo_name}'.format(repo_name=backend.repo.repo_name)
37 39
38 try:
39 rhodecode.disable_error_handler = False
40 with mock.patch.object(client, '_get_proxy_method') as p:
41 p.side_effect = client.exceptions.PyroVCSCommunicationError()
40 # Path the get proxy method to raise an exception instead of making a RPC
41 # call to the vcsserver.
42 with mock.patch.object(client, '_get_proxy_method') as p:
43 p.side_effect = client.exceptions.PyroVCSCommunicationError()
44 # Patch pylons error handling middleware to not re-raise exceptions.
45 with mock.patch.object(PylonsErrorHandlingMiddleware, 'reraise') as r:
46 r.return_value = False
42 47 response = app.get(url, expect_errors=True)
43 finally:
44 rhodecode.disable_error_handler = True
45 48
46 49 assert response.status_code == 502
47 50 assert 'Could not connect to VCS Server' in response.body
General Comments 0
You need to be logged in to leave comments. Login now