Show More
@@ -0,0 +1,194 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | ||
|
3 | # Copyright (C) 2010-2017 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 | import os | |
|
23 | import time | |
|
24 | import tempfile | |
|
25 | import pytest | |
|
26 | import subprocess32 | |
|
27 | import configobj | |
|
28 | ||
|
29 | from urllib2 import urlopen, URLError | |
|
30 | from pyramid.compat import configparser | |
|
31 | ||
|
32 | ||
|
33 | from rhodecode.tests import TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS | |
|
34 | from rhodecode.tests.utils import is_url_reachable | |
|
35 | ||
|
36 | ||
|
37 | def get_port(pyramid_config): | |
|
38 | config = configparser.ConfigParser() | |
|
39 | config.read(pyramid_config) | |
|
40 | return config.get('server:main', 'port') | |
|
41 | ||
|
42 | ||
|
43 | def get_host_url(pyramid_config): | |
|
44 | """Construct the host url using the port in the test configuration.""" | |
|
45 | return '127.0.0.1:%s' % get_port(pyramid_config) | |
|
46 | ||
|
47 | ||
|
48 | def assert_no_running_instance(url): | |
|
49 | if is_url_reachable(url): | |
|
50 | print("Hint: Usually this means another instance of server " | |
|
51 | "is running in the background at %s." % url) | |
|
52 | pytest.fail( | |
|
53 | "Port is not free at %s, cannot start server at" % url) | |
|
54 | ||
|
55 | ||
|
56 | class ServerBase(object): | |
|
57 | _args = [] | |
|
58 | log_file_name = 'NOT_DEFINED.log' | |
|
59 | status_url_tmpl = 'http://{host}:{port}' | |
|
60 | ||
|
61 | def __init__(self, config_file, log_file): | |
|
62 | self.config_file = config_file | |
|
63 | config_data = configobj.ConfigObj(config_file) | |
|
64 | self._config = config_data['server:main'] | |
|
65 | ||
|
66 | self._args = [] | |
|
67 | self.log_file = log_file or os.path.join( | |
|
68 | tempfile.gettempdir(), self.log_file_name) | |
|
69 | self.process = None | |
|
70 | self.server_out = None | |
|
71 | print("Using the {} configuration:{}".format( | |
|
72 | self.__class__.__name__, config_file)) | |
|
73 | ||
|
74 | if not os.path.isfile(config_file): | |
|
75 | raise RuntimeError('Failed to get config at {}'.format(config_file)) | |
|
76 | ||
|
77 | @property | |
|
78 | def command(self): | |
|
79 | return ' '.join(self._args) | |
|
80 | ||
|
81 | @property | |
|
82 | def http_url(self): | |
|
83 | template = 'http://{host}:{port}/' | |
|
84 | return template.format(**self._config) | |
|
85 | ||
|
86 | def host_url(self): | |
|
87 | return 'http://' + get_host_url(self.config_file) | |
|
88 | ||
|
89 | def get_rc_log(self): | |
|
90 | with open(self.log_file) as f: | |
|
91 | return f.read() | |
|
92 | ||
|
93 | def wait_until_ready(self, timeout=15): | |
|
94 | host = self._config['host'] | |
|
95 | port = self._config['port'] | |
|
96 | status_url = self.status_url_tmpl.format(host=host, port=port) | |
|
97 | start = time.time() | |
|
98 | ||
|
99 | while time.time() - start < timeout: | |
|
100 | try: | |
|
101 | urlopen(status_url) | |
|
102 | break | |
|
103 | except URLError: | |
|
104 | time.sleep(0.2) | |
|
105 | else: | |
|
106 | pytest.exit( | |
|
107 | "Starting the {} failed or took more than {} " | |
|
108 | "seconds. cmd: `{}`".format( | |
|
109 | self.__class__.__name__, timeout, self.command)) | |
|
110 | ||
|
111 | def shutdown(self): | |
|
112 | self.process.kill() | |
|
113 | self.server_out.flush() | |
|
114 | self.server_out.close() | |
|
115 | ||
|
116 | def get_log_file_with_port(self): | |
|
117 | log_file = list(self.log_file.partition('.log')) | |
|
118 | log_file.insert(1, get_port(self.config_file)) | |
|
119 | log_file = ''.join(log_file) | |
|
120 | return log_file | |
|
121 | ||
|
122 | ||
|
123 | class RcVCSServer(ServerBase): | |
|
124 | """ | |
|
125 | Represents a running VCSServer instance. | |
|
126 | """ | |
|
127 | ||
|
128 | log_file_name = 'rc-vcsserver.log' | |
|
129 | status_url_tmpl = 'http://{host}:{port}/status' | |
|
130 | ||
|
131 | def __init__(self, config_file, log_file=None): | |
|
132 | super(RcVCSServer, self).__init__(config_file, log_file) | |
|
133 | self._args = [ | |
|
134 | 'gunicorn', '--paste', self.config_file] | |
|
135 | ||
|
136 | def start(self): | |
|
137 | env = os.environ.copy() | |
|
138 | ||
|
139 | self.log_file = self.get_log_file_with_port() | |
|
140 | self.server_out = open(self.log_file, 'w') | |
|
141 | ||
|
142 | host_url = self.host_url() | |
|
143 | assert_no_running_instance(host_url) | |
|
144 | ||
|
145 | print('rhodecode-vcsserver starting at: {}'.format(host_url)) | |
|
146 | print('rhodecode-vcsserver command: {}'.format(self.command)) | |
|
147 | print('rhodecode-vcsserver logfile: {}'.format(self.log_file)) | |
|
148 | ||
|
149 | self.process = subprocess32.Popen( | |
|
150 | self._args, bufsize=0, env=env, | |
|
151 | stdout=self.server_out, stderr=self.server_out) | |
|
152 | ||
|
153 | ||
|
154 | class RcWebServer(ServerBase): | |
|
155 | """ | |
|
156 | Represents a running RCE web server used as a test fixture. | |
|
157 | """ | |
|
158 | ||
|
159 | log_file_name = 'rc-web.log' | |
|
160 | status_url_tmpl = 'http://{host}:{port}/_admin/ops/ping' | |
|
161 | ||
|
162 | def __init__(self, config_file, log_file=None): | |
|
163 | super(RcWebServer, self).__init__(config_file, log_file) | |
|
164 | self._args = [ | |
|
165 | 'gunicorn', '--worker-class', 'gevent', '--paste', config_file] | |
|
166 | ||
|
167 | def start(self): | |
|
168 | env = os.environ.copy() | |
|
169 | env['RC_NO_TMP_PATH'] = '1' | |
|
170 | ||
|
171 | self.log_file = self.get_log_file_with_port() | |
|
172 | self.server_out = open(self.log_file, 'w') | |
|
173 | ||
|
174 | host_url = self.host_url() | |
|
175 | assert_no_running_instance(host_url) | |
|
176 | ||
|
177 | print('rhodecode-web starting at: {}'.format(host_url)) | |
|
178 | print('rhodecode-web command: {}'.format(self.command)) | |
|
179 | print('rhodecode-web logfile: {}'.format(self.log_file)) | |
|
180 | ||
|
181 | self.process = subprocess32.Popen( | |
|
182 | self._args, bufsize=0, env=env, | |
|
183 | stdout=self.server_out, stderr=self.server_out) | |
|
184 | ||
|
185 | def repo_clone_url(self, repo_name, **kwargs): | |
|
186 | params = { | |
|
187 | 'user': TEST_USER_ADMIN_LOGIN, | |
|
188 | 'passwd': TEST_USER_ADMIN_PASS, | |
|
189 | 'host': get_host_url(self.config_file), | |
|
190 | 'cloned_repo': repo_name, | |
|
191 | } | |
|
192 | params.update(**kwargs) | |
|
193 | _url = 'http://%(user)s:%(passwd)s@%(host)s/%(cloned_repo)s' % params | |
|
194 | return _url |
@@ -43,7 +43,6 b' def vcsserver_http_echo_app(request, vcs' | |||
|
43 | 43 | """ |
|
44 | 44 | vcsserver = vcsserver_factory( |
|
45 | 45 | request=request, |
|
46 | use_http=True, | |
|
47 | 46 | overrides=[{'app:main': {'dev.use_echo_app': 'true'}}]) |
|
48 | 47 | return vcsserver |
|
49 | 48 |
@@ -18,25 +18,15 b'' | |||
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | import os | |
|
22 | 21 | import json |
|
23 | import time | |
|
24 | 22 | import platform |
|
25 | 23 | import socket |
|
26 | import tempfile | |
|
27 | import subprocess32 | |
|
28 | 24 | |
|
29 | from urllib2 import urlopen, URLError | |
|
30 | ||
|
31 | import configobj | |
|
32 | 25 | import pytest |
|
33 | 26 | |
|
34 | ||
|
35 | 27 | from rhodecode.lib.pyramid_utils import get_app_config |
|
36 | 28 | from rhodecode.tests.fixture import TestINI |
|
37 |
from rhodecode.tests. |
|
|
38 | ||
|
39 | VCSSERVER_LOG = os.path.join(tempfile.gettempdir(), 'rc-vcsserver.log') | |
|
29 | from rhodecode.tests.server_utils import RcVCSServer | |
|
40 | 30 | |
|
41 | 31 | |
|
42 | 32 | def _parse_json(value): |
@@ -94,17 +84,8 b' def pytest_addoption(parser):' | |||
|
94 | 84 | "Start the VCSServer with HTTP protocol support.") |
|
95 | 85 | |
|
96 | 86 | |
|
97 | @pytest.fixture(scope="session") | |
|
98 | def vcs_server_config_override(request): | |
|
99 | """ | |
|
100 | Allows injecting the overrides by specifying this inside test class | |
|
101 | """ | |
|
102 | ||
|
103 | return () | |
|
104 | ||
|
105 | ||
|
106 | 87 | @pytest.fixture(scope='session') |
|
107 |
def vcsserver(request, vcsserver_port, vcsserver_factory |
|
|
88 | def vcsserver(request, vcsserver_port, vcsserver_factory): | |
|
108 | 89 | """ |
|
109 | 90 | Session scope VCSServer. |
|
110 | 91 | |
@@ -125,10 +106,8 b' def vcsserver(request, vcsserver_port, v' | |||
|
125 | 106 | if not request.config.getoption('with_vcsserver'): |
|
126 | 107 | return None |
|
127 | 108 | |
|
128 | use_http = _use_vcs_http_server(request.config) | |
|
129 | 109 | return vcsserver_factory( |
|
130 |
request, |
|
|
131 | overrides=vcs_server_config_override) | |
|
110 | request, vcsserver_port=vcsserver_port) | |
|
132 | 111 | |
|
133 | 112 | |
|
134 | 113 | @pytest.fixture(scope='session') |
@@ -137,23 +116,21 b' def vcsserver_factory(tmpdir_factory):' | |||
|
137 | 116 | Use this if you need a running vcsserver with a special configuration. |
|
138 | 117 | """ |
|
139 | 118 | |
|
140 |
def factory(request |
|
|
119 | def factory(request, overrides=(), vcsserver_port=None, | |
|
120 | log_file=None): | |
|
141 | 121 | |
|
142 | 122 | if vcsserver_port is None: |
|
143 | 123 | vcsserver_port = get_available_port() |
|
144 | 124 | |
|
145 | 125 | overrides = list(overrides) |
|
146 | if use_http: | |
|
147 | 126 |
|
|
148 | else: | |
|
149 | overrides.append({'DEFAULT': {'port': vcsserver_port}}) | |
|
150 | 127 | |
|
151 | 128 | if is_cygwin(): |
|
152 | 129 | platform_override = {'DEFAULT': { |
|
153 | 130 | 'beaker.cache.repo_object.type': 'nocache'}} |
|
154 | 131 | overrides.append(platform_override) |
|
155 | 132 | |
|
156 |
option_name = 'vcsserver_config_http' |
|
|
133 | option_name = 'vcsserver_config_http' | |
|
157 | 134 | override_option_name = 'vcsserver_config_override' |
|
158 | 135 | config_file = get_config( |
|
159 | 136 | request.config, option_name=option_name, |
@@ -161,9 +138,7 b' def vcsserver_factory(tmpdir_factory):' | |||
|
161 | 138 | basetemp=tmpdir_factory.getbasetemp().strpath, |
|
162 | 139 | prefix='test_vcs_') |
|
163 | 140 | |
|
164 | print("Using the VCSServer configuration:{}".format(config_file)) | |
|
165 | ServerClass = HttpVCSServer if use_http else None | |
|
166 | server = ServerClass(config_file) | |
|
141 | server = RcVCSServer(config_file, log_file) | |
|
167 | 142 | server.start() |
|
168 | 143 | |
|
169 | 144 | @request.addfinalizer |
@@ -180,93 +155,11 b' def is_cygwin():' | |||
|
180 | 155 | return 'cygwin' in platform.system().lower() |
|
181 | 156 | |
|
182 | 157 | |
|
183 | def _use_vcs_http_server(config): | |
|
184 | protocol_option = 'vcsserver_protocol' | |
|
185 | protocol = ( | |
|
186 | config.getoption(protocol_option) or | |
|
187 | config.getini(protocol_option) or | |
|
188 | 'http') | |
|
189 | return protocol == 'http' | |
|
190 | ||
|
191 | ||
|
192 | 158 | def _use_log_level(config): |
|
193 | 159 | level = config.getoption('test_loglevel') or 'warn' |
|
194 | 160 | return level.upper() |
|
195 | 161 | |
|
196 | 162 | |
|
197 | class VCSServer(object): | |
|
198 | """ | |
|
199 | Represents a running VCSServer instance. | |
|
200 | """ | |
|
201 | ||
|
202 | _args = [] | |
|
203 | ||
|
204 | def start(self): | |
|
205 | print("Starting the VCSServer: {}".format(self._args)) | |
|
206 | self.process = subprocess32.Popen(self._args) | |
|
207 | ||
|
208 | def wait_until_ready(self, timeout=30): | |
|
209 | raise NotImplementedError() | |
|
210 | ||
|
211 | def shutdown(self): | |
|
212 | self.process.kill() | |
|
213 | ||
|
214 | ||
|
215 | class HttpVCSServer(VCSServer): | |
|
216 | """ | |
|
217 | Represents a running VCSServer instance. | |
|
218 | """ | |
|
219 | def __init__(self, config_file): | |
|
220 | self.config_file = config_file | |
|
221 | config_data = configobj.ConfigObj(config_file) | |
|
222 | self._config = config_data['server:main'] | |
|
223 | ||
|
224 | args = ['gunicorn', '--paste', config_file] | |
|
225 | self._args = args | |
|
226 | ||
|
227 | @property | |
|
228 | def http_url(self): | |
|
229 | template = 'http://{host}:{port}/' | |
|
230 | return template.format(**self._config) | |
|
231 | ||
|
232 | def start(self): | |
|
233 | env = os.environ.copy() | |
|
234 | host_url = 'http://' + get_host_url(self.config_file) | |
|
235 | ||
|
236 | rc_log = list(VCSSERVER_LOG.partition('.log')) | |
|
237 | rc_log.insert(1, get_port(self.config_file)) | |
|
238 | rc_log = ''.join(rc_log) | |
|
239 | ||
|
240 | server_out = open(rc_log, 'w') | |
|
241 | ||
|
242 | command = ' '.join(self._args) | |
|
243 | print('rhodecode-vcsserver starting at: {}'.format(host_url)) | |
|
244 | print('rhodecode-vcsserver command: {}'.format(command)) | |
|
245 | print('rhodecode-vcsserver logfile: {}'.format(rc_log)) | |
|
246 | self.process = subprocess32.Popen( | |
|
247 | self._args, bufsize=0, env=env, stdout=server_out, stderr=server_out) | |
|
248 | ||
|
249 | def wait_until_ready(self, timeout=30): | |
|
250 | host = self._config['host'] | |
|
251 | port = self._config['port'] | |
|
252 | status_url = 'http://{host}:{port}/status'.format(host=host, port=port) | |
|
253 | start = time.time() | |
|
254 | ||
|
255 | while time.time() - start < timeout: | |
|
256 | try: | |
|
257 | urlopen(status_url) | |
|
258 | break | |
|
259 | except URLError: | |
|
260 | time.sleep(0.2) | |
|
261 | else: | |
|
262 | pytest.exit( | |
|
263 | "Starting the VCSServer failed or took more than {} " | |
|
264 | "seconds. cmd: `{}`".format(timeout, ' '.join(self._args))) | |
|
265 | ||
|
266 | def shutdown(self): | |
|
267 | self.process.kill() | |
|
268 | ||
|
269 | ||
|
270 | 163 | @pytest.fixture(scope='session') |
|
271 | 164 | def ini_config(request, tmpdir_factory, rcserver_port, vcsserver_port): |
|
272 | 165 | option_name = 'pyramid_config' |
@@ -280,6 +173,10 b' def ini_config(request, tmpdir_factory, ' | |||
|
280 | 173 | # fixtures of the test cases. For the test run it must always be |
|
281 | 174 | # off in the INI file. |
|
282 | 175 | 'vcs.start_server': 'false', |
|
176 | ||
|
177 | 'vcs.server.protocol': 'http', | |
|
178 | 'vcs.scm_app_implementation': 'http', | |
|
179 | 'vcs.hooks.protocol': 'http', | |
|
283 | 180 | }}, |
|
284 | 181 | |
|
285 | 182 | {'handler_console': { |
@@ -289,14 +186,6 b' def ini_config(request, tmpdir_factory, ' | |||
|
289 | 186 | }}, |
|
290 | 187 | |
|
291 | 188 | ] |
|
292 | if _use_vcs_http_server(request.config): | |
|
293 | overrides.append({ | |
|
294 | 'app:main': { | |
|
295 | 'vcs.server.protocol': 'http', | |
|
296 | 'vcs.scm_app_implementation': 'http', | |
|
297 | 'vcs.hooks.protocol': 'http', | |
|
298 | } | |
|
299 | }) | |
|
300 | 189 | |
|
301 | 190 | filename = get_config( |
|
302 | 191 | request.config, option_name=option_name, |
@@ -313,6 +202,19 b' def ini_settings(ini_config):' | |||
|
313 | 202 | return get_app_config(ini_path) |
|
314 | 203 | |
|
315 | 204 | |
|
205 | def get_available_port(): | |
|
206 | family = socket.AF_INET | |
|
207 | socktype = socket.SOCK_STREAM | |
|
208 | host = '127.0.0.1' | |
|
209 | ||
|
210 | mysocket = socket.socket(family, socktype) | |
|
211 | mysocket.bind((host, 0)) | |
|
212 | port = mysocket.getsockname()[1] | |
|
213 | mysocket.close() | |
|
214 | del mysocket | |
|
215 | return port | |
|
216 | ||
|
217 | ||
|
316 | 218 | @pytest.fixture(scope='session') |
|
317 | 219 | def rcserver_port(request): |
|
318 | 220 | port = get_available_port() |
@@ -329,19 +231,6 b' def vcsserver_port(request):' | |||
|
329 | 231 | return port |
|
330 | 232 | |
|
331 | 233 | |
|
332 | def get_available_port(): | |
|
333 | family = socket.AF_INET | |
|
334 | socktype = socket.SOCK_STREAM | |
|
335 | host = '127.0.0.1' | |
|
336 | ||
|
337 | mysocket = socket.socket(family, socktype) | |
|
338 | mysocket.bind((host, 0)) | |
|
339 | port = mysocket.getsockname()[1] | |
|
340 | mysocket.close() | |
|
341 | del mysocket | |
|
342 | return port | |
|
343 | ||
|
344 | ||
|
345 | 234 | @pytest.fixture(scope='session') |
|
346 | 235 | def available_port_factory(): |
|
347 | 236 | """ |
@@ -31,11 +31,6 b' from rhodecode.tests import get_new_dir' | |||
|
31 | 31 | from rhodecode.tests.utils import check_skip_backends, check_xfail_backends |
|
32 | 32 | |
|
33 | 33 | |
|
34 | @pytest.fixture(scope="session") | |
|
35 | def vcs_server_config_override(): | |
|
36 | return ({'server:main': {'workers': 1}},) | |
|
37 | ||
|
38 | ||
|
39 | 34 | @pytest.fixture() |
|
40 | 35 | def vcs_repository_support( |
|
41 | 36 | request, backend_alias, baseapp, _vcs_repo_container): |
@@ -27,76 +27,30 b' py.test config for test suite for making' | |||
|
27 | 27 | to redirect things to stderr instead of stdout. |
|
28 | 28 | """ |
|
29 | 29 | |
|
30 | import ConfigParser | |
|
31 | 30 | import os |
|
32 | import subprocess32 | |
|
33 | 31 | import tempfile |
|
34 | 32 | import textwrap |
|
35 | 33 | import pytest |
|
36 | 34 | |
|
37 | import rhodecode | |
|
35 | from rhodecode import events | |
|
36 | from rhodecode.model.db import Integration | |
|
37 | from rhodecode.model.integration import IntegrationModel | |
|
38 | 38 | from rhodecode.model.db import Repository |
|
39 | 39 | from rhodecode.model.meta import Session |
|
40 | 40 | from rhodecode.model.settings import SettingsModel |
|
41 | from rhodecode.tests import ( | |
|
42 | GIT_REPO, HG_REPO, TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS,) | |
|
41 | from rhodecode.integrations.types.webhook import WebhookIntegrationType | |
|
42 | ||
|
43 | from rhodecode.tests import GIT_REPO, HG_REPO | |
|
43 | 44 | from rhodecode.tests.fixture import Fixture |
|
44 |
from rhodecode.tests.utils import |
|
|
45 | from rhodecode.tests.server_utils import RcWebServer | |
|
45 | 46 | |
|
46 | RC_LOG = os.path.join(tempfile.gettempdir(), 'rc.log') | |
|
47 | 47 | REPO_GROUP = 'a_repo_group' |
|
48 | 48 | HG_REPO_WITH_GROUP = '%s/%s' % (REPO_GROUP, HG_REPO) |
|
49 | 49 | GIT_REPO_WITH_GROUP = '%s/%s' % (REPO_GROUP, GIT_REPO) |
|
50 | 50 | |
|
51 | 51 | |
|
52 | def assert_no_running_instance(url): | |
|
53 | if is_url_reachable(url): | |
|
54 | print("Hint: Usually this means another instance of Enterprise " | |
|
55 | "is running in the background.") | |
|
56 | pytest.fail( | |
|
57 | "Port is not free at %s, cannot start web interface" % url) | |
|
58 | ||
|
59 | ||
|
60 | def get_port(pyramid_config): | |
|
61 | config = ConfigParser.ConfigParser() | |
|
62 | config.read(pyramid_config) | |
|
63 | return config.get('server:main', 'port') | |
|
64 | ||
|
65 | ||
|
66 | def get_host_url(pyramid_config): | |
|
67 | """Construct the host url using the port in the test configuration.""" | |
|
68 | return '127.0.0.1:%s' % get_port(pyramid_config) | |
|
69 | ||
|
70 | ||
|
71 | class RcWebServer(object): | |
|
72 | """ | |
|
73 | Represents a running RCE web server used as a test fixture. | |
|
74 | """ | |
|
75 | def __init__(self, pyramid_config, log_file): | |
|
76 | self.pyramid_config = pyramid_config | |
|
77 | self.log_file = log_file | |
|
78 | ||
|
79 | def repo_clone_url(self, repo_name, **kwargs): | |
|
80 | params = { | |
|
81 | 'user': TEST_USER_ADMIN_LOGIN, | |
|
82 | 'passwd': TEST_USER_ADMIN_PASS, | |
|
83 | 'host': get_host_url(self.pyramid_config), | |
|
84 | 'cloned_repo': repo_name, | |
|
85 | } | |
|
86 | params.update(**kwargs) | |
|
87 | _url = 'http://%(user)s:%(passwd)s@%(host)s/%(cloned_repo)s' % params | |
|
88 | return _url | |
|
89 | ||
|
90 | def host_url(self): | |
|
91 | return 'http://' + get_host_url(self.pyramid_config) | |
|
92 | ||
|
93 | def get_rc_log(self): | |
|
94 | with open(self.log_file) as f: | |
|
95 | return f.read() | |
|
96 | ||
|
97 | ||
|
98 | 52 | @pytest.fixture(scope="module") |
|
99 |
def rcextensions(request, |
|
|
53 | def rcextensions(request, db_connection, tmpdir_factory): | |
|
100 | 54 | """ |
|
101 | 55 | Installs a testing rcextensions pack to ensure they work as expected. |
|
102 | 56 | """ |
@@ -122,7 +76,7 b' def rcextensions(request, baseapp, tmpdi' | |||
|
122 | 76 | |
|
123 | 77 | |
|
124 | 78 | @pytest.fixture(scope="module") |
|
125 |
def repos(request, |
|
|
79 | def repos(request, db_connection): | |
|
126 | 80 | """Create a copy of each test repo in a repo group.""" |
|
127 | 81 | fixture = Fixture() |
|
128 | 82 | repo_group = fixture.create_repo_group(REPO_GROUP) |
@@ -141,62 +95,56 b' def repos(request, baseapp):' | |||
|
141 | 95 | fixture.destroy_repo_group(repo_group_id) |
|
142 | 96 | |
|
143 | 97 | |
|
144 |
@pytest.fixture(scope=" |
|
|
145 |
def |
|
|
146 | return ({'server:main': {'workers': 2}},) | |
|
98 | @pytest.fixture(scope="module") | |
|
99 | def rc_web_server_config_modification(): | |
|
100 | return [] | |
|
147 | 101 | |
|
148 | 102 | |
|
149 | 103 | @pytest.fixture(scope="module") |
|
150 | def rc_web_server_config(testini_factory): | |
|
104 | def rc_web_server_config_factory(testini_factory, rc_web_server_config_modification): | |
|
151 | 105 | """ |
|
152 | 106 | Configuration file used for the fixture `rc_web_server`. |
|
153 | 107 | """ |
|
154 | CUSTOM_PARAMS = [ | |
|
108 | ||
|
109 | def factory(vcsserver_port): | |
|
110 | custom_params = [ | |
|
155 | 111 | {'handler_console': {'level': 'DEBUG'}}, |
|
112 | {'app:main': {'vcs.server': 'localhost:%s' % vcsserver_port}} | |
|
156 | 113 | ] |
|
157 | return testini_factory(CUSTOM_PARAMS) | |
|
114 | custom_params.extend(rc_web_server_config_modification) | |
|
115 | return testini_factory(custom_params) | |
|
116 | return factory | |
|
158 | 117 | |
|
159 | 118 | |
|
160 | 119 | @pytest.fixture(scope="module") |
|
161 | 120 | def rc_web_server( |
|
162 | request, baseapp, rc_web_server_config, repos, rcextensions): | |
|
163 | """ | |
|
164 | Run the web server as a subprocess. | |
|
165 | ||
|
166 | Since we have already a running vcsserver, this is not spawned again. | |
|
121 | request, vcsserver_factory, available_port_factory, | |
|
122 | rc_web_server_config_factory, repos, rcextensions): | |
|
167 | 123 |
|
|
168 | env = os.environ.copy() | |
|
169 | env['RC_NO_TMP_PATH'] = '1' | |
|
124 | Run the web server as a subprocess. with it's own instance of vcsserver | |
|
125 | """ | |
|
170 | 126 | |
|
171 | rc_log = list(RC_LOG.partition('.log')) | |
|
172 | rc_log.insert(1, get_port(rc_web_server_config)) | |
|
173 | rc_log = ''.join(rc_log) | |
|
127 | vcsserver_port = available_port_factory() | |
|
128 | print('Using vcsserver ops test port {}'.format(vcsserver_port)) | |
|
174 | 129 | |
|
175 | server_out = open(rc_log, 'w') | |
|
176 | ||
|
177 | host_url = 'http://' + get_host_url(rc_web_server_config) | |
|
178 | assert_no_running_instance(host_url) | |
|
179 | command = ['gunicorn', '--worker-class', 'gevent', '--paste', rc_web_server_config] | |
|
130 | vcs_log = os.path.join(tempfile.gettempdir(), 'rc_op_vcs.log') | |
|
131 | vcsserver_factory( | |
|
132 | request, vcsserver_port=vcsserver_port, | |
|
133 | log_file=vcs_log, | |
|
134 | overrides=({'server:main': {'workers': 2}},)) | |
|
180 | 135 | |
|
181 | print('rhodecode-web starting at: {}'.format(host_url)) | |
|
182 | print('rhodecode-web command: {}'.format(command)) | |
|
183 | print('rhodecode-web logfile: {}'.format(rc_log)) | |
|
184 | ||
|
185 | proc = subprocess32.Popen( | |
|
186 | command, bufsize=0, env=env, stdout=server_out, stderr=server_out) | |
|
187 | ||
|
188 | wait_for_url(host_url, timeout=30) | |
|
136 | rc_log = os.path.join(tempfile.gettempdir(), 'rc_op_web.log') | |
|
137 | rc_web_server_config = rc_web_server_config_factory( | |
|
138 | vcsserver_port=vcsserver_port) | |
|
139 | server = RcWebServer(rc_web_server_config, log_file=rc_log) | |
|
140 | server.start() | |
|
189 | 141 | |
|
190 | 142 | @request.addfinalizer |
|
191 | def stop_web_server(): | |
|
192 | # TODO: Find out how to integrate with the reporting of py.test to | |
|
193 | # make this information available. | |
|
194 | print("\nServer log file written to %s" % (rc_log, )) | |
|
195 | proc.kill() | |
|
196 | server_out.flush() | |
|
197 | server_out.close() | |
|
143 | def cleanup(): | |
|
144 | server.shutdown() | |
|
198 | 145 | |
|
199 | return RcWebServer(rc_web_server_config, log_file=rc_log) | |
|
146 | server.wait_until_ready() | |
|
147 | return server | |
|
200 | 148 | |
|
201 | 149 | |
|
202 | 150 | @pytest.fixture |
@@ -274,3 +222,41 b' def fs_repo_only(request, rhodecode_fixt' | |||
|
274 | 222 | request.addfinalizer(cleanup) |
|
275 | 223 | |
|
276 | 224 | return fs_repo_fabric |
|
225 | ||
|
226 | ||
|
227 | @pytest.fixture | |
|
228 | def enable_webhook_push_integration(request): | |
|
229 | integration = Integration() | |
|
230 | integration.integration_type = WebhookIntegrationType.key | |
|
231 | Session().add(integration) | |
|
232 | ||
|
233 | settings = dict( | |
|
234 | url='http://httpbin.org', | |
|
235 | secret_token='secret', | |
|
236 | username=None, | |
|
237 | password=None, | |
|
238 | custom_header_key=None, | |
|
239 | custom_header_val=None, | |
|
240 | method_type='get', | |
|
241 | events=[events.RepoPushEvent.name], | |
|
242 | log_data=True | |
|
243 | ) | |
|
244 | ||
|
245 | IntegrationModel().update_integration( | |
|
246 | integration, | |
|
247 | name='IntegrationWebhookTest', | |
|
248 | enabled=True, | |
|
249 | settings=settings, | |
|
250 | repo=None, | |
|
251 | repo_group=None, | |
|
252 | child_repos_only=False, | |
|
253 | ) | |
|
254 | Session().commit() | |
|
255 | integration_id = integration.integration_id | |
|
256 | ||
|
257 | @request.addfinalizer | |
|
258 | def cleanup(): | |
|
259 | integration = Integration.get(integration_id) | |
|
260 | Session().delete(integration) | |
|
261 | Session().commit() | |
|
262 |
@@ -33,14 +33,12 b' from rhodecode.tests import (GIT_REPO, H' | |||
|
33 | 33 | from rhodecode.tests.vcs_operations import Command |
|
34 | 34 | |
|
35 | 35 | |
|
36 | # override rc_web_server_config fixture with custom INI | |
|
37 | @pytest.fixture(scope='module') | |
|
38 | def rc_web_server_config(testini_factory): | |
|
39 | CUSTOM_PARAMS = [ | |
|
36 | @pytest.fixture(scope="module") | |
|
37 | def rc_web_server_config_modification(): | |
|
38 | return [ | |
|
40 | 39 | {'app:main': {'auth_ret_code': '403'}}, |
|
41 | 40 | {'app:main': {'auth_ret_code_detection': 'true'}}, |
|
42 | 41 | ] |
|
43 | return testini_factory(CUSTOM_PARAMS) | |
|
44 | 42 | |
|
45 | 43 | |
|
46 | 44 | @pytest.mark.usefixtures("disable_locking", "disable_anonymous_user") |
@@ -33,14 +33,12 b' from rhodecode.tests import (GIT_REPO, H' | |||
|
33 | 33 | from rhodecode.tests.vcs_operations import Command |
|
34 | 34 | |
|
35 | 35 | |
|
36 | # override rc_web_server_config fixture with custom INI | |
|
37 | @pytest.fixture(scope='module') | |
|
38 | def rc_web_server_config(testini_factory): | |
|
39 | CUSTOM_PARAMS = [ | |
|
36 | @pytest.fixture(scope="module") | |
|
37 | def rc_web_server_config_modification(): | |
|
38 | return [ | |
|
40 | 39 | {'app:main': {'auth_ret_code': '404'}}, |
|
41 | 40 | {'app:main': {'auth_ret_code_detection': 'false'}}, |
|
42 | 41 | ] |
|
43 | return testini_factory(CUSTOM_PARAMS) | |
|
44 | 42 | |
|
45 | 43 | |
|
46 | 44 | @pytest.mark.usefixtures("disable_locking", "disable_anonymous_user") |
@@ -33,14 +33,12 b' from rhodecode.tests import (GIT_REPO, H' | |||
|
33 | 33 | from rhodecode.tests.vcs_operations import Command |
|
34 | 34 | |
|
35 | 35 | |
|
36 | # override rc_web_server_config fixture with custom INI | |
|
37 | @pytest.fixture(scope='module') | |
|
38 | def rc_web_server_config(testini_factory): | |
|
39 | CUSTOM_PARAMS = [ | |
|
36 | @pytest.fixture(scope="module") | |
|
37 | def rc_web_server_config_modification(): | |
|
38 | return [ | |
|
40 | 39 | {'app:main': {'auth_ret_code': '600'}}, |
|
41 | 40 | {'app:main': {'auth_ret_code_detection': 'false'}}, |
|
42 | 41 | ] |
|
43 | return testini_factory(CUSTOM_PARAMS) | |
|
44 | 42 | |
|
45 | 43 | |
|
46 | 44 | @pytest.mark.usefixtures("disable_locking", "disable_anonymous_user") |
@@ -37,18 +37,6 b' from rhodecode.tests.vcs_operations impo' | |||
|
37 | 37 | from .test_vcs_operations import _check_proper_clone, _check_proper_git_push |
|
38 | 38 | |
|
39 | 39 | |
|
40 | # override rc_web_server_config fixture with custom INI | |
|
41 | @pytest.fixture(scope="module") | |
|
42 | def rc_web_server_config(testini_factory): | |
|
43 | """ | |
|
44 | Configuration file used for the fixture `rc_web_server`. | |
|
45 | """ | |
|
46 | CUSTOM_PARAMS = [ | |
|
47 | {'handler_console': {'level': 'DEBUG'}}, | |
|
48 | ] | |
|
49 | return testini_factory(CUSTOM_PARAMS) | |
|
50 | ||
|
51 | ||
|
52 | 40 | def test_git_clone_with_small_push_buffer(backend_git, rc_web_server, tmpdir): |
|
53 | 41 | clone_url = rc_web_server.repo_clone_url(GIT_REPO) |
|
54 | 42 | cmd = Command('/tmp') |
@@ -41,13 +41,11 b' from rhodecode.tests.vcs_operations impo' | |||
|
41 | 41 | Command, _check_proper_clone, _check_proper_git_push, _add_files_and_push) |
|
42 | 42 | |
|
43 | 43 | |
|
44 | # override rc_web_server_config fixture with custom INI | |
|
45 | @pytest.fixture(scope='module') | |
|
46 | def rc_web_server_config(testini_factory): | |
|
47 | CUSTOM_PARAMS = [ | |
|
44 | @pytest.fixture(scope="module") | |
|
45 | def rc_web_server_config_modification(): | |
|
46 | return [ | |
|
48 | 47 | {'app:main': {'lock_ret_code': '423'}}, |
|
49 | 48 | ] |
|
50 | return testini_factory(CUSTOM_PARAMS) | |
|
51 | 49 | |
|
52 | 50 | |
|
53 | 51 | @pytest.mark.usefixtures("disable_locking", "disable_anonymous_user") |
@@ -40,13 +40,11 b' from rhodecode.tests import (' | |||
|
40 | 40 | from rhodecode.tests.vcs_operations import Command, _add_files_and_push |
|
41 | 41 | |
|
42 | 42 | |
|
43 | # override rc_web_server_config fixture with custom INI | |
|
44 | @pytest.fixture(scope='module') | |
|
45 | def rc_web_server_config(testini_factory): | |
|
46 | CUSTOM_PARAMS = [ | |
|
43 | @pytest.fixture(scope="module") | |
|
44 | def rc_web_server_config_modification(): | |
|
45 | return [ | |
|
47 | 46 | {'app:main': {'lock_ret_code': '400'}}, |
|
48 | 47 | ] |
|
49 | return testini_factory(CUSTOM_PARAMS) | |
|
50 | 48 | |
|
51 | 49 | |
|
52 | 50 | @pytest.mark.usefixtures("disable_locking", "disable_anonymous_user") |
@@ -61,17 +61,17 b' class TestVCSOperationsSpecial(object):' | |||
|
61 | 61 | # Doing an explicit commit in order to get latest user logs on MySQL |
|
62 | 62 | Session().commit() |
|
63 | 63 | |
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 | # | |
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
|
64 | def test_git_fetches_from_remote_repository_with_annotated_tags( | |
|
65 | self, backend_git, rc_web_server): | |
|
66 | # Note: This is a test specific to the git backend. It checks the | |
|
67 | # integration of fetching from a remote repository which contains | |
|
68 | # annotated tags. | |
|
69 | ||
|
70 | # Dulwich shows this specific behavior only when | |
|
71 | # operating against a remote repository. | |
|
72 | source_repo = backend_git['annotated-tag'] | |
|
73 | target_vcs_repo = backend_git.create_repo().scm_instance() | |
|
74 | target_vcs_repo.fetch(rc_web_server.repo_clone_url(source_repo.repo_name)) | |
|
75 | 75 | |
|
76 | 76 | def test_git_push_shows_pull_request_refs(self, backend_git, rc_web_server, tmpdir): |
|
77 | 77 | """ |
@@ -30,14 +30,8 b' Test suite for making push/pull operatio' | |||
|
30 | 30 | import pytest |
|
31 | 31 | import requests |
|
32 | 32 | |
|
33 | from rhodecode import events | |
|
34 | from rhodecode.model.db import Integration | |
|
35 | from rhodecode.model.integration import IntegrationModel | |
|
36 | from rhodecode.model.meta import Session | |
|
37 | ||
|
38 | 33 | from rhodecode.tests import GIT_REPO, HG_REPO |
|
39 | 34 | from rhodecode.tests.vcs_operations import Command, _add_files_and_push |
|
40 | from rhodecode.integrations.types.webhook import WebhookIntegrationType | |
|
41 | 35 | |
|
42 | 36 | |
|
43 | 37 | def check_connection(): |
@@ -54,43 +48,6 b' connection_available = pytest.mark.skipi' | |||
|
54 | 48 | not check_connection(), reason="No outside internet connection available") |
|
55 | 49 | |
|
56 | 50 | |
|
57 | @pytest.fixture | |
|
58 | def enable_webhook_push_integration(request): | |
|
59 | integration = Integration() | |
|
60 | integration.integration_type = WebhookIntegrationType.key | |
|
61 | Session().add(integration) | |
|
62 | ||
|
63 | settings = dict( | |
|
64 | url='http://httpbin.org', | |
|
65 | secret_token='secret', | |
|
66 | username=None, | |
|
67 | password=None, | |
|
68 | custom_header_key=None, | |
|
69 | custom_header_val=None, | |
|
70 | method_type='get', | |
|
71 | events=[events.RepoPushEvent.name], | |
|
72 | log_data=True | |
|
73 | ) | |
|
74 | ||
|
75 | IntegrationModel().update_integration( | |
|
76 | integration, | |
|
77 | name='IntegrationWebhookTest', | |
|
78 | enabled=True, | |
|
79 | settings=settings, | |
|
80 | repo=None, | |
|
81 | repo_group=None, | |
|
82 | child_repos_only=False, | |
|
83 | ) | |
|
84 | Session().commit() | |
|
85 | integration_id = integration.integration_id | |
|
86 | ||
|
87 | @request.addfinalizer | |
|
88 | def cleanup(): | |
|
89 | integration = Integration.get(integration_id) | |
|
90 | Session().delete(integration) | |
|
91 | Session().commit() | |
|
92 | ||
|
93 | ||
|
94 | 51 | @pytest.mark.usefixtures( |
|
95 | 52 | "disable_locking", "disable_anonymous_user", |
|
96 | 53 | "enable_webhook_push_integration") |
General Comments 0
You need to be logged in to leave comments.
Login now