Show More
@@ -26,7 +26,7 b' from rhodecode.tests import TEST_USER_AD' | |||
|
26 | 26 | from rhodecode.api.tests.utils import ( |
|
27 | 27 | build_data, api_call, assert_error, assert_ok, crash, jsonify) |
|
28 | 28 | from rhodecode.tests.fixture import Fixture |
|
29 |
from rhodecode.tests.plugin import |
|
|
29 | from rhodecode.tests.plugin import plain_http_host_only_stub | |
|
30 | 30 | |
|
31 | 31 | fixture = Fixture() |
|
32 | 32 | |
@@ -80,7 +80,7 b' class TestApiUpdateRepo(object):' | |||
|
80 | 80 | ({'repo_name': 'new_repo_name'}, |
|
81 | 81 | { |
|
82 | 82 | 'repo_name': 'new_repo_name', |
|
83 | 'url': 'http://{}/new_repo_name'.format(http_host_only_stub()) | |
|
83 | 'url': 'http://{}/new_repo_name'.format(plain_http_host_only_stub()) | |
|
84 | 84 | }), |
|
85 | 85 | |
|
86 | 86 | ({'repo_name': 'test_group_for_update/{}'.format(UPDATE_REPO_NAME), |
@@ -88,7 +88,7 b' class TestApiUpdateRepo(object):' | |||
|
88 | 88 | { |
|
89 | 89 | 'repo_name': 'test_group_for_update/{}'.format(UPDATE_REPO_NAME), |
|
90 | 90 | 'url': 'http://{}/test_group_for_update/{}'.format( |
|
91 | http_host_only_stub(), UPDATE_REPO_NAME) | |
|
91 | plain_http_host_only_stub(), UPDATE_REPO_NAME) | |
|
92 | 92 | }), |
|
93 | 93 | ]) |
|
94 | 94 | def test_api_update_repo(self, updates, expected, backend): |
@@ -41,8 +41,7 b' def dummy_conf_file(tmpdir):' | |||
|
41 | 41 | return os.path.join(f_path) |
|
42 | 42 | |
|
43 | 43 | |
|
44 | @pytest.fixture | |
|
45 | def dummy_env(): | |
|
44 | def plain_dummy_env(): | |
|
46 | 45 | return { |
|
47 | 46 | 'request': |
|
48 | 47 | AttributeDict(host_url='http://localhost', script_name='/') |
@@ -50,8 +49,17 b' def dummy_env():' | |||
|
50 | 49 | |
|
51 | 50 | |
|
52 | 51 | @pytest.fixture |
|
52 | def dummy_env(): | |
|
53 | return plain_dummy_env() | |
|
54 | ||
|
55 | ||
|
56 | def plain_dummy_user(): | |
|
57 | return AttributeDict(username='test_user') | |
|
58 | ||
|
59 | ||
|
60 | @pytest.fixture | |
|
53 | 61 | def dummy_user(): |
|
54 | return AttributeDict(username='test_user') | |
|
62 | return plain_dummy_user() | |
|
55 | 63 | |
|
56 | 64 | |
|
57 | 65 | @pytest.fixture |
@@ -23,7 +23,7 b' import mock' | |||
|
23 | 23 | import pytest |
|
24 | 24 | |
|
25 | 25 | from rhodecode.apps.ssh_support.lib.backends.git import GitServer |
|
26 | from rhodecode.apps.ssh_support.tests.conftest import dummy_env, dummy_user | |
|
26 | from rhodecode.apps.ssh_support.tests.conftest import plain_dummy_env, plain_dummy_user | |
|
27 | 27 | |
|
28 | 28 | |
|
29 | 29 | class GitServerCreator(object): |
@@ -37,7 +37,7 b' class GitServerCreator(object):' | |||
|
37 | 37 | } |
|
38 | 38 | repo_name = 'test_git' |
|
39 | 39 | repo_mode = 'receive-pack' |
|
40 | user = dummy_user() | |
|
40 | user = plain_dummy_user() | |
|
41 | 41 | |
|
42 | 42 | def __init__(self): |
|
43 | 43 | def config_get(part, key): |
@@ -56,7 +56,7 b' class GitServerCreator(object):' | |||
|
56 | 56 | self.repo_name: 'repository.admin' |
|
57 | 57 | }, |
|
58 | 58 | 'config': self.config_mock, |
|
59 | 'env': dummy_env() | |
|
59 | 'env': plain_dummy_env() | |
|
60 | 60 | } |
|
61 | 61 | parameters.update(kwargs) |
|
62 | 62 | server = GitServer(**parameters) |
@@ -22,7 +22,7 b' import mock' | |||
|
22 | 22 | import pytest |
|
23 | 23 | |
|
24 | 24 | from rhodecode.apps.ssh_support.lib.backends.hg import MercurialServer |
|
25 | from rhodecode.apps.ssh_support.tests.conftest import dummy_env, dummy_user | |
|
25 | from rhodecode.apps.ssh_support.tests.conftest import plain_dummy_env, plain_dummy_user | |
|
26 | 26 | |
|
27 | 27 | |
|
28 | 28 | class MercurialServerCreator(object): |
@@ -36,7 +36,7 b' class MercurialServerCreator(object):' | |||
|
36 | 36 | } |
|
37 | 37 | } |
|
38 | 38 | repo_name = 'test_hg' |
|
39 | user = dummy_user() | |
|
39 | user = plain_dummy_user() | |
|
40 | 40 | |
|
41 | 41 | def __init__(self): |
|
42 | 42 | def config_get(part, key): |
@@ -54,7 +54,7 b' class MercurialServerCreator(object):' | |||
|
54 | 54 | 'test_hg': 'repository.admin' |
|
55 | 55 | }, |
|
56 | 56 | 'config': self.config_mock, |
|
57 | 'env': dummy_env() | |
|
57 | 'env': plain_dummy_env() | |
|
58 | 58 | } |
|
59 | 59 | parameters.update(kwargs) |
|
60 | 60 | server = MercurialServer(**parameters) |
@@ -22,7 +22,7 b' import mock' | |||
|
22 | 22 | import pytest |
|
23 | 23 | |
|
24 | 24 | from rhodecode.apps.ssh_support.lib.backends.svn import SubversionServer |
|
25 | from rhodecode.apps.ssh_support.tests.conftest import dummy_env, dummy_user | |
|
25 | from rhodecode.apps.ssh_support.tests.conftest import plain_dummy_env, plain_dummy_user | |
|
26 | 26 | |
|
27 | 27 | |
|
28 | 28 | class SubversionServerCreator(object): |
@@ -35,7 +35,7 b' class SubversionServerCreator(object):' | |||
|
35 | 35 | } |
|
36 | 36 | } |
|
37 | 37 | repo_name = 'test-svn' |
|
38 | user = dummy_user() | |
|
38 | user = plain_dummy_user() | |
|
39 | 39 | |
|
40 | 40 | def __init__(self): |
|
41 | 41 | def config_get(part, key): |
@@ -53,7 +53,7 b' class SubversionServerCreator(object):' | |||
|
53 | 53 | self.repo_name: 'repository.admin' |
|
54 | 54 | }, |
|
55 | 55 | 'config': self.config_mock, |
|
56 | 'env': dummy_env() | |
|
56 | 'env': plain_dummy_env() | |
|
57 | 57 | } |
|
58 | 58 | |
|
59 | 59 | parameters.update(kwargs) |
@@ -236,7 +236,7 b' def no_newline_id_generator(test_name):' | |||
|
236 | 236 | nicer output of progress of test |
|
237 | 237 | """ |
|
238 | 238 | org_name = test_name |
|
239 | test_name = str(test_name)\ | |
|
239 | test_name = safe_str(test_name)\ | |
|
240 | 240 | .replace('\n', '_N') \ |
|
241 | 241 | .replace('\r', '_N') \ |
|
242 | 242 | .replace('\t', '_T') \ |
@@ -34,7 +34,7 b' def _get_dbs_from_metafunc(metafunc):' | |||
|
34 | 34 | if hasattr(metafunc.function, 'dbs'): |
|
35 | 35 | # Supported backends by this test function, created from |
|
36 | 36 | # pytest.mark.dbs |
|
37 |
backends = metafunc. |
|
|
37 | backends = metafunc.definition.get_closest_marker('dbs').args | |
|
38 | 38 | else: |
|
39 | 39 | backends = metafunc.config.getoption('--dbs') |
|
40 | 40 | return backends |
@@ -139,7 +139,7 b' def get_backends_from_metafunc(metafunc)' | |||
|
139 | 139 | if hasattr(metafunc.function, 'backends'): |
|
140 | 140 | # Supported backends by this test function, created from |
|
141 | 141 | # pytest.mark.backends |
|
142 |
backends = metafunc. |
|
|
142 | backends = metafunc.definition.get_closest_marker('backends').args | |
|
143 | 143 | elif hasattr(metafunc.cls, 'backend_alias'): |
|
144 | 144 | # Support class attribute "backend_alias", this is mainly |
|
145 | 145 | # for legacy reasons for tests not yet using pytest.mark.backends |
@@ -182,8 +182,14 b' def http_environ_session():' | |||
|
182 | 182 | """ |
|
183 | 183 | Allow to use "http_environ" in session scope. |
|
184 | 184 | """ |
|
185 | return http_environ( | |
|
186 | http_host_stub=http_host_stub()) | |
|
185 | return plain_http_environ() | |
|
186 | ||
|
187 | ||
|
188 | def plain_http_host_stub(): | |
|
189 | """ | |
|
190 | Value of HTTP_HOST in the test run. | |
|
191 | """ | |
|
192 | return 'example.com:80' | |
|
187 | 193 | |
|
188 | 194 | |
|
189 | 195 | @pytest.fixture |
@@ -191,7 +197,14 b' def http_host_stub():' | |||
|
191 | 197 | """ |
|
192 | 198 | Value of HTTP_HOST in the test run. |
|
193 | 199 | """ |
|
194 | return 'example.com:80' | |
|
200 | return plain_http_host_stub() | |
|
201 | ||
|
202 | ||
|
203 | def plain_http_host_only_stub(): | |
|
204 | """ | |
|
205 | Value of HTTP_HOST in the test run. | |
|
206 | """ | |
|
207 | return plain_http_host_stub().split(':')[0] | |
|
195 | 208 | |
|
196 | 209 | |
|
197 | 210 | @pytest.fixture |
@@ -199,11 +212,10 b' def http_host_only_stub():' | |||
|
199 | 212 | """ |
|
200 | 213 | Value of HTTP_HOST in the test run. |
|
201 | 214 | """ |
|
202 |
return http_host_stub() |
|
|
215 | return plain_http_host_only_stub() | |
|
203 | 216 | |
|
204 | 217 | |
|
205 | @pytest.fixture | |
|
206 | def http_environ(http_host_stub): | |
|
218 | def plain_http_environ(): | |
|
207 | 219 | """ |
|
208 | 220 | HTTP extra environ keys. |
|
209 | 221 | |
@@ -212,14 +224,26 b' def http_environ(http_host_stub):' | |||
|
212 | 224 | to override this for a specific test case. |
|
213 | 225 | """ |
|
214 | 226 | return { |
|
215 | 'SERVER_NAME': http_host_only_stub(), | |
|
216 | 'SERVER_PORT': http_host_stub.split(':')[1], | |
|
217 | 'HTTP_HOST': http_host_stub, | |
|
227 | 'SERVER_NAME': plain_http_host_only_stub(), | |
|
228 | 'SERVER_PORT': plain_http_host_stub().split(':')[1], | |
|
229 | 'HTTP_HOST': plain_http_host_stub(), | |
|
218 | 230 | 'HTTP_USER_AGENT': 'rc-test-agent', |
|
219 | 231 | 'REQUEST_METHOD': 'GET' |
|
220 | 232 | } |
|
221 | 233 | |
|
222 | 234 | |
|
235 | @pytest.fixture | |
|
236 | def http_environ(): | |
|
237 | """ | |
|
238 | HTTP extra environ keys. | |
|
239 | ||
|
240 | User by the test application and as well for setting up the pylons | |
|
241 | environment. In the case of the fixture "app" it should be possible | |
|
242 | to override this for a specific test case. | |
|
243 | """ | |
|
244 | return plain_http_environ() | |
|
245 | ||
|
246 | ||
|
223 | 247 | @pytest.fixture(scope='session') |
|
224 | 248 | def baseapp(ini_config, vcsserver, http_environ_session): |
|
225 | 249 | from rhodecode.lib.pyramid_utils import get_app_config |
@@ -423,18 +447,7 b' class TestRepoContainer(object):' | |||
|
423 | 447 | self._fixture.destroy_repo(repo_name) |
|
424 | 448 | |
|
425 | 449 | |
|
426 | @pytest.fixture | |
|
427 | def backend(request, backend_alias, baseapp, test_repo): | |
|
428 | """ | |
|
429 | Parametrized fixture which represents a single backend implementation. | |
|
430 | ||
|
431 | It respects the option `--backends` to focus the test run on specific | |
|
432 | backend implementations. | |
|
433 | ||
|
434 | It also supports `pytest.mark.xfail_backends` to mark tests as failing | |
|
435 | for specific backends. This is intended as a utility for incremental | |
|
436 | development of a new backend implementation. | |
|
437 | """ | |
|
450 | def backend_base(request, backend_alias, baseapp, test_repo): | |
|
438 | 451 | if backend_alias not in request.config.getoption('--backends'): |
|
439 | 452 | pytest.skip("Backend %s not selected." % (backend_alias, )) |
|
440 | 453 | |
@@ -452,18 +465,33 b' def backend(request, backend_alias, base' | |||
|
452 | 465 | |
|
453 | 466 | |
|
454 | 467 | @pytest.fixture |
|
468 | def backend(request, backend_alias, baseapp, test_repo): | |
|
469 | """ | |
|
470 | Parametrized fixture which represents a single backend implementation. | |
|
471 | ||
|
472 | It respects the option `--backends` to focus the test run on specific | |
|
473 | backend implementations. | |
|
474 | ||
|
475 | It also supports `pytest.mark.xfail_backends` to mark tests as failing | |
|
476 | for specific backends. This is intended as a utility for incremental | |
|
477 | development of a new backend implementation. | |
|
478 | """ | |
|
479 | return backend_base(request, backend_alias, baseapp, test_repo) | |
|
480 | ||
|
481 | ||
|
482 | @pytest.fixture | |
|
455 | 483 | def backend_git(request, baseapp, test_repo): |
|
456 | return backend(request, 'git', baseapp, test_repo) | |
|
484 | return backend_base(request, 'git', baseapp, test_repo) | |
|
457 | 485 | |
|
458 | 486 | |
|
459 | 487 | @pytest.fixture |
|
460 | 488 | def backend_hg(request, baseapp, test_repo): |
|
461 | return backend(request, 'hg', baseapp, test_repo) | |
|
489 | return backend_base(request, 'hg', baseapp, test_repo) | |
|
462 | 490 | |
|
463 | 491 | |
|
464 | 492 | @pytest.fixture |
|
465 | 493 | def backend_svn(request, baseapp, test_repo): |
|
466 | return backend(request, 'svn', baseapp, test_repo) | |
|
494 | return backend_base(request, 'svn', baseapp, test_repo) | |
|
467 | 495 | |
|
468 | 496 | |
|
469 | 497 | @pytest.fixture |
@@ -675,17 +703,7 b' class Backend(object):' | |||
|
675 | 703 | repo.set_refs(ref_name, refs[ref_name]) |
|
676 | 704 | |
|
677 | 705 | |
|
678 | @pytest.fixture | |
|
679 | def vcsbackend(request, backend_alias, tests_tmp_path, baseapp, test_repo): | |
|
680 | """ | |
|
681 | Parametrized fixture which represents a single vcs backend implementation. | |
|
682 | ||
|
683 | See the fixture `backend` for more details. This one implements the same | |
|
684 | concept, but on vcs level. So it does not provide model instances etc. | |
|
685 | ||
|
686 | Parameters are generated dynamically, see :func:`pytest_generate_tests` | |
|
687 | for how this works. | |
|
688 | """ | |
|
706 | def vcsbackend_base(request, backend_alias, tests_tmp_path, baseapp, test_repo): | |
|
689 | 707 | if backend_alias not in request.config.getoption('--backends'): |
|
690 | 708 | pytest.skip("Backend %s not selected." % (backend_alias, )) |
|
691 | 709 | |
@@ -704,31 +722,32 b' def vcsbackend(request, backend_alias, t' | |||
|
704 | 722 | |
|
705 | 723 | |
|
706 | 724 | @pytest.fixture |
|
725 | def vcsbackend(request, backend_alias, tests_tmp_path, baseapp, test_repo): | |
|
726 | """ | |
|
727 | Parametrized fixture which represents a single vcs backend implementation. | |
|
728 | ||
|
729 | See the fixture `backend` for more details. This one implements the same | |
|
730 | concept, but on vcs level. So it does not provide model instances etc. | |
|
731 | ||
|
732 | Parameters are generated dynamically, see :func:`pytest_generate_tests` | |
|
733 | for how this works. | |
|
734 | """ | |
|
735 | return vcsbackend_base(request, backend_alias, tests_tmp_path, baseapp, test_repo) | |
|
736 | ||
|
737 | ||
|
738 | @pytest.fixture | |
|
707 | 739 | def vcsbackend_git(request, tests_tmp_path, baseapp, test_repo): |
|
708 | return vcsbackend(request, 'git', tests_tmp_path, baseapp, test_repo) | |
|
740 | return vcsbackend_base(request, 'git', tests_tmp_path, baseapp, test_repo) | |
|
709 | 741 | |
|
710 | 742 | |
|
711 | 743 | @pytest.fixture |
|
712 | 744 | def vcsbackend_hg(request, tests_tmp_path, baseapp, test_repo): |
|
713 | return vcsbackend(request, 'hg', tests_tmp_path, baseapp, test_repo) | |
|
745 | return vcsbackend_base(request, 'hg', tests_tmp_path, baseapp, test_repo) | |
|
714 | 746 | |
|
715 | 747 | |
|
716 | 748 | @pytest.fixture |
|
717 | 749 | def vcsbackend_svn(request, tests_tmp_path, baseapp, test_repo): |
|
718 | return vcsbackend(request, 'svn', tests_tmp_path, baseapp, test_repo) | |
|
719 | ||
|
720 | ||
|
721 | @pytest.fixture | |
|
722 | def vcsbackend_random(vcsbackend_git): | |
|
723 | """ | |
|
724 | Use this to express that your tests need "a vcsbackend". | |
|
725 | ||
|
726 | The fixture `vcsbackend` would run the test multiple times for each | |
|
727 | available vcs backend which is a pure waste of time if the test is | |
|
728 | independent of the vcs backend type. | |
|
729 | """ | |
|
730 | # TODO: johbo: Change this to pick a random backend | |
|
731 | return vcsbackend_git | |
|
750 | return vcsbackend_base(request, 'svn', tests_tmp_path, baseapp, test_repo) | |
|
732 | 751 | |
|
733 | 752 | |
|
734 | 753 | @pytest.fixture |
@@ -156,7 +156,7 b' def set_anonymous_access(enabled):' | |||
|
156 | 156 | def check_xfail_backends(node, backend_alias): |
|
157 | 157 | # Using "xfail_backends" here intentionally, since this marks work |
|
158 | 158 | # which is "to be done" soon. |
|
159 | skip_marker = node.get_marker('xfail_backends') | |
|
159 | skip_marker = node.get_closest_marker('xfail_backends') | |
|
160 | 160 | if skip_marker and backend_alias in skip_marker.args: |
|
161 | 161 | msg = "Support for backend %s to be developed." % (backend_alias, ) |
|
162 | 162 | msg = skip_marker.kwargs.get('reason', msg) |
@@ -166,7 +166,7 b' def check_xfail_backends(node, backend_a' | |||
|
166 | 166 | def check_skip_backends(node, backend_alias): |
|
167 | 167 | # Using "skip_backends" here intentionally, since this marks work which is |
|
168 | 168 | # not supported. |
|
169 | skip_marker = node.get_marker('skip_backends') | |
|
169 | skip_marker = node.get_closest_marker('skip_backends') | |
|
170 | 170 | if skip_marker and backend_alias in skip_marker.args: |
|
171 | 171 | msg = "Feature not supported for backend %s." % (backend_alias, ) |
|
172 | 172 | msg = skip_marker.kwargs.get('reason', msg) |
General Comments 0
You need to be logged in to leave comments.
Login now