##// END OF EJS Templates
core: updated copyrights to 2024
core: updated copyrights to 2024

File last commit:

r1327:278da2b3 default
r1327:278da2b3 default
Show More
test_hooks.py
141 lines | 4.7 KiB | text/x-python | PythonLexer
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 # RhodeCode VCSServer provides access to different vcs backends via network.
core: updated copyrights to 2024
r1327 # Copyright (C) 2014-2024 RhodeCode GmbH
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 #
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
core: deprecated http based callback deamon....
r1315 import pytest
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
import mercurial.ui
import mock
chore(refactor): renamed rc_json to ext_json for ce compat
r1243 from vcsserver.lib.ext_json import json
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 from vcsserver import hooks
def get_hg_ui(extras=None):
"""Create a Config object with a valid RC_SCM_DATA entry."""
extras = extras or {}
required_extras = {
'username': '',
'repository': '',
'locked_by': '',
'scm': '',
'make_lock': '',
'action': '',
'ip': '',
}
required_extras.update(extras)
hg_ui = mercurial.ui.ui()
python3: code change for py3 support...
r1048 hg_ui.setconfig(b'rhodecode', b'RC_SCM_DATA', json.dumps(required_extras))
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
return hg_ui
def test_git_pre_receive_is_disabled():
extras = {'hooks': ['pull']}
response = hooks.git_pre_receive(None, None,
{'RC_SCM_DATA': json.dumps(extras)})
assert response == 0
def test_git_post_receive_is_disabled():
extras = {'hooks': ['pull']}
response = hooks.git_post_receive(None, '',
{'RC_SCM_DATA': json.dumps(extras)})
assert response == 0
def test_git_post_receive_calls_repo_size():
extras = {'hooks': ['push', 'repo_size']}
python3: code change for py3 support...
r1048
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 with mock.patch.object(hooks, '_call_hook') as call_hook_mock:
hooks.git_post_receive(
None, '', {'RC_SCM_DATA': json.dumps(extras)})
hooks: store hook type for extensions.
r555 extras.update({'commit_ids': [], 'hook_type': 'post_receive',
hooks: expose pushed refs inside hooks....
r223 'new_refs': {'bookmarks': [], 'branches': [], 'tags': []}})
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 expected_calls = [
mock.call('repo_size', extras, mock.ANY),
mock.call('post_push', extras, mock.ANY),
]
assert call_hook_mock.call_args_list == expected_calls
def test_git_post_receive_does_not_call_disabled_repo_size():
extras = {'hooks': ['push']}
python3: code change for py3 support...
r1048
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 with mock.patch.object(hooks, '_call_hook') as call_hook_mock:
hooks.git_post_receive(
None, '', {'RC_SCM_DATA': json.dumps(extras)})
hooks: store hook type for extensions.
r555 extras.update({'commit_ids': [], 'hook_type': 'post_receive',
hooks: expose pushed refs inside hooks....
r223 'new_refs': {'bookmarks': [], 'branches': [], 'tags': []}})
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 expected_calls = [
mock.call('post_push', extras, mock.ANY)
]
assert call_hook_mock.call_args_list == expected_calls
def test_repo_size_exception_does_not_affect_git_post_receive():
extras = {'hooks': ['push', 'repo_size']}
status = 0
def side_effect(name, *args, **kwargs):
if name == 'repo_size':
raise Exception('Fake exception')
else:
return status
with mock.patch.object(hooks, '_call_hook') as call_hook_mock:
call_hook_mock.side_effect = side_effect
result = hooks.git_post_receive(
None, '', {'RC_SCM_DATA': json.dumps(extras)})
assert result == status
def test_git_pre_pull_is_disabled():
assert hooks.git_pre_pull({'hooks': ['push']}) == hooks.HookResponse(0, '')
def test_git_post_pull_is_disabled():
assert (
hooks.git_post_pull({'hooks': ['push']}) == hooks.HookResponse(0, ''))
lint: auto-fixes
r1152 class TestGetHooksClient:
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
feat(celery-hooks): added HooksCeleryClient, removed support od HooksDummyClient, updated tests. Fixes: RCCE-55
r1204 def test_return_celery_client_when_queue_and_backend_provided(self):
hooks: cleanups hooks protocol code, and ensure we can propagate options from CE into VCS
r1324 extras = {
'hooks_protocol': 'celery',
'hooks_config': {'broker_url': 'redis://task_queue:0', 'result_backend': 'redis://task_queue:0'}
}
result = hooks._get_hooks_client(extras)
feat(celery-hooks): added HooksCeleryClient, removed support od HooksDummyClient, updated tests. Fixes: RCCE-55
r1204 assert isinstance(result, hooks.HooksCeleryClient)
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
core: deprecated http based callback deamon....
r1315 class TestHooksCeleryClient:
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130
core: deprecated http based callback deamon....
r1315 def test_hooks_http_client_init(self):
queue = 'redis://redis:6379/0'
backend = 'redis://redis:6379/0'
client = hooks.HooksCeleryClient(queue, backend)
assert client.celery_app.conf.broker_url == queue
hooks: cleanups hooks protocol code, and ensure we can propagate options from CE into VCS
r1324
def test_hooks_http_client_init_with_extra_opts(self):
queue = 'redis://redis:6379/0'
backend = 'redis://redis:6379/0'
client = hooks.HooksCeleryClient(queue, backend, _celery_opts={'task_always_eager': True})
assert client.celery_app.conf.broker_url == queue
assert client.celery_app.conf.task_always_eager == True