diff --git a/rhodecode/apps/repository/tests/test_repo_files.py b/rhodecode/apps/repository/tests/test_repo_files.py --- a/rhodecode/apps/repository/tests/test_repo_files.py +++ b/rhodecode/apps/repository/tests/test_repo_files.py @@ -989,7 +989,7 @@ class TestModifyFilesWithWebInterface(ob commit_id=backend.default_head_id, f_path='vcs/nodes.py'), params={ - 'message': 'i commited', + 'message': 'i committed', 'csrf_token': csrf_token, }, status=302) diff --git a/rhodecode/model/scm.py b/rhodecode/model/scm.py --- a/rhodecode/model/scm.py +++ b/rhodecode/model/scm.py @@ -754,7 +754,7 @@ class ScmModel(BaseModel): only for git :param trigger_push_hook: trigger push hooks - :returns: new commited commit + :returns: new committed commit """ user = self._get_user(user) diff --git a/rhodecode/templates/feed/atom_feed_entry.mako b/rhodecode/templates/feed/atom_feed_entry.mako --- a/rhodecode/templates/feed/atom_feed_entry.mako +++ b/rhodecode/templates/feed/atom_feed_entry.mako @@ -1,6 +1,6 @@ ## -*- coding: utf-8 -*- -${_('%(user)s commited on %(date)s UTC') % { +${_('%(user)s committed on %(date)s UTC') % { 'user': h.person(commit.author), 'date': h.format_date(commit.date) }} diff --git a/rhodecode/tests/plugin.py b/rhodecode/tests/plugin.py --- a/rhodecode/tests/plugin.py +++ b/rhodecode/tests/plugin.py @@ -30,6 +30,7 @@ import subprocess32 import time import uuid import dateutil.tz +import logging import mock import pyramid.testing @@ -66,6 +67,7 @@ from rhodecode.tests.utils import Custom from rhodecode.tests.fixture import Fixture from rhodecode.config import utils as config_utils +log = logging.getLogger(__name__) def _split_comma(value): return value.split(',') @@ -268,7 +270,7 @@ def baseapp(ini_config, vcsserver, http_ from rhodecode.lib.pyramid_utils import get_app_config from rhodecode.config.middleware import make_pyramid_app - print("Using the RhodeCode configuration:{}".format(ini_config)) + log.info("Using the RhodeCode configuration:{}".format(ini_config)) pyramid.paster.setup_logging(ini_config) settings = get_app_config(ini_config) diff --git a/rhodecode/tests/pylons_plugin.py b/rhodecode/tests/pylons_plugin.py --- a/rhodecode/tests/pylons_plugin.py +++ b/rhodecode/tests/pylons_plugin.py @@ -206,7 +206,7 @@ def get_available_port(min_port=40000, m @pytest.fixture(scope='session') def rcserver_port(request): port = get_available_port() - print('Using rcserver port {}'.format(port)) + print('Using rhodecode port {}'.format(port)) return port diff --git a/rhodecode/tests/server_utils.py b/rhodecode/tests/server_utils.py --- a/rhodecode/tests/server_utils.py +++ b/rhodecode/tests/server_utils.py @@ -25,6 +25,7 @@ import tempfile import pytest import subprocess32 import configobj +import logging from urllib2 import urlopen, URLError from pyramid.compat import configparser @@ -33,6 +34,8 @@ from pyramid.compat import configparser from rhodecode.tests import TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS from rhodecode.tests.utils import is_url_reachable +log = logging.getLogger(__name__) + def get_port(pyramid_config): config = configparser.ConfigParser() @@ -68,7 +71,7 @@ class ServerBase(object): tempfile.gettempdir(), self.log_file_name) self.process = None self.server_out = None - print("Using the {} configuration:{}".format( + log.info("Using the {} configuration:{}".format( self.__class__.__name__, config_file)) if not os.path.isfile(config_file): @@ -108,7 +111,7 @@ class ServerBase(object): "seconds. cmd: `{}`".format( self.__class__.__name__, timeout, self.command)) - print('Server of {} ready at url {}'.format( + log.info('Server of {} ready at url {}'.format( self.__class__.__name__, status_url)) def shutdown(self): @@ -144,10 +147,10 @@ class RcVCSServer(ServerBase): host_url = self.host_url() assert_no_running_instance(host_url) - print('rhodecode-vcsserver start command: {}'.format(' '.join(self._args))) - print('rhodecode-vcsserver starting at: {}'.format(host_url)) - print('rhodecode-vcsserver command: {}'.format(self.command)) - print('rhodecode-vcsserver logfile: {}'.format(self.log_file)) + log.info('rhodecode-vcsserver start command: {}'.format(' '.join(self._args))) + log.info('rhodecode-vcsserver starting at: {}'.format(host_url)) + log.info('rhodecode-vcsserver command: {}'.format(self.command)) + log.info('rhodecode-vcsserver logfile: {}'.format(self.log_file)) self.process = subprocess32.Popen( self._args, bufsize=0, env=env, @@ -177,9 +180,9 @@ class RcWebServer(ServerBase): host_url = self.host_url() assert_no_running_instance(host_url) - print('rhodecode-web starting at: {}'.format(host_url)) - print('rhodecode-web command: {}'.format(self.command)) - print('rhodecode-web logfile: {}'.format(self.log_file)) + log.info('rhodecode-web starting at: {}'.format(host_url)) + log.info('rhodecode-web command: {}'.format(self.command)) + log.info('rhodecode-web logfile: {}'.format(self.log_file)) self.process = subprocess32.Popen( self._args, bufsize=0, env=env, diff --git a/rhodecode/tests/vcs_operations/__init__.py b/rhodecode/tests/vcs_operations/__init__.py --- a/rhodecode/tests/vcs_operations/__init__.py +++ b/rhodecode/tests/vcs_operations/__init__.py @@ -77,14 +77,13 @@ class Command(object): assert self.process.returncode == 0 -def _add_files(vcs, dest, clone_url=None, tags=None, target_branch=None, - new_branch=False, **kwargs): +def _add_files(vcs, dest, clone_url=None, tags=None, target_branch=None, new_branch=False, **kwargs): git_ident = "git config user.name {} && git config user.email {}".format( 'Marcin Kuźminski', 'me@email.com') cwd = path = jn(dest) tags = tags or [] - added_file = jn(path, '%ssetup.py' % tempfile._RandomNameSequence().next()) + added_file = jn(path, '%s_setup.py' % tempfile._RandomNameSequence().next()) Command(cwd).execute('touch %s' % added_file) Command(cwd).execute('%s add %s' % (vcs, added_file)) author_str = 'Marcin Kuźminski ' @@ -92,19 +91,20 @@ def _add_files(vcs, dest, clone_url=None for i in range(kwargs.get('files_no', 3)): cmd = """echo 'added_line%s' >> %s""" % (i, added_file) Command(cwd).execute(cmd) + if vcs == 'hg': - cmd = """hg commit -m 'commited new %s' -u '%s' %s """ % ( + cmd = """hg commit -m 'committed new %s' -u '%s' %s """ % ( i, author_str, added_file ) elif vcs == 'git': - cmd = """%s && git commit -m 'commited new %s' %s""" % ( + cmd = """%s && git commit -m 'committed new %s' %s""" % ( git_ident, i, added_file) Command(cwd).execute(cmd) for tag in tags: if vcs == 'hg': Command(cwd).execute( - 'hg tag', tag['name']) + 'hg tag -m "{}" -u "{}" '.format(tag['commit'], author_str), tag['name']) elif vcs == 'git': if tag['commit']: # annotated tag diff --git a/rhodecode/tests/vcs_operations/conftest.py b/rhodecode/tests/vcs_operations/conftest.py --- a/rhodecode/tests/vcs_operations/conftest.py +++ b/rhodecode/tests/vcs_operations/conftest.py @@ -31,6 +31,7 @@ import os import tempfile import textwrap import pytest +import logging from rhodecode import events from rhodecode.model.db import Integration, UserRepoToPerm, Permission, \ @@ -49,6 +50,8 @@ REPO_GROUP = 'a_repo_group' HG_REPO_WITH_GROUP = '%s/%s' % (REPO_GROUP, HG_REPO) GIT_REPO_WITH_GROUP = '%s/%s' % (REPO_GROUP, GIT_REPO) +log = logging.getLogger(__name__) + @pytest.fixture(scope="module") def rcextensions(request, db_connection, tmpdir_factory): @@ -126,10 +129,10 @@ def rc_web_server( Run the web server as a subprocess. with it's own instance of vcsserver """ rcweb_port = available_port_factory() - print('Using rcweb ops test port {}'.format(rcweb_port)) + log.info('Using rcweb ops test port {}'.format(rcweb_port)) vcsserver_port = available_port_factory() - print('Using vcsserver ops test port {}'.format(vcsserver_port)) + log.info('Using vcsserver ops test port {}'.format(vcsserver_port)) vcs_log = os.path.join(tempfile.gettempdir(), 'rc_op_vcs.log') vcsserver_factory( diff --git a/rhodecode/tests/vcs_operations/test_vcs_operations_integrations_trigger.py b/rhodecode/tests/vcs_operations/test_vcs_operations_integrations_trigger.py new file mode 100644 --- /dev/null +++ b/rhodecode/tests/vcs_operations/test_vcs_operations_integrations_trigger.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- + +# Copyright (C) 2010-2020 RhodeCode GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License, version 3 +# (only), as published by the Free Software Foundation. +# +# 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 Affero General Public License +# along with this program. If not, see . +# +# This program is dual-licensed. If you wish to learn more about the +# RhodeCode Enterprise Edition, including its added features, Support services, +# and proprietary license terms, please see https://rhodecode.com/licenses/ + +""" +Test suite for making push/pull operations, on specially modified INI files + +.. important:: + + You must have git >= 1.8.5 for tests to work fine. With 68b939b git started + to redirect things to stderr instead of stdout. +""" + +import pytest +import requests + +from rhodecode.tests import GIT_REPO, HG_REPO +from rhodecode.tests.vcs_operations import Command, _add_files_and_push + + +def check_connection(): + try: + response = requests.get('http://httpbin.org') + return response.status_code == 200 + except Exception as e: + print(e) + + return False + + +connection_available = pytest.mark.skipif( + not check_connection(), reason="No outside internet connection available") + + +@pytest.mark.usefixtures("baseapp", "enable_webhook_push_integration") +class TestVCSOperationsOnCustomIniConfig(object): + + def test_push_with_webhook_hg(self, rc_web_server, tmpdir): + clone_url = rc_web_server.repo_clone_url(HG_REPO) + + stdout, stderr = Command('/tmp').execute( + 'hg clone', clone_url, tmpdir.strpath) + + push_url = rc_web_server.repo_clone_url(HG_REPO) + _add_files_and_push('hg', tmpdir.strpath, clone_url=push_url) + + rc_log = rc_web_server.get_rc_log() + assert 'ERROR' not in rc_log + assert "executing task TASK:<@task: rhodecode.integrations.types.webhook.post_to_webhook" in rc_log + assert "handling event repo-push with integration