##// END OF EJS Templates
testing: added webhook tests and fixed tags adding
super-admin -
r4879:e11d95c4 default
parent child Browse files
Show More
@@ -0,0 +1,80 b''
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2010-2020 RhodeCode GmbH
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
21 """
22 Test suite for making push/pull operations, on specially modified INI files
23
24 .. important::
25
26 You must have git >= 1.8.5 for tests to work fine. With 68b939b git started
27 to redirect things to stderr instead of stdout.
28 """
29
30 import pytest
31 import requests
32
33 from rhodecode.tests import GIT_REPO, HG_REPO
34 from rhodecode.tests.vcs_operations import Command, _add_files_and_push
35
36
37 def check_connection():
38 try:
39 response = requests.get('http://httpbin.org')
40 return response.status_code == 200
41 except Exception as e:
42 print(e)
43
44 return False
45
46
47 connection_available = pytest.mark.skipif(
48 not check_connection(), reason="No outside internet connection available")
49
50
51 @pytest.mark.usefixtures("baseapp", "enable_webhook_push_integration")
52 class TestVCSOperationsOnCustomIniConfig(object):
53
54 def test_push_with_webhook_hg(self, rc_web_server, tmpdir):
55 clone_url = rc_web_server.repo_clone_url(HG_REPO)
56
57 stdout, stderr = Command('/tmp').execute(
58 'hg clone', clone_url, tmpdir.strpath)
59
60 push_url = rc_web_server.repo_clone_url(HG_REPO)
61 _add_files_and_push('hg', tmpdir.strpath, clone_url=push_url)
62
63 rc_log = rc_web_server.get_rc_log()
64 assert 'ERROR' not in rc_log
65 assert "executing task TASK:<@task: rhodecode.integrations.types.webhook.post_to_webhook" in rc_log
66 assert "handling event repo-push with integration <rhodecode.integrations.types.webhook.WebhookIntegrationType" in rc_log
67
68 def test_push_with_webhook_gut(self, rc_web_server, tmpdir):
69 clone_url = rc_web_server.repo_clone_url(GIT_REPO)
70
71 stdout, stderr = Command('/tmp').execute(
72 'git clone', clone_url, tmpdir.strpath)
73
74 push_url = rc_web_server.repo_clone_url(GIT_REPO)
75 _add_files_and_push('git', tmpdir.strpath, clone_url=push_url)
76
77 rc_log = rc_web_server.get_rc_log()
78 assert 'ERROR' not in rc_log
79 assert "executing task TASK:<@task: rhodecode.integrations.types.webhook.post_to_webhook" in rc_log
80 assert "handling event repo-push with integration <rhodecode.integrations.types.webhook.WebhookIntegrationType" in rc_log
@@ -989,7 +989,7 b' class TestModifyFilesWithWebInterface(ob'
989 989 commit_id=backend.default_head_id,
990 990 f_path='vcs/nodes.py'),
991 991 params={
992 'message': 'i commited',
992 'message': 'i committed',
993 993 'csrf_token': csrf_token,
994 994 },
995 995 status=302)
@@ -754,7 +754,7 b' class ScmModel(BaseModel):'
754 754 only for git
755 755 :param trigger_push_hook: trigger push hooks
756 756
757 :returns: new commited commit
757 :returns: new committed commit
758 758 """
759 759
760 760 user = self._get_user(user)
@@ -1,6 +1,6 b''
1 1 ## -*- coding: utf-8 -*-
2 2
3 ${_('%(user)s commited on %(date)s UTC') % {
3 ${_('%(user)s committed on %(date)s UTC') % {
4 4 'user': h.person(commit.author),
5 5 'date': h.format_date(commit.date)
6 6 }}
@@ -30,6 +30,7 b' import subprocess32'
30 30 import time
31 31 import uuid
32 32 import dateutil.tz
33 import logging
33 34
34 35 import mock
35 36 import pyramid.testing
@@ -66,6 +67,7 b' from rhodecode.tests.utils import Custom'
66 67 from rhodecode.tests.fixture import Fixture
67 68 from rhodecode.config import utils as config_utils
68 69
70 log = logging.getLogger(__name__)
69 71
70 72 def _split_comma(value):
71 73 return value.split(',')
@@ -268,7 +270,7 b' def baseapp(ini_config, vcsserver, http_'
268 270 from rhodecode.lib.pyramid_utils import get_app_config
269 271 from rhodecode.config.middleware import make_pyramid_app
270 272
271 print("Using the RhodeCode configuration:{}".format(ini_config))
273 log.info("Using the RhodeCode configuration:{}".format(ini_config))
272 274 pyramid.paster.setup_logging(ini_config)
273 275
274 276 settings = get_app_config(ini_config)
@@ -206,7 +206,7 b' def get_available_port(min_port=40000, m'
206 206 @pytest.fixture(scope='session')
207 207 def rcserver_port(request):
208 208 port = get_available_port()
209 print('Using rcserver port {}'.format(port))
209 print('Using rhodecode port {}'.format(port))
210 210 return port
211 211
212 212
@@ -25,6 +25,7 b' import tempfile'
25 25 import pytest
26 26 import subprocess32
27 27 import configobj
28 import logging
28 29
29 30 from urllib2 import urlopen, URLError
30 31 from pyramid.compat import configparser
@@ -33,6 +34,8 b' from pyramid.compat import configparser'
33 34 from rhodecode.tests import TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS
34 35 from rhodecode.tests.utils import is_url_reachable
35 36
37 log = logging.getLogger(__name__)
38
36 39
37 40 def get_port(pyramid_config):
38 41 config = configparser.ConfigParser()
@@ -68,7 +71,7 b' class ServerBase(object):'
68 71 tempfile.gettempdir(), self.log_file_name)
69 72 self.process = None
70 73 self.server_out = None
71 print("Using the {} configuration:{}".format(
74 log.info("Using the {} configuration:{}".format(
72 75 self.__class__.__name__, config_file))
73 76
74 77 if not os.path.isfile(config_file):
@@ -108,7 +111,7 b' class ServerBase(object):'
108 111 "seconds. cmd: `{}`".format(
109 112 self.__class__.__name__, timeout, self.command))
110 113
111 print('Server of {} ready at url {}'.format(
114 log.info('Server of {} ready at url {}'.format(
112 115 self.__class__.__name__, status_url))
113 116
114 117 def shutdown(self):
@@ -144,10 +147,10 b' class RcVCSServer(ServerBase):'
144 147 host_url = self.host_url()
145 148 assert_no_running_instance(host_url)
146 149
147 print('rhodecode-vcsserver start command: {}'.format(' '.join(self._args)))
148 print('rhodecode-vcsserver starting at: {}'.format(host_url))
149 print('rhodecode-vcsserver command: {}'.format(self.command))
150 print('rhodecode-vcsserver logfile: {}'.format(self.log_file))
150 log.info('rhodecode-vcsserver start command: {}'.format(' '.join(self._args)))
151 log.info('rhodecode-vcsserver starting at: {}'.format(host_url))
152 log.info('rhodecode-vcsserver command: {}'.format(self.command))
153 log.info('rhodecode-vcsserver logfile: {}'.format(self.log_file))
151 154
152 155 self.process = subprocess32.Popen(
153 156 self._args, bufsize=0, env=env,
@@ -177,9 +180,9 b' class RcWebServer(ServerBase):'
177 180 host_url = self.host_url()
178 181 assert_no_running_instance(host_url)
179 182
180 print('rhodecode-web starting at: {}'.format(host_url))
181 print('rhodecode-web command: {}'.format(self.command))
182 print('rhodecode-web logfile: {}'.format(self.log_file))
183 log.info('rhodecode-web starting at: {}'.format(host_url))
184 log.info('rhodecode-web command: {}'.format(self.command))
185 log.info('rhodecode-web logfile: {}'.format(self.log_file))
183 186
184 187 self.process = subprocess32.Popen(
185 188 self._args, bufsize=0, env=env,
@@ -77,14 +77,13 b' class Command(object):'
77 77 assert self.process.returncode == 0
78 78
79 79
80 def _add_files(vcs, dest, clone_url=None, tags=None, target_branch=None,
81 new_branch=False, **kwargs):
80 def _add_files(vcs, dest, clone_url=None, tags=None, target_branch=None, new_branch=False, **kwargs):
82 81 git_ident = "git config user.name {} && git config user.email {}".format(
83 82 'Marcin Kuźminski', 'me@email.com')
84 83 cwd = path = jn(dest)
85 84
86 85 tags = tags or []
87 added_file = jn(path, '%ssetup.py' % tempfile._RandomNameSequence().next())
86 added_file = jn(path, '%s_setup.py' % tempfile._RandomNameSequence().next())
88 87 Command(cwd).execute('touch %s' % added_file)
89 88 Command(cwd).execute('%s add %s' % (vcs, added_file))
90 89 author_str = 'Marcin Kuźminski <me@email.com>'
@@ -92,19 +91,20 b' def _add_files(vcs, dest, clone_url=None'
92 91 for i in range(kwargs.get('files_no', 3)):
93 92 cmd = """echo 'added_line%s' >> %s""" % (i, added_file)
94 93 Command(cwd).execute(cmd)
94
95 95 if vcs == 'hg':
96 cmd = """hg commit -m 'commited new %s' -u '%s' %s """ % (
96 cmd = """hg commit -m 'committed new %s' -u '%s' %s """ % (
97 97 i, author_str, added_file
98 98 )
99 99 elif vcs == 'git':
100 cmd = """%s && git commit -m 'commited new %s' %s""" % (
100 cmd = """%s && git commit -m 'committed new %s' %s""" % (
101 101 git_ident, i, added_file)
102 102 Command(cwd).execute(cmd)
103 103
104 104 for tag in tags:
105 105 if vcs == 'hg':
106 106 Command(cwd).execute(
107 'hg tag', tag['name'])
107 'hg tag -m "{}" -u "{}" '.format(tag['commit'], author_str), tag['name'])
108 108 elif vcs == 'git':
109 109 if tag['commit']:
110 110 # annotated tag
@@ -31,6 +31,7 b' import os'
31 31 import tempfile
32 32 import textwrap
33 33 import pytest
34 import logging
34 35
35 36 from rhodecode import events
36 37 from rhodecode.model.db import Integration, UserRepoToPerm, Permission, \
@@ -49,6 +50,8 b" REPO_GROUP = 'a_repo_group'"
49 50 HG_REPO_WITH_GROUP = '%s/%s' % (REPO_GROUP, HG_REPO)
50 51 GIT_REPO_WITH_GROUP = '%s/%s' % (REPO_GROUP, GIT_REPO)
51 52
53 log = logging.getLogger(__name__)
54
52 55
53 56 @pytest.fixture(scope="module")
54 57 def rcextensions(request, db_connection, tmpdir_factory):
@@ -126,10 +129,10 b' def rc_web_server('
126 129 Run the web server as a subprocess. with it's own instance of vcsserver
127 130 """
128 131 rcweb_port = available_port_factory()
129 print('Using rcweb ops test port {}'.format(rcweb_port))
132 log.info('Using rcweb ops test port {}'.format(rcweb_port))
130 133
131 134 vcsserver_port = available_port_factory()
132 print('Using vcsserver ops test port {}'.format(vcsserver_port))
135 log.info('Using vcsserver ops test port {}'.format(vcsserver_port))
133 136
134 137 vcs_log = os.path.join(tempfile.gettempdir(), 'rc_op_vcs.log')
135 138 vcsserver_factory(
General Comments 0
You need to be logged in to leave comments. Login now