##// END OF EJS Templates
tests: fix disable_vcs tests
dan -
r192:f246f4bc default
parent child Browse files
Show More
@@ -70,7 +70,7 b' class DisableVCSPagesWrapper(object):'
70 self.handler = handler
70 self.handler = handler
71
71
72 def __call__(self, context, request):
72 def __call__(self, context, request):
73 if not self._check_vcs_requirement(request.environ['PATH_INFO']):
73 if not self._check_vcs_requirement(request.path):
74 raise VCSServerUnavailable('VCS Server is not available')
74 raise VCSServerUnavailable('VCS Server is not available')
75
75
76 return self.handler(context, request)
76 return self.handler(context, request)
@@ -19,36 +19,35 b''
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import pytest
21 import pytest
22 from rhodecode.lib.middleware.disable_vcs import DisableVCSPagesWrapper
22 from pyramid.response import Response
23 from pyramid.testing import DummyRequest
24 from rhodecode.lib.middleware.disable_vcs import (
25 DisableVCSPagesWrapper, VCSServerUnavailable)
23
26
24
27
25 @pytest.mark.parametrize('url, expected_url', [
28 @pytest.mark.parametrize('url, should_raise', [
26 ('/', '/'),
29 ('/', False),
27 ('/_admin/settings', '/_admin/settings'),
30 ('/_admin/settings', False),
28 ('/_admin/i_am_fine', '/_admin/i_am_fine'),
31 ('/_admin/i_am_fine', False),
29 ('/_admin/settings/mappings', '/error/vcs_unavailable'),
32 ('/_admin/settings/mappings', True),
30 ('/_admin/my_account/repos', '/error/vcs_unavailable'),
33 ('/_admin/my_account/repos', True),
31 ('/_admin/create_repository', '/error/vcs_unavailable'),
34 ('/_admin/create_repository', True),
32 ('/_admin/gists/1', '/error/vcs_unavailable'),
35 ('/_admin/gists/1', True),
33 ('/_admin/notifications/1', '/error/vcs_unavailable'),
36 ('/_admin/notifications/1', True),
34 ])
37 ])
35 def test_vcs_disabled(url, expected_url):
38 def test_vcs_disabled(url, should_raise):
36 app = DisableVCSPagesWrapper(app=SimpleApp())
39 wrapped_view = DisableVCSPagesWrapper(pyramid_view)
37 assert expected_url == app(get_environ(url), None)
40 request = DummyRequest(path=url)
38
39
41
40 def get_environ(url):
42 if should_raise:
41 """Construct a minimum WSGI environ based on the URL."""
43 with pytest.raises(VCSServerUnavailable):
42 environ = {
44 response = wrapped_view(None, request)
43 'PATH_INFO': url,
45 else:
44 }
46 response = wrapped_view(None, request)
45 return environ
47 assert response.status_int == 200
46
47
48
48 class SimpleApp(object):
49 def pyramid_view(context, request):
49 """
50 """
50 A mock app to be used in the wrapper that returns the modified URL
51 A mock pyramid view to be used in the wrapper
51 from the middleware
52 """
52 """
53 def __call__(self, environ, start_response):
53 return Response('success')
54 return environ['PATH_INFO']
General Comments 0
You need to be logged in to leave comments. Login now