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