tests: fixed some pytest deprecated calls, and warnings.
This commit is contained in:
parent
5e3a70e588
commit
1db967ddb0
9 changed files with 99 additions and 72 deletions
|
|
@ -26,7 +26,7 @@ from rhodecode.tests import TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN
|
|||
from rhodecode.api.tests.utils import (
|
||||
build_data, api_call, assert_error, assert_ok, crash, jsonify)
|
||||
from rhodecode.tests.fixture import Fixture
|
||||
from rhodecode.tests.plugin import http_host_stub, http_host_only_stub
|
||||
from rhodecode.tests.plugin import plain_http_host_only_stub
|
||||
|
||||
fixture = Fixture()
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ class TestApiUpdateRepo(object):
|
|||
({'repo_name': 'new_repo_name'},
|
||||
{
|
||||
'repo_name': 'new_repo_name',
|
||||
'url': 'http://{}/new_repo_name'.format(http_host_only_stub())
|
||||
'url': 'http://{}/new_repo_name'.format(plain_http_host_only_stub())
|
||||
}),
|
||||
|
||||
({'repo_name': 'test_group_for_update/{}'.format(UPDATE_REPO_NAME),
|
||||
|
|
@ -88,7 +88,7 @@ class TestApiUpdateRepo(object):
|
|||
{
|
||||
'repo_name': 'test_group_for_update/{}'.format(UPDATE_REPO_NAME),
|
||||
'url': 'http://{}/test_group_for_update/{}'.format(
|
||||
http_host_only_stub(), UPDATE_REPO_NAME)
|
||||
plain_http_host_only_stub(), UPDATE_REPO_NAME)
|
||||
}),
|
||||
])
|
||||
def test_api_update_repo(self, updates, expected, backend):
|
||||
|
|
|
|||
|
|
@ -41,8 +41,7 @@ def dummy_conf_file(tmpdir):
|
|||
return os.path.join(f_path)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dummy_env():
|
||||
def plain_dummy_env():
|
||||
return {
|
||||
'request':
|
||||
AttributeDict(host_url='http://localhost', script_name='/')
|
||||
|
|
@ -50,10 +49,19 @@ def dummy_env():
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def dummy_user():
|
||||
def dummy_env():
|
||||
return plain_dummy_env()
|
||||
|
||||
|
||||
def plain_dummy_user():
|
||||
return AttributeDict(username='test_user')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dummy_user():
|
||||
return plain_dummy_user()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ssh_wrapper(app, dummy_conf_file, dummy_env):
|
||||
conn_info = '127.0.0.1 22 10.0.0.1 443'
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import mock
|
|||
import pytest
|
||||
|
||||
from rhodecode.apps.ssh_support.lib.backends.git import GitServer
|
||||
from rhodecode.apps.ssh_support.tests.conftest import dummy_env, dummy_user
|
||||
from rhodecode.apps.ssh_support.tests.conftest import plain_dummy_env, plain_dummy_user
|
||||
|
||||
|
||||
class GitServerCreator(object):
|
||||
|
|
@ -37,7 +37,7 @@ class GitServerCreator(object):
|
|||
}
|
||||
repo_name = 'test_git'
|
||||
repo_mode = 'receive-pack'
|
||||
user = dummy_user()
|
||||
user = plain_dummy_user()
|
||||
|
||||
def __init__(self):
|
||||
def config_get(part, key):
|
||||
|
|
@ -56,7 +56,7 @@ class GitServerCreator(object):
|
|||
self.repo_name: 'repository.admin'
|
||||
},
|
||||
'config': self.config_mock,
|
||||
'env': dummy_env()
|
||||
'env': plain_dummy_env()
|
||||
}
|
||||
parameters.update(kwargs)
|
||||
server = GitServer(**parameters)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import mock
|
|||
import pytest
|
||||
|
||||
from rhodecode.apps.ssh_support.lib.backends.hg import MercurialServer
|
||||
from rhodecode.apps.ssh_support.tests.conftest import dummy_env, dummy_user
|
||||
from rhodecode.apps.ssh_support.tests.conftest import plain_dummy_env, plain_dummy_user
|
||||
|
||||
|
||||
class MercurialServerCreator(object):
|
||||
|
|
@ -36,7 +36,7 @@ class MercurialServerCreator(object):
|
|||
}
|
||||
}
|
||||
repo_name = 'test_hg'
|
||||
user = dummy_user()
|
||||
user = plain_dummy_user()
|
||||
|
||||
def __init__(self):
|
||||
def config_get(part, key):
|
||||
|
|
@ -54,7 +54,7 @@ class MercurialServerCreator(object):
|
|||
'test_hg': 'repository.admin'
|
||||
},
|
||||
'config': self.config_mock,
|
||||
'env': dummy_env()
|
||||
'env': plain_dummy_env()
|
||||
}
|
||||
parameters.update(kwargs)
|
||||
server = MercurialServer(**parameters)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import mock
|
|||
import pytest
|
||||
|
||||
from rhodecode.apps.ssh_support.lib.backends.svn import SubversionServer
|
||||
from rhodecode.apps.ssh_support.tests.conftest import dummy_env, dummy_user
|
||||
from rhodecode.apps.ssh_support.tests.conftest import plain_dummy_env, plain_dummy_user
|
||||
|
||||
|
||||
class SubversionServerCreator(object):
|
||||
|
|
@ -35,7 +35,7 @@ class SubversionServerCreator(object):
|
|||
}
|
||||
}
|
||||
repo_name = 'test-svn'
|
||||
user = dummy_user()
|
||||
user = plain_dummy_user()
|
||||
|
||||
def __init__(self):
|
||||
def config_get(part, key):
|
||||
|
|
@ -53,7 +53,7 @@ class SubversionServerCreator(object):
|
|||
self.repo_name: 'repository.admin'
|
||||
},
|
||||
'config': self.config_mock,
|
||||
'env': dummy_env()
|
||||
'env': plain_dummy_env()
|
||||
}
|
||||
|
||||
parameters.update(kwargs)
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ def no_newline_id_generator(test_name):
|
|||
nicer output of progress of test
|
||||
"""
|
||||
org_name = test_name
|
||||
test_name = str(test_name)\
|
||||
test_name = safe_str(test_name)\
|
||||
.replace('\n', '_N') \
|
||||
.replace('\r', '_N') \
|
||||
.replace('\t', '_T') \
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ def _get_dbs_from_metafunc(metafunc):
|
|||
if hasattr(metafunc.function, 'dbs'):
|
||||
# Supported backends by this test function, created from
|
||||
# pytest.mark.dbs
|
||||
backends = metafunc.function.dbs.args
|
||||
backends = metafunc.definition.get_closest_marker('dbs').args
|
||||
else:
|
||||
backends = metafunc.config.getoption('--dbs')
|
||||
return backends
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ def get_backends_from_metafunc(metafunc):
|
|||
if hasattr(metafunc.function, 'backends'):
|
||||
# Supported backends by this test function, created from
|
||||
# pytest.mark.backends
|
||||
backends = metafunc.function.backends.args
|
||||
backends = metafunc.definition.get_closest_marker('backends').args
|
||||
elif hasattr(metafunc.cls, 'backend_alias'):
|
||||
# Support class attribute "backend_alias", this is mainly
|
||||
# for legacy reasons for tests not yet using pytest.mark.backends
|
||||
|
|
@ -182,28 +182,40 @@ def http_environ_session():
|
|||
"""
|
||||
Allow to use "http_environ" in session scope.
|
||||
"""
|
||||
return http_environ(
|
||||
http_host_stub=http_host_stub())
|
||||
return plain_http_environ()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def http_host_stub():
|
||||
def plain_http_host_stub():
|
||||
"""
|
||||
Value of HTTP_HOST in the test run.
|
||||
"""
|
||||
return 'example.com:80'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def http_host_stub():
|
||||
"""
|
||||
Value of HTTP_HOST in the test run.
|
||||
"""
|
||||
return plain_http_host_stub()
|
||||
|
||||
|
||||
def plain_http_host_only_stub():
|
||||
"""
|
||||
Value of HTTP_HOST in the test run.
|
||||
"""
|
||||
return plain_http_host_stub().split(':')[0]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def http_host_only_stub():
|
||||
"""
|
||||
Value of HTTP_HOST in the test run.
|
||||
"""
|
||||
return http_host_stub().split(':')[0]
|
||||
return plain_http_host_only_stub()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def http_environ(http_host_stub):
|
||||
def plain_http_environ():
|
||||
"""
|
||||
HTTP extra environ keys.
|
||||
|
||||
|
|
@ -212,14 +224,26 @@ def http_environ(http_host_stub):
|
|||
to override this for a specific test case.
|
||||
"""
|
||||
return {
|
||||
'SERVER_NAME': http_host_only_stub(),
|
||||
'SERVER_PORT': http_host_stub.split(':')[1],
|
||||
'HTTP_HOST': http_host_stub,
|
||||
'SERVER_NAME': plain_http_host_only_stub(),
|
||||
'SERVER_PORT': plain_http_host_stub().split(':')[1],
|
||||
'HTTP_HOST': plain_http_host_stub(),
|
||||
'HTTP_USER_AGENT': 'rc-test-agent',
|
||||
'REQUEST_METHOD': 'GET'
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def http_environ():
|
||||
"""
|
||||
HTTP extra environ keys.
|
||||
|
||||
User by the test application and as well for setting up the pylons
|
||||
environment. In the case of the fixture "app" it should be possible
|
||||
to override this for a specific test case.
|
||||
"""
|
||||
return plain_http_environ()
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def baseapp(ini_config, vcsserver, http_environ_session):
|
||||
from rhodecode.lib.pyramid_utils import get_app_config
|
||||
|
|
@ -423,18 +447,7 @@ class TestRepoContainer(object):
|
|||
self._fixture.destroy_repo(repo_name)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def backend(request, backend_alias, baseapp, test_repo):
|
||||
"""
|
||||
Parametrized fixture which represents a single backend implementation.
|
||||
|
||||
It respects the option `--backends` to focus the test run on specific
|
||||
backend implementations.
|
||||
|
||||
It also supports `pytest.mark.xfail_backends` to mark tests as failing
|
||||
for specific backends. This is intended as a utility for incremental
|
||||
development of a new backend implementation.
|
||||
"""
|
||||
def backend_base(request, backend_alias, baseapp, test_repo):
|
||||
if backend_alias not in request.config.getoption('--backends'):
|
||||
pytest.skip("Backend %s not selected." % (backend_alias, ))
|
||||
|
||||
|
|
@ -451,19 +464,34 @@ def backend(request, backend_alias, baseapp, test_repo):
|
|||
return backend
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def backend(request, backend_alias, baseapp, test_repo):
|
||||
"""
|
||||
Parametrized fixture which represents a single backend implementation.
|
||||
|
||||
It respects the option `--backends` to focus the test run on specific
|
||||
backend implementations.
|
||||
|
||||
It also supports `pytest.mark.xfail_backends` to mark tests as failing
|
||||
for specific backends. This is intended as a utility for incremental
|
||||
development of a new backend implementation.
|
||||
"""
|
||||
return backend_base(request, backend_alias, baseapp, test_repo)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def backend_git(request, baseapp, test_repo):
|
||||
return backend(request, 'git', baseapp, test_repo)
|
||||
return backend_base(request, 'git', baseapp, test_repo)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def backend_hg(request, baseapp, test_repo):
|
||||
return backend(request, 'hg', baseapp, test_repo)
|
||||
return backend_base(request, 'hg', baseapp, test_repo)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def backend_svn(request, baseapp, test_repo):
|
||||
return backend(request, 'svn', baseapp, test_repo)
|
||||
return backend_base(request, 'svn', baseapp, test_repo)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -675,17 +703,7 @@ class Backend(object):
|
|||
repo.set_refs(ref_name, refs[ref_name])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def vcsbackend(request, backend_alias, tests_tmp_path, baseapp, test_repo):
|
||||
"""
|
||||
Parametrized fixture which represents a single vcs backend implementation.
|
||||
|
||||
See the fixture `backend` for more details. This one implements the same
|
||||
concept, but on vcs level. So it does not provide model instances etc.
|
||||
|
||||
Parameters are generated dynamically, see :func:`pytest_generate_tests`
|
||||
for how this works.
|
||||
"""
|
||||
def vcsbackend_base(request, backend_alias, tests_tmp_path, baseapp, test_repo):
|
||||
if backend_alias not in request.config.getoption('--backends'):
|
||||
pytest.skip("Backend %s not selected." % (backend_alias, ))
|
||||
|
||||
|
|
@ -703,32 +721,33 @@ def vcsbackend(request, backend_alias, tests_tmp_path, baseapp, test_repo):
|
|||
return backend
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def vcsbackend(request, backend_alias, tests_tmp_path, baseapp, test_repo):
|
||||
"""
|
||||
Parametrized fixture which represents a single vcs backend implementation.
|
||||
|
||||
See the fixture `backend` for more details. This one implements the same
|
||||
concept, but on vcs level. So it does not provide model instances etc.
|
||||
|
||||
Parameters are generated dynamically, see :func:`pytest_generate_tests`
|
||||
for how this works.
|
||||
"""
|
||||
return vcsbackend_base(request, backend_alias, tests_tmp_path, baseapp, test_repo)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def vcsbackend_git(request, tests_tmp_path, baseapp, test_repo):
|
||||
return vcsbackend(request, 'git', tests_tmp_path, baseapp, test_repo)
|
||||
return vcsbackend_base(request, 'git', tests_tmp_path, baseapp, test_repo)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def vcsbackend_hg(request, tests_tmp_path, baseapp, test_repo):
|
||||
return vcsbackend(request, 'hg', tests_tmp_path, baseapp, test_repo)
|
||||
return vcsbackend_base(request, 'hg', tests_tmp_path, baseapp, test_repo)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def vcsbackend_svn(request, tests_tmp_path, baseapp, test_repo):
|
||||
return vcsbackend(request, 'svn', tests_tmp_path, baseapp, test_repo)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def vcsbackend_random(vcsbackend_git):
|
||||
"""
|
||||
Use this to express that your tests need "a vcsbackend".
|
||||
|
||||
The fixture `vcsbackend` would run the test multiple times for each
|
||||
available vcs backend which is a pure waste of time if the test is
|
||||
independent of the vcs backend type.
|
||||
"""
|
||||
# TODO: johbo: Change this to pick a random backend
|
||||
return vcsbackend_git
|
||||
return vcsbackend_base(request, 'svn', tests_tmp_path, baseapp, test_repo)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ def set_anonymous_access(enabled):
|
|||
def check_xfail_backends(node, backend_alias):
|
||||
# Using "xfail_backends" here intentionally, since this marks work
|
||||
# which is "to be done" soon.
|
||||
skip_marker = node.get_marker('xfail_backends')
|
||||
skip_marker = node.get_closest_marker('xfail_backends')
|
||||
if skip_marker and backend_alias in skip_marker.args:
|
||||
msg = "Support for backend %s to be developed." % (backend_alias, )
|
||||
msg = skip_marker.kwargs.get('reason', msg)
|
||||
|
|
@ -166,7 +166,7 @@ def check_xfail_backends(node, backend_alias):
|
|||
def check_skip_backends(node, backend_alias):
|
||||
# Using "skip_backends" here intentionally, since this marks work which is
|
||||
# not supported.
|
||||
skip_marker = node.get_marker('skip_backends')
|
||||
skip_marker = node.get_closest_marker('skip_backends')
|
||||
if skip_marker and backend_alias in skip_marker.args:
|
||||
msg = "Feature not supported for backend %s." % (backend_alias, )
|
||||
msg = skip_marker.kwargs.get('reason', msg)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue