# HG changeset patch # User RhodeCode Admin # Date 2024-10-25 08:34:22 # Node ID 750c46dc7fabe90d869d0dc7f2612633f2bd07e5 # Parent 8dd6cbfd0a6481c951ad61d39cb07647bc6027d2 fix(tests): fixed tests for PR celery hooks deamon diff --git a/rhodecode/lib/hook_daemon/base.py b/rhodecode/lib/hook_daemon/base.py --- a/rhodecode/lib/hook_daemon/base.py +++ b/rhodecode/lib/hook_daemon/base.py @@ -20,7 +20,7 @@ import os import time import logging -from rhodecode.lib.config_utils import get_config +from rhodecode.lib.config_utils import get_app_config_lightweight from rhodecode.lib.svn_txn_utils import get_txn_id_from_store @@ -68,7 +68,12 @@ def prepare_callback_daemon(extras, prot txn_id=txn_id, host=host, port=port) case 'celery': from rhodecode.lib.hook_daemon.celery_hooks_deamon import CeleryHooksCallbackDaemon - callback_daemon = CeleryHooksCallbackDaemon(get_config(extras['config'])) + + config = get_app_config_lightweight(extras['config']) + task_queue = config.get('celery.broker_url') + task_backend = config.get('celery.result_backend') + + callback_daemon = CeleryHooksCallbackDaemon(task_queue, task_backend) case 'local': from rhodecode.lib.hook_daemon.hook_module import Hooks callback_daemon = HooksModuleCallbackDaemon(Hooks.__module__) diff --git a/rhodecode/lib/hook_daemon/celery_hooks_deamon.py b/rhodecode/lib/hook_daemon/celery_hooks_deamon.py --- a/rhodecode/lib/hook_daemon/celery_hooks_deamon.py +++ b/rhodecode/lib/hook_daemon/celery_hooks_deamon.py @@ -24,10 +24,12 @@ class CeleryHooksCallbackDaemon(BaseHook Context manger for achieving a compatibility with celery backend """ - def __init__(self, config): - # TODO: replace this with settings bootstrapped... - self.task_queue = config.get('app:main', 'celery.broker_url') - self.task_backend = config.get('app:main', 'celery.result_backend') + def __init__(self, task_queue, task_backend): + self.task_queue = task_queue + self.task_backend = task_backend def __repr__(self): return f'CeleryHooksCallbackDaemon(task_queue={self.task_queue}, task_backend={self.task_backend})' + + def __repr__(self): + return f'CeleryHooksCallbackDaemon(task_queue={self.task_queue}, task_backend={self.task_backend})' diff --git a/rhodecode/tests/fixture_mods/fixture_utils.py b/rhodecode/tests/fixture_mods/fixture_utils.py --- a/rhodecode/tests/fixture_mods/fixture_utils.py +++ b/rhodecode/tests/fixture_mods/fixture_utils.py @@ -177,7 +177,7 @@ def baseapp(ini_config, vcsserver, http_ from rhodecode.lib.config_utils import get_app_config from rhodecode.config.middleware import make_pyramid_app - log.info("Using the RhodeCode configuration:{}".format(ini_config)) + log.info("Using the RhodeCode configuration:%s", ini_config) pyramid.paster.setup_logging(ini_config) settings = get_app_config(ini_config) diff --git a/rhodecode/tests/lib/test_hooks_daemon.py b/rhodecode/tests/lib/test_hooks_daemon.py --- a/rhodecode/tests/lib/test_hooks_daemon.py +++ b/rhodecode/tests/lib/test_hooks_daemon.py @@ -322,6 +322,7 @@ class TestPrepareHooksDaemon(object): 'invalid', 'Http', 'HTTP', + 'celerY' )) def test_raises_on_invalid_protocol(self, protocol): expected_extras = { diff --git a/rhodecode/tests/models/test_pullrequest.py b/rhodecode/tests/models/test_pullrequest.py --- a/rhodecode/tests/models/test_pullrequest.py +++ b/rhodecode/tests/models/test_pullrequest.py @@ -567,10 +567,11 @@ def test_merge_response_message(mr_type, @pytest.fixture() -def merge_extras(user_regular): +def merge_extras(request, user_regular): """ Context for the vcs operation when running a merge. """ + extras = { 'ip': '127.0.0.1', 'username': user_regular.username, @@ -578,7 +579,7 @@ def merge_extras(user_regular): 'action': 'push', 'repository': 'fake_target_repo_name', 'scm': 'git', - 'config': 'fake_config_ini_path', + 'config': request.config.getini('pyramid_config'), 'repo_store': '', 'make_lock': None, 'locked_by': [None, None, None],