##// END OF EJS Templates
tests: Adapt tests to recent changes.
Martin Bornhold -
r592:36736ad1 default
parent child Browse files
Show More
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
@@ -25,68 +25,6 b' import pytest'
25 from rhodecode.config import environment
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 @pytest.fixture
28 @pytest.fixture
91 def _external_calls_patcher(request):
29 def _external_calls_patcher(request):
92 # TODO: mikhail: This is a temporary solution. Ideally load_environment
30 # TODO: mikhail: This is a temporary solution. Ideally load_environment
@@ -58,9 +58,10 b' def get_environ(url):'
58 # Edge case: not a smart protocol url
58 # Edge case: not a smart protocol url
59 ('/foo/bar', 'pull'),
59 ('/foo/bar', 'pull'),
60 ])
60 ])
61 def test_get_action(url, expected_action):
61 def test_get_action(url, expected_action, pylonsapp):
62 app = simplegit.SimpleGit(application=None,
62 app = simplegit.SimpleGit(application=None,
63 config={'auth_ret_code': '', 'base_path': ''})
63 config={'auth_ret_code': '', 'base_path': ''},
64 registry=None)
64 assert expected_action == app._get_action(get_environ(url))
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 ('/foo/bar/git-upload-pack', 'foo/bar'),
75 ('/foo/bar/git-upload-pack', 'foo/bar'),
75 ('/foo/bar/git-receive-pack', 'foo/bar'),
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 app = simplegit.SimpleGit(application=None,
79 app = simplegit.SimpleGit(application=None,
79 config={'auth_ret_code': '', 'base_path': ''})
80 config={'auth_ret_code': '', 'base_path': ''},
81 registry=None)
80 assert expected_repo_name == app._get_repository_name(get_environ(url))
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 app = simplegit.SimpleGit(application=None,
86 app = simplegit.SimpleGit(application=None,
85 config={'auth_ret_code': '', 'base_path': ''})
87 config={'auth_ret_code': '', 'base_path': ''},
88 registry=None)
86 extras = {'foo': 'FOO', 'bar': 'BAR'}
89 extras = {'foo': 'FOO', 'bar': 'BAR'}
87
90
88 # We copy the extras as the method below will change the contents.
91 # We copy the extras as the method below will change the contents.
@@ -95,13 +98,13 b' def test_get_config():'
95 assert config == expected_config
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 config = {
102 config = {
100 'auth_ret_code': '',
103 'auth_ret_code': '',
101 'base_path': '',
104 'base_path': '',
102 'vcs.scm_app_implementation':
105 'vcs.scm_app_implementation':
103 'rhodecode.tests.lib.middleware.mock_scm_app',
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 wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {})
109 wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {})
107 assert wsgi_app is mock_scm_app.mock_git_wsgi
110 assert wsgi_app is mock_scm_app.mock_git_wsgi
@@ -55,7 +55,8 b' def get_environ(url):'
55 ])
55 ])
56 def test_get_action(url, expected_action):
56 def test_get_action(url, expected_action):
57 app = simplehg.SimpleHg(application=None,
57 app = simplehg.SimpleHg(application=None,
58 config={'auth_ret_code': '', 'base_path': ''})
58 config={'auth_ret_code': '', 'base_path': ''},
59 registry=None)
59 assert expected_action == app._get_action(get_environ(url))
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 def test_get_repository_name(url, expected_repo_name):
74 def test_get_repository_name(url, expected_repo_name):
74 app = simplehg.SimpleHg(application=None,
75 app = simplehg.SimpleHg(application=None,
75 config={'auth_ret_code': '', 'base_path': ''})
76 config={'auth_ret_code': '', 'base_path': ''},
77 registry=None)
76 assert expected_repo_name == app._get_repository_name(get_environ(url))
78 assert expected_repo_name == app._get_repository_name(get_environ(url))
77
79
78
80
79 def test_get_config():
81 def test_get_config():
80 app = simplehg.SimpleHg(application=None,
82 app = simplehg.SimpleHg(application=None,
81 config={'auth_ret_code': '', 'base_path': ''})
83 config={'auth_ret_code': '', 'base_path': ''},
84 registry=None)
82 extras = {'foo': 'FOO', 'bar': 'BAR'}
85 extras = {'foo': 'FOO', 'bar': 'BAR'}
83
86
84 mock_config = Config()
87 mock_config = Config()
@@ -108,6 +111,6 b' def test_create_wsgi_app_uses_scm_app_fr'
108 'vcs.scm_app_implementation':
111 'vcs.scm_app_implementation':
109 'rhodecode.tests.lib.middleware.mock_scm_app',
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 wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {})
115 wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {})
113 assert wsgi_app is mock_scm_app.mock_hg_wsgi
116 assert wsgi_app is mock_scm_app.mock_hg_wsgi
@@ -33,7 +33,8 b' class TestSimpleSvn(object):'
33 self.app = SimpleSvn(
33 self.app = SimpleSvn(
34 application='None',
34 application='None',
35 config={'auth_ret_code': '',
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 def test_get_config(self):
39 def test_get_config(self):
39 extras = {'foo': 'FOO', 'bar': 'BAR'}
40 extras = {'foo': 'FOO', 'bar': 'BAR'}
@@ -25,9 +25,7 b' import pytest'
25 import webtest.app
25 import webtest.app
26
26
27 from rhodecode.lib.caching_query import FromCache
27 from rhodecode.lib.caching_query import FromCache
28 from rhodecode.lib.hooks_daemon import (
28 from rhodecode.lib.hooks_daemon import DummyHooksCallbackDaemon
29 Pyro4HooksCallbackDaemon, DummyHooksCallbackDaemon,
30 HttpHooksCallbackDaemon)
31 from rhodecode.lib.middleware import simplevcs
29 from rhodecode.lib.middleware import simplevcs
32 from rhodecode.lib.middleware.https_fixup import HttpsFixup
30 from rhodecode.lib.middleware.https_fixup import HttpsFixup
33 from rhodecode.lib.middleware.utils import scm_app
31 from rhodecode.lib.middleware.utils import scm_app
@@ -66,7 +64,7 b' def vcscontroller(pylonsapp, config_stub'
66 config_stub.include('rhodecode.authentication')
64 config_stub.include('rhodecode.authentication')
67
65
68 set_anonymous_access(True)
66 set_anonymous_access(True)
69 controller = StubVCSController(pylonsapp, pylonsapp.config)
67 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
70 app = HttpsFixup(controller, pylonsapp.config)
68 app = HttpsFixup(controller, pylonsapp.config)
71 app = webtest.app.TestApp(app)
69 app = webtest.app.TestApp(app)
72
70
@@ -131,7 +129,7 b' class StubFailVCSController(simplevcs.Si'
131
129
132 @pytest.fixture(scope='module')
130 @pytest.fixture(scope='module')
133 def fail_controller(pylonsapp):
131 def fail_controller(pylonsapp):
134 controller = StubFailVCSController(pylonsapp, pylonsapp.config)
132 controller = StubFailVCSController(pylonsapp, pylonsapp.config, None)
135 controller = HttpsFixup(controller, pylonsapp.config)
133 controller = HttpsFixup(controller, pylonsapp.config)
136 controller = webtest.app.TestApp(controller)
134 controller = webtest.app.TestApp(controller)
137 return controller
135 return controller
@@ -148,7 +146,7 b' def test_provides_traceback_for_appenlig'
148
146
149
147
150 def test_provides_utils_scm_app_as_scm_app_by_default(pylonsapp):
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 assert controller.scm_app is scm_app
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 config = pylonsapp.config.copy()
154 config = pylonsapp.config.copy()
157 config['vcs.scm_app_implementation'] = (
155 config['vcs.scm_app_implementation'] = (
158 'rhodecode.tests.lib.middleware.mock_scm_app')
156 'rhodecode.tests.lib.middleware.mock_scm_app')
159 controller = StubVCSController(pylonsapp, config)
157 controller = StubVCSController(pylonsapp, config, None)
160 assert controller.scm_app is mock_scm_app
158 assert controller.scm_app is mock_scm_app
161
159
162
160
@@ -231,7 +229,12 b' class TestGenerateVcsResponse:'
231 assert prepare_mock.call_count == 1
229 assert prepare_mock.call_count == 1
232
230
233 def call_controller_with_response_body(self, response_body):
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 controller._invalidate_cache = mock.Mock()
238 controller._invalidate_cache = mock.Mock()
236 controller.stub_response_body = response_body
239 controller.stub_response_body = response_body
237 self.start_response = mock.Mock()
240 self.start_response = mock.Mock()
@@ -281,16 +284,12 b' class TestInitializeGenerator:'
281
284
282
285
283 class TestPrepareHooksDaemon(object):
286 class TestPrepareHooksDaemon(object):
284 def test_calls_imported_prepare_callback_daemon(self):
287 def test_calls_imported_prepare_callback_daemon(self, pylonsapp):
285 config = {
288 settings = pylonsapp.application.config
286 'base_path': 'fake_base_path',
287 'vcs.hooks.direct_calls': False,
288 'vcs.hooks.protocol': 'http'
289 }
290 expected_extras = {'extra1': 'value1'}
289 expected_extras = {'extra1': 'value1'}
291 daemon = DummyHooksCallbackDaemon()
290 daemon = DummyHooksCallbackDaemon()
292
291
293 controller = StubVCSController(None, config)
292 controller = StubVCSController(None, settings, None)
294 prepare_patcher = mock.patch.object(
293 prepare_patcher = mock.patch.object(
295 simplevcs, 'prepare_callback_daemon',
294 simplevcs, 'prepare_callback_daemon',
296 return_value=(daemon, expected_extras))
295 return_value=(daemon, expected_extras))
@@ -298,7 +297,9 b' class TestPrepareHooksDaemon(object):'
298 callback_daemon, extras = controller._prepare_callback_daemon(
297 callback_daemon, extras = controller._prepare_callback_daemon(
299 expected_extras.copy())
298 expected_extras.copy())
300 prepare_mock.assert_called_once_with(
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 assert callback_daemon == daemon
304 assert callback_daemon == daemon
304 assert extras == extras
305 assert extras == extras
@@ -102,8 +102,9 b' class TestVCSMiddleware(object):'
102 }
102 }
103 app = Mock()
103 app = Mock()
104 config = Mock()
104 config = Mock()
105 registry = Mock()
105 middleware = vcs.VCSMiddleware(
106 middleware = vcs.VCSMiddleware(
106 app, config=config, appenlight_client=None)
107 app, config=config, appenlight_client=None, registry=registry)
107 snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn')
108 snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn')
108 settings_patch = patch.dict(
109 settings_patch = patch.dict(
109 rhodecode.CONFIG,
110 rhodecode.CONFIG,
@@ -112,7 +113,7 b' class TestVCSMiddleware(object):'
112 svn_mock.return_value = None
113 svn_mock.return_value = None
113 middleware._get_handler_app(environ)
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 def test_get_handler_app_retuns_no_svn_app_when_proxy_disabled(self):
118 def test_get_handler_app_retuns_no_svn_app_when_proxy_disabled(self):
118 environ = {
119 environ = {
@@ -121,8 +122,9 b' class TestVCSMiddleware(object):'
121 }
122 }
122 app = Mock()
123 app = Mock()
123 config = Mock()
124 config = Mock()
125 registry = Mock()
124 middleware = vcs.VCSMiddleware(
126 middleware = vcs.VCSMiddleware(
125 app, config=config, appenlight_client=None)
127 app, config=config, appenlight_client=None, registry=registry)
126 snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn')
128 snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn')
127 settings_patch = patch.dict(
129 settings_patch = patch.dict(
128 rhodecode.CONFIG,
130 rhodecode.CONFIG,
General Comments 0
You need to be logged in to leave comments. Login now