tests: Adapt tests to recent changes.
This commit is contained in:
parent
c46ad9f215
commit
ebaab4bbd2
7 changed files with 42 additions and 94 deletions
|
|
@ -25,68 +25,6 @@ import pytest
|
|||
from rhodecode.config import environment
|
||||
|
||||
|
||||
class TestUseDirectHookCalls(object):
|
||||
@pytest.mark.parametrize('config', [
|
||||
{
|
||||
'vcs.hooks.direct_calls': 'true',
|
||||
'base_path': 'fake_base_path'
|
||||
}
|
||||
])
|
||||
def test_returns_true_when_conditions_are_met(self, config):
|
||||
result = environment._use_direct_hook_calls(config)
|
||||
assert result is True
|
||||
|
||||
@pytest.mark.parametrize('config', [
|
||||
{
|
||||
'vcs.hooks.direct_calls': 'false',
|
||||
'base_path': 'fake_base_path'
|
||||
},
|
||||
{
|
||||
'base_path': 'fake_base_path'
|
||||
}
|
||||
])
|
||||
def test_returns_false_when_conditions_are_not_met(self, config):
|
||||
result = environment._use_direct_hook_calls(config)
|
||||
assert result is False
|
||||
|
||||
|
||||
class TestGetVcsHooksProtocol(object):
|
||||
def test_returns_pyro4_by_default(self):
|
||||
config = {}
|
||||
result = environment._get_vcs_hooks_protocol(config)
|
||||
assert result == 'pyro4'
|
||||
|
||||
@pytest.mark.parametrize('protocol', ['PYRO4', 'HTTP', 'Pyro4', 'Http'])
|
||||
def test_returns_lower_case_value(self, protocol):
|
||||
config = {
|
||||
'vcs.hooks.protocol': protocol
|
||||
}
|
||||
result = environment._get_vcs_hooks_protocol(config)
|
||||
assert result == protocol.lower()
|
||||
|
||||
|
||||
class TestLoadEnvironment(object):
|
||||
def test_calls_use_direct_hook_calls(self, _external_calls_patcher):
|
||||
global_conf = {
|
||||
'here': '',
|
||||
'vcs.connection_timeout': '0',
|
||||
'vcs.server.enable': 'false'
|
||||
}
|
||||
app_conf = {
|
||||
'cache_dir': '/tmp/',
|
||||
'__file__': '/tmp/abcde.ini'
|
||||
}
|
||||
direct_calls_patcher = mock.patch.object(
|
||||
environment, '_use_direct_hook_calls', return_value=True)
|
||||
protocol_patcher = mock.patch.object(
|
||||
environment, '_get_vcs_hooks_protocol', return_value='http')
|
||||
with direct_calls_patcher as direct_calls_mock, \
|
||||
protocol_patcher as protocol_mock:
|
||||
environment.load_environment(global_conf, app_conf)
|
||||
direct_calls_mock.call_count == 1
|
||||
protocol_mock.call_count == 1
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def _external_calls_patcher(request):
|
||||
# TODO: mikhail: This is a temporary solution. Ideally load_environment
|
||||
|
|
|
|||
0
rhodecode/tests/config/test_sanitize_settings.py
Normal file
0
rhodecode/tests/config/test_sanitize_settings.py
Normal file
|
|
@ -58,9 +58,10 @@ def get_environ(url):
|
|||
# Edge case: not a smart protocol url
|
||||
('/foo/bar', 'pull'),
|
||||
])
|
||||
def test_get_action(url, expected_action):
|
||||
def test_get_action(url, expected_action, pylonsapp):
|
||||
app = simplegit.SimpleGit(application=None,
|
||||
config={'auth_ret_code': '', 'base_path': ''})
|
||||
config={'auth_ret_code': '', 'base_path': ''},
|
||||
registry=None)
|
||||
assert expected_action == app._get_action(get_environ(url))
|
||||
|
||||
|
||||
|
|
@ -74,15 +75,17 @@ def test_get_action(url, expected_action):
|
|||
('/foo/bar/git-upload-pack', 'foo/bar'),
|
||||
('/foo/bar/git-receive-pack', 'foo/bar'),
|
||||
])
|
||||
def test_get_repository_name(url, expected_repo_name):
|
||||
def test_get_repository_name(url, expected_repo_name, pylonsapp):
|
||||
app = simplegit.SimpleGit(application=None,
|
||||
config={'auth_ret_code': '', 'base_path': ''})
|
||||
config={'auth_ret_code': '', 'base_path': ''},
|
||||
registry=None)
|
||||
assert expected_repo_name == app._get_repository_name(get_environ(url))
|
||||
|
||||
|
||||
def test_get_config():
|
||||
def test_get_config(pylonsapp):
|
||||
app = simplegit.SimpleGit(application=None,
|
||||
config={'auth_ret_code': '', 'base_path': ''})
|
||||
config={'auth_ret_code': '', 'base_path': ''},
|
||||
registry=None)
|
||||
extras = {'foo': 'FOO', 'bar': 'BAR'}
|
||||
|
||||
# We copy the extras as the method below will change the contents.
|
||||
|
|
@ -95,13 +98,13 @@ def test_get_config():
|
|||
assert config == expected_config
|
||||
|
||||
|
||||
def test_create_wsgi_app_uses_scm_app_from_simplevcs():
|
||||
def test_create_wsgi_app_uses_scm_app_from_simplevcs(pylonsapp):
|
||||
config = {
|
||||
'auth_ret_code': '',
|
||||
'base_path': '',
|
||||
'vcs.scm_app_implementation':
|
||||
'rhodecode.tests.lib.middleware.mock_scm_app',
|
||||
}
|
||||
app = simplegit.SimpleGit(application=None, config=config)
|
||||
app = simplegit.SimpleGit(application=None, config=config, registry=None)
|
||||
wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {})
|
||||
assert wsgi_app is mock_scm_app.mock_git_wsgi
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@ def get_environ(url):
|
|||
])
|
||||
def test_get_action(url, expected_action):
|
||||
app = simplehg.SimpleHg(application=None,
|
||||
config={'auth_ret_code': '', 'base_path': ''})
|
||||
config={'auth_ret_code': '', 'base_path': ''},
|
||||
registry=None)
|
||||
assert expected_action == app._get_action(get_environ(url))
|
||||
|
||||
|
||||
|
|
@ -72,13 +73,15 @@ def test_get_action(url, expected_action):
|
|||
])
|
||||
def test_get_repository_name(url, expected_repo_name):
|
||||
app = simplehg.SimpleHg(application=None,
|
||||
config={'auth_ret_code': '', 'base_path': ''})
|
||||
config={'auth_ret_code': '', 'base_path': ''},
|
||||
registry=None)
|
||||
assert expected_repo_name == app._get_repository_name(get_environ(url))
|
||||
|
||||
|
||||
def test_get_config():
|
||||
app = simplehg.SimpleHg(application=None,
|
||||
config={'auth_ret_code': '', 'base_path': ''})
|
||||
config={'auth_ret_code': '', 'base_path': ''},
|
||||
registry=None)
|
||||
extras = {'foo': 'FOO', 'bar': 'BAR'}
|
||||
|
||||
mock_config = Config()
|
||||
|
|
@ -108,6 +111,6 @@ def test_create_wsgi_app_uses_scm_app_from_simplevcs():
|
|||
'vcs.scm_app_implementation':
|
||||
'rhodecode.tests.lib.middleware.mock_scm_app',
|
||||
}
|
||||
app = simplehg.SimpleHg(application=None, config=config)
|
||||
app = simplehg.SimpleHg(application=None, config=config, registry=None)
|
||||
wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {})
|
||||
assert wsgi_app is mock_scm_app.mock_hg_wsgi
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ class TestSimpleSvn(object):
|
|||
self.app = SimpleSvn(
|
||||
application='None',
|
||||
config={'auth_ret_code': '',
|
||||
'base_path': rhodecode.CONFIG['base_path']})
|
||||
'base_path': rhodecode.CONFIG['base_path']},
|
||||
registry=None)
|
||||
|
||||
def test_get_config(self):
|
||||
extras = {'foo': 'FOO', 'bar': 'BAR'}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,7 @@ import pytest
|
|||
import webtest.app
|
||||
|
||||
from rhodecode.lib.caching_query import FromCache
|
||||
from rhodecode.lib.hooks_daemon import (
|
||||
Pyro4HooksCallbackDaemon, DummyHooksCallbackDaemon,
|
||||
HttpHooksCallbackDaemon)
|
||||
from rhodecode.lib.hooks_daemon import DummyHooksCallbackDaemon
|
||||
from rhodecode.lib.middleware import simplevcs
|
||||
from rhodecode.lib.middleware.https_fixup import HttpsFixup
|
||||
from rhodecode.lib.middleware.utils import scm_app
|
||||
|
|
@ -66,7 +64,7 @@ def vcscontroller(pylonsapp, config_stub):
|
|||
config_stub.include('rhodecode.authentication')
|
||||
|
||||
set_anonymous_access(True)
|
||||
controller = StubVCSController(pylonsapp, pylonsapp.config)
|
||||
controller = StubVCSController(pylonsapp, pylonsapp.config, None)
|
||||
app = HttpsFixup(controller, pylonsapp.config)
|
||||
app = webtest.app.TestApp(app)
|
||||
|
||||
|
|
@ -131,7 +129,7 @@ class StubFailVCSController(simplevcs.SimpleVCS):
|
|||
|
||||
@pytest.fixture(scope='module')
|
||||
def fail_controller(pylonsapp):
|
||||
controller = StubFailVCSController(pylonsapp, pylonsapp.config)
|
||||
controller = StubFailVCSController(pylonsapp, pylonsapp.config, None)
|
||||
controller = HttpsFixup(controller, pylonsapp.config)
|
||||
controller = webtest.app.TestApp(controller)
|
||||
return controller
|
||||
|
|
@ -148,7 +146,7 @@ def test_provides_traceback_for_appenlight(fail_controller):
|
|||
|
||||
|
||||
def test_provides_utils_scm_app_as_scm_app_by_default(pylonsapp):
|
||||
controller = StubVCSController(pylonsapp, pylonsapp.config)
|
||||
controller = StubVCSController(pylonsapp, pylonsapp.config, None)
|
||||
assert controller.scm_app is scm_app
|
||||
|
||||
|
||||
|
|
@ -156,7 +154,7 @@ def test_allows_to_override_scm_app_via_config(pylonsapp):
|
|||
config = pylonsapp.config.copy()
|
||||
config['vcs.scm_app_implementation'] = (
|
||||
'rhodecode.tests.lib.middleware.mock_scm_app')
|
||||
controller = StubVCSController(pylonsapp, config)
|
||||
controller = StubVCSController(pylonsapp, config, None)
|
||||
assert controller.scm_app is mock_scm_app
|
||||
|
||||
|
||||
|
|
@ -231,7 +229,12 @@ class TestGenerateVcsResponse:
|
|||
assert prepare_mock.call_count == 1
|
||||
|
||||
def call_controller_with_response_body(self, response_body):
|
||||
controller = StubVCSController(None, {'base_path': 'fake_base_path'})
|
||||
settings = {
|
||||
'base_path': 'fake_base_path',
|
||||
'vcs.hooks.protocol': 'http',
|
||||
'vcs.hooks.direct_calls': False,
|
||||
}
|
||||
controller = StubVCSController(None, settings, None)
|
||||
controller._invalidate_cache = mock.Mock()
|
||||
controller.stub_response_body = response_body
|
||||
self.start_response = mock.Mock()
|
||||
|
|
@ -281,16 +284,12 @@ class TestInitializeGenerator:
|
|||
|
||||
|
||||
class TestPrepareHooksDaemon(object):
|
||||
def test_calls_imported_prepare_callback_daemon(self):
|
||||
config = {
|
||||
'base_path': 'fake_base_path',
|
||||
'vcs.hooks.direct_calls': False,
|
||||
'vcs.hooks.protocol': 'http'
|
||||
}
|
||||
def test_calls_imported_prepare_callback_daemon(self, pylonsapp):
|
||||
settings = pylonsapp.application.config
|
||||
expected_extras = {'extra1': 'value1'}
|
||||
daemon = DummyHooksCallbackDaemon()
|
||||
|
||||
controller = StubVCSController(None, config)
|
||||
controller = StubVCSController(None, settings, None)
|
||||
prepare_patcher = mock.patch.object(
|
||||
simplevcs, 'prepare_callback_daemon',
|
||||
return_value=(daemon, expected_extras))
|
||||
|
|
@ -298,7 +297,9 @@ class TestPrepareHooksDaemon(object):
|
|||
callback_daemon, extras = controller._prepare_callback_daemon(
|
||||
expected_extras.copy())
|
||||
prepare_mock.assert_called_once_with(
|
||||
expected_extras, protocol='http', use_direct_calls=False)
|
||||
expected_extras,
|
||||
protocol=settings['vcs.hooks.protocol'],
|
||||
use_direct_calls=settings['vcs.hooks.direct_calls'])
|
||||
|
||||
assert callback_daemon == daemon
|
||||
assert extras == extras
|
||||
|
|
|
|||
|
|
@ -102,8 +102,9 @@ class TestVCSMiddleware(object):
|
|||
}
|
||||
app = Mock()
|
||||
config = Mock()
|
||||
registry = Mock()
|
||||
middleware = vcs.VCSMiddleware(
|
||||
app, config=config, appenlight_client=None)
|
||||
app, config=config, appenlight_client=None, registry=registry)
|
||||
snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn')
|
||||
settings_patch = patch.dict(
|
||||
rhodecode.CONFIG,
|
||||
|
|
@ -112,7 +113,7 @@ class TestVCSMiddleware(object):
|
|||
svn_mock.return_value = None
|
||||
middleware._get_handler_app(environ)
|
||||
|
||||
svn_mock.assert_called_once_with(app, config)
|
||||
svn_mock.assert_called_once_with(app, config, registry)
|
||||
|
||||
def test_get_handler_app_retuns_no_svn_app_when_proxy_disabled(self):
|
||||
environ = {
|
||||
|
|
@ -121,8 +122,9 @@ class TestVCSMiddleware(object):
|
|||
}
|
||||
app = Mock()
|
||||
config = Mock()
|
||||
registry = Mock()
|
||||
middleware = vcs.VCSMiddleware(
|
||||
app, config=config, appenlight_client=None)
|
||||
app, config=config, appenlight_client=None, registry=registry)
|
||||
snv_patch = patch('rhodecode.lib.middleware.vcs.SimpleSvn')
|
||||
settings_patch = patch.dict(
|
||||
rhodecode.CONFIG,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue