Show More
|
1 | NO CONTENT: new file 100644 |
@@ -25,68 +25,6 b' import pytest' | |||
|
25 | 25 | from rhodecode.config import environment |
|
26 | 26 | |
|
27 | 27 | |
|
28 | class TestUseDirectHookCalls(object): | |
|
29 | @pytest.mark.parametrize('config', [ | |
|
30 | { | |
|
31 | 'vcs.hooks.direct_calls': 'true', | |
|
32 | 'base_path': 'fake_base_path' | |
|
33 | } | |
|
34 | ]) | |
|
35 | def test_returns_true_when_conditions_are_met(self, config): | |
|
36 | result = environment._use_direct_hook_calls(config) | |
|
37 | assert result is True | |
|
38 | ||
|
39 | @pytest.mark.parametrize('config', [ | |
|
40 | { | |
|
41 | 'vcs.hooks.direct_calls': 'false', | |
|
42 | 'base_path': 'fake_base_path' | |
|
43 | }, | |
|
44 | { | |
|
45 | 'base_path': 'fake_base_path' | |
|
46 | } | |
|
47 | ]) | |
|
48 | def test_returns_false_when_conditions_are_not_met(self, config): | |
|
49 | result = environment._use_direct_hook_calls(config) | |
|
50 | assert result is False | |
|
51 | ||
|
52 | ||
|
53 | class TestGetVcsHooksProtocol(object): | |
|
54 | def test_returns_pyro4_by_default(self): | |
|
55 | config = {} | |
|
56 | result = environment._get_vcs_hooks_protocol(config) | |
|
57 | assert result == 'pyro4' | |
|
58 | ||
|
59 | @pytest.mark.parametrize('protocol', ['PYRO4', 'HTTP', 'Pyro4', 'Http']) | |
|
60 | def test_returns_lower_case_value(self, protocol): | |
|
61 | config = { | |
|
62 | 'vcs.hooks.protocol': protocol | |
|
63 | } | |
|
64 | result = environment._get_vcs_hooks_protocol(config) | |
|
65 | assert result == protocol.lower() | |
|
66 | ||
|
67 | ||
|
68 | class TestLoadEnvironment(object): | |
|
69 | def test_calls_use_direct_hook_calls(self, _external_calls_patcher): | |
|
70 | global_conf = { | |
|
71 | 'here': '', | |
|
72 | 'vcs.connection_timeout': '0', | |
|
73 | 'vcs.server.enable': 'false' | |
|
74 | } | |
|
75 | app_conf = { | |
|
76 | 'cache_dir': '/tmp/', | |
|
77 | '__file__': '/tmp/abcde.ini' | |
|
78 | } | |
|
79 | direct_calls_patcher = mock.patch.object( | |
|
80 | environment, '_use_direct_hook_calls', return_value=True) | |
|
81 | protocol_patcher = mock.patch.object( | |
|
82 | environment, '_get_vcs_hooks_protocol', return_value='http') | |
|
83 | with direct_calls_patcher as direct_calls_mock, \ | |
|
84 | protocol_patcher as protocol_mock: | |
|
85 | environment.load_environment(global_conf, app_conf) | |
|
86 | direct_calls_mock.call_count == 1 | |
|
87 | protocol_mock.call_count == 1 | |
|
88 | ||
|
89 | ||
|
90 | 28 | @pytest.fixture |
|
91 | 29 | def _external_calls_patcher(request): |
|
92 | 30 | # TODO: mikhail: This is a temporary solution. Ideally load_environment |
@@ -58,9 +58,10 b' def get_environ(url):' | |||
|
58 | 58 | # Edge case: not a smart protocol url |
|
59 | 59 | ('/foo/bar', 'pull'), |
|
60 | 60 | ]) |
|
61 | def test_get_action(url, expected_action): | |
|
61 | def test_get_action(url, expected_action, pylonsapp): | |
|
62 | 62 | app = simplegit.SimpleGit(application=None, |
|
63 |
config={'auth_ret_code': '', 'base_path': ''} |
|
|
63 | config={'auth_ret_code': '', 'base_path': ''}, | |
|
64 | registry=None) | |
|
64 | 65 | assert expected_action == app._get_action(get_environ(url)) |
|
65 | 66 | |
|
66 | 67 | |
@@ -74,15 +75,17 b' def test_get_action(url, expected_action' | |||
|
74 | 75 | ('/foo/bar/git-upload-pack', 'foo/bar'), |
|
75 | 76 | ('/foo/bar/git-receive-pack', 'foo/bar'), |
|
76 | 77 | ]) |
|
77 | def test_get_repository_name(url, expected_repo_name): | |
|
78 | def test_get_repository_name(url, expected_repo_name, pylonsapp): | |
|
78 | 79 | app = simplegit.SimpleGit(application=None, |
|
79 |
config={'auth_ret_code': '', 'base_path': ''} |
|
|
80 | config={'auth_ret_code': '', 'base_path': ''}, | |
|
81 | registry=None) | |
|
80 | 82 | assert expected_repo_name == app._get_repository_name(get_environ(url)) |
|
81 | 83 | |
|
82 | 84 | |
|
83 | def test_get_config(): | |
|
85 | def test_get_config(pylonsapp): | |
|
84 | 86 | app = simplegit.SimpleGit(application=None, |
|
85 |
config={'auth_ret_code': '', 'base_path': ''} |
|
|
87 | config={'auth_ret_code': '', 'base_path': ''}, | |
|
88 | registry=None) | |
|
86 | 89 | extras = {'foo': 'FOO', 'bar': 'BAR'} |
|
87 | 90 | |
|
88 | 91 | # We copy the extras as the method below will change the contents. |
@@ -95,13 +98,13 b' def test_get_config():' | |||
|
95 | 98 | assert config == expected_config |
|
96 | 99 | |
|
97 | 100 | |
|
98 | def test_create_wsgi_app_uses_scm_app_from_simplevcs(): | |
|
101 | def test_create_wsgi_app_uses_scm_app_from_simplevcs(pylonsapp): | |
|
99 | 102 | config = { |
|
100 | 103 | 'auth_ret_code': '', |
|
101 | 104 | 'base_path': '', |
|
102 | 105 | 'vcs.scm_app_implementation': |
|
103 | 106 | 'rhodecode.tests.lib.middleware.mock_scm_app', |
|
104 | 107 | } |
|
105 | app = simplegit.SimpleGit(application=None, config=config) | |
|
108 | app = simplegit.SimpleGit(application=None, config=config, registry=None) | |
|
106 | 109 | wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {}) |
|
107 | 110 | assert wsgi_app is mock_scm_app.mock_git_wsgi |
@@ -55,7 +55,8 b' def get_environ(url):' | |||
|
55 | 55 | ]) |
|
56 | 56 | def test_get_action(url, expected_action): |
|
57 | 57 | app = simplehg.SimpleHg(application=None, |
|
58 |
config={'auth_ret_code': '', 'base_path': ''} |
|
|
58 | config={'auth_ret_code': '', 'base_path': ''}, | |
|
59 | registry=None) | |
|
59 | 60 | assert expected_action == app._get_action(get_environ(url)) |
|
60 | 61 | |
|
61 | 62 | |
@@ -72,13 +73,15 b' def test_get_action(url, expected_action' | |||
|
72 | 73 | ]) |
|
73 | 74 | def test_get_repository_name(url, expected_repo_name): |
|
74 | 75 | app = simplehg.SimpleHg(application=None, |
|
75 |
config={'auth_ret_code': '', 'base_path': ''} |
|
|
76 | config={'auth_ret_code': '', 'base_path': ''}, | |
|
77 | registry=None) | |
|
76 | 78 | assert expected_repo_name == app._get_repository_name(get_environ(url)) |
|
77 | 79 | |
|
78 | 80 | |
|
79 | 81 | def test_get_config(): |
|
80 | 82 | app = simplehg.SimpleHg(application=None, |
|
81 |
config={'auth_ret_code': '', 'base_path': ''} |
|
|
83 | config={'auth_ret_code': '', 'base_path': ''}, | |
|
84 | registry=None) | |
|
82 | 85 | extras = {'foo': 'FOO', 'bar': 'BAR'} |
|
83 | 86 | |
|
84 | 87 | mock_config = Config() |
@@ -108,6 +111,6 b' def test_create_wsgi_app_uses_scm_app_fr' | |||
|
108 | 111 | 'vcs.scm_app_implementation': |
|
109 | 112 | 'rhodecode.tests.lib.middleware.mock_scm_app', |
|
110 | 113 | } |
|
111 | app = simplehg.SimpleHg(application=None, config=config) | |
|
114 | app = simplehg.SimpleHg(application=None, config=config, registry=None) | |
|
112 | 115 | wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {}) |
|
113 | 116 | assert wsgi_app is mock_scm_app.mock_hg_wsgi |
@@ -33,7 +33,8 b' class TestSimpleSvn(object):' | |||
|
33 | 33 | self.app = SimpleSvn( |
|
34 | 34 | application='None', |
|
35 | 35 | config={'auth_ret_code': '', |
|
36 |
'base_path': rhodecode.CONFIG['base_path']} |
|
|
36 | 'base_path': rhodecode.CONFIG['base_path']}, | |
|
37 | registry=None) | |
|
37 | 38 | |
|
38 | 39 | def test_get_config(self): |
|
39 | 40 | extras = {'foo': 'FOO', 'bar': 'BAR'} |
@@ -25,9 +25,7 b' import pytest' | |||
|
25 | 25 | import webtest.app |
|
26 | 26 | |
|
27 | 27 | from rhodecode.lib.caching_query import FromCache |
|
28 |
from rhodecode.lib.hooks_daemon import |
|
|
29 | Pyro4HooksCallbackDaemon, DummyHooksCallbackDaemon, | |
|
30 | HttpHooksCallbackDaemon) | |
|
28 | from rhodecode.lib.hooks_daemon import DummyHooksCallbackDaemon | |
|
31 | 29 | from rhodecode.lib.middleware import simplevcs |
|
32 | 30 | from rhodecode.lib.middleware.https_fixup import HttpsFixup |
|
33 | 31 | from rhodecode.lib.middleware.utils import scm_app |
@@ -66,7 +64,7 b' def vcscontroller(pylonsapp, config_stub' | |||
|
66 | 64 | config_stub.include('rhodecode.authentication') |
|
67 | 65 | |
|
68 | 66 | set_anonymous_access(True) |
|
69 | controller = StubVCSController(pylonsapp, pylonsapp.config) | |
|
67 | controller = StubVCSController(pylonsapp, pylonsapp.config, None) | |
|
70 | 68 | app = HttpsFixup(controller, pylonsapp.config) |
|
71 | 69 | app = webtest.app.TestApp(app) |
|
72 | 70 | |
@@ -131,7 +129,7 b' class StubFailVCSController(simplevcs.Si' | |||
|
131 | 129 | |
|
132 | 130 | @pytest.fixture(scope='module') |
|
133 | 131 | def fail_controller(pylonsapp): |
|
134 | controller = StubFailVCSController(pylonsapp, pylonsapp.config) | |
|
132 | controller = StubFailVCSController(pylonsapp, pylonsapp.config, None) | |
|
135 | 133 | controller = HttpsFixup(controller, pylonsapp.config) |
|
136 | 134 | controller = webtest.app.TestApp(controller) |
|
137 | 135 | return controller |
@@ -148,7 +146,7 b' def test_provides_traceback_for_appenlig' | |||
|
148 | 146 | |
|
149 | 147 | |
|
150 | 148 | def test_provides_utils_scm_app_as_scm_app_by_default(pylonsapp): |
|
151 | controller = StubVCSController(pylonsapp, pylonsapp.config) | |
|
149 | controller = StubVCSController(pylonsapp, pylonsapp.config, None) | |
|
152 | 150 | assert controller.scm_app is scm_app |
|
153 | 151 | |
|
154 | 152 | |
@@ -156,7 +154,7 b' def test_allows_to_override_scm_app_via_' | |||
|
156 | 154 | config = pylonsapp.config.copy() |
|
157 | 155 | config['vcs.scm_app_implementation'] = ( |
|
158 | 156 | 'rhodecode.tests.lib.middleware.mock_scm_app') |
|
159 | controller = StubVCSController(pylonsapp, config) | |
|
157 | controller = StubVCSController(pylonsapp, config, None) | |
|
160 | 158 | assert controller.scm_app is mock_scm_app |
|
161 | 159 | |
|
162 | 160 | |
@@ -231,7 +229,12 b' class TestGenerateVcsResponse:' | |||
|
231 | 229 | assert prepare_mock.call_count == 1 |
|
232 | 230 | |
|
233 | 231 | def call_controller_with_response_body(self, response_body): |
|
234 | controller = StubVCSController(None, {'base_path': 'fake_base_path'}) | |
|
232 | settings = { | |
|
233 | 'base_path': 'fake_base_path', | |
|
234 | 'vcs.hooks.protocol': 'http', | |
|
235 | 'vcs.hooks.direct_calls': False, | |
|
236 | } | |
|
237 | controller = StubVCSController(None, settings, None) | |
|
235 | 238 | controller._invalidate_cache = mock.Mock() |
|
236 | 239 | controller.stub_response_body = response_body |
|
237 | 240 | self.start_response = mock.Mock() |
@@ -281,16 +284,12 b' class TestInitializeGenerator:' | |||
|
281 | 284 | |
|
282 | 285 | |
|
283 | 286 | class TestPrepareHooksDaemon(object): |
|
284 | def test_calls_imported_prepare_callback_daemon(self): | |
|
285 | config = { | |
|
286 | 'base_path': 'fake_base_path', | |
|
287 | 'vcs.hooks.direct_calls': False, | |
|
288 | 'vcs.hooks.protocol': 'http' | |
|
289 | } | |
|
287 | def test_calls_imported_prepare_callback_daemon(self, pylonsapp): | |
|
288 | settings = pylonsapp.application.config | |
|
290 | 289 | expected_extras = {'extra1': 'value1'} |
|
291 | 290 | daemon = DummyHooksCallbackDaemon() |
|
292 | 291 | |
|
293 |
controller = StubVCSController(None, |
|
|
292 | controller = StubVCSController(None, settings, None) | |
|
294 | 293 | prepare_patcher = mock.patch.object( |
|
295 | 294 | simplevcs, 'prepare_callback_daemon', |
|
296 | 295 | return_value=(daemon, expected_extras)) |
@@ -298,7 +297,9 b' class TestPrepareHooksDaemon(object):' | |||
|
298 | 297 | callback_daemon, extras = controller._prepare_callback_daemon( |
|
299 | 298 | expected_extras.copy()) |
|
300 | 299 | prepare_mock.assert_called_once_with( |
|
301 | expected_extras, protocol='http', use_direct_calls=False) | |
|
300 | expected_extras, | |
|
301 | protocol=settings['vcs.hooks.protocol'], | |
|
302 | use_direct_calls=settings['vcs.hooks.direct_calls']) | |
|
302 | 303 | |
|
303 | 304 | assert callback_daemon == daemon |
|
304 | 305 | assert extras == extras |
@@ -102,8 +102,9 b' class TestVCSMiddleware(object):' | |||
|
102 | 102 | } |
|
103 | 103 | app = Mock() |
|
104 | 104 | config = Mock() |
|
105 | registry = Mock() | |
|
105 | 106 | middleware = vcs.VCSMiddleware( |
|
106 | app, config=config, appenlight_client=None) | |
|
107 | app, config=config, appenlight_client=None, registry=registry) | |
|
107 | 108 | snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn') |
|
108 | 109 | settings_patch = patch.dict( |
|
109 | 110 | rhodecode.CONFIG, |
@@ -112,7 +113,7 b' class TestVCSMiddleware(object):' | |||
|
112 | 113 | svn_mock.return_value = None |
|
113 | 114 | middleware._get_handler_app(environ) |
|
114 | 115 | |
|
115 | svn_mock.assert_called_once_with(app, config) | |
|
116 | svn_mock.assert_called_once_with(app, config, registry) | |
|
116 | 117 | |
|
117 | 118 | def test_get_handler_app_retuns_no_svn_app_when_proxy_disabled(self): |
|
118 | 119 | environ = { |
@@ -121,8 +122,9 b' class TestVCSMiddleware(object):' | |||
|
121 | 122 | } |
|
122 | 123 | app = Mock() |
|
123 | 124 | config = Mock() |
|
125 | registry = Mock() | |
|
124 | 126 | middleware = vcs.VCSMiddleware( |
|
125 | app, config=config, appenlight_client=None) | |
|
127 | app, config=config, appenlight_client=None, registry=registry) | |
|
126 | 128 | snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn') |
|
127 | 129 | settings_patch = patch.dict( |
|
128 | 130 | rhodecode.CONFIG, |
General Comments 0
You need to be logged in to leave comments.
Login now