##// END OF EJS Templates
pull-requests: add merge check that detects WIP marker in title. This will prevent merges in such case....
pull-requests: add merge check that detects WIP marker in title. This will prevent merges in such case. Usually WIP in title means unfinished task that needs still some work. This pattern is present in Gitlab/Github and is already quite common.

File last commit:

r3946:39fb0295 default
r4099:c12e69d0 default
Show More
test_server_svn.py
124 lines | 4.5 KiB | text/x-python | PythonLexer
ssh: embedded ssh support...
r2043 # -*- coding: utf-8 -*-
docs: updated copyrights to 2019
r3363 # Copyright (C) 2016-2019 RhodeCode GmbH
ssh: embedded ssh support...
r2043 #
# 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 <http://www.gnu.org/licenses/>.
#
# 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/
ssh-support: enabled full handling of all backends via SSH....
r2187 import mock
ssh: embedded ssh support...
r2043 import pytest
ssh-support: don't use API calls to fetch the data....
r2186 from rhodecode.apps.ssh_support.lib.backends.svn import SubversionServer
dan
tests: fixed some pytest deprecated calls, and warnings.
r3098 from rhodecode.apps.ssh_support.tests.conftest import plain_dummy_env, plain_dummy_user
ssh: embedded ssh support...
r2043
class SubversionServerCreator(object):
root = '/tmp/repo/path/'
svn_path = '/usr/local/bin/svnserve'
config_data = {
'app:main': {
ssh-support: enabled full handling of all backends via SSH....
r2187 'ssh.executable.svn': svn_path,
'vcs.hooks.protocol': 'http',
ssh: embedded ssh support...
r2043 }
}
repo_name = 'test-svn'
dan
tests: fixed some pytest deprecated calls, and warnings.
r3098 user = plain_dummy_user()
ssh: embedded ssh support...
r2043
def __init__(self):
def config_get(part, key):
return self.config_data.get(part, {}).get(key)
ssh-support: enabled full handling of all backends via SSH....
r2187 self.config_mock = mock.Mock()
self.config_mock.get = mock.Mock(side_effect=config_get)
ssh: embedded ssh support...
r2043
def create(self, **kwargs):
parameters = {
ssh-support: enabled full handling of all backends via SSH....
r2187 'store': self.root,
'repo_name': self.repo_name,
ssh: embedded ssh support...
r2043 'ini_path': '',
'user': self.user,
'user_permissions': {
ssh-support: enabled full handling of all backends via SSH....
r2187 self.repo_name: 'repository.admin'
ssh: embedded ssh support...
r2043 },
'config': self.config_mock,
dan
tests: fixed some pytest deprecated calls, and warnings.
r3098 'env': plain_dummy_env()
ssh: embedded ssh support...
r2043 }
ssh-support: enabled full handling of all backends via SSH....
r2187
ssh: embedded ssh support...
r2043 parameters.update(kwargs)
server = SubversionServer(**parameters)
return server
pytest: use consistent way of creating a fixture by using pytest.fixture()
r3946 @pytest.fixture()
ssh-support: enabled full handling of all backends via SSH....
r2187 def svn_server(app):
return SubversionServerCreator()
ssh: embedded ssh support...
r2043 class TestSubversionServer(object):
ssh-support: enabled full handling of all backends via SSH....
r2187 def test_command(self, svn_server):
ssh: embedded ssh support...
r2043 server = svn_server.create()
ssh-support: enabled full handling of all backends via SSH....
r2187 expected_command = [
svn_server.svn_path, '-t', '--config-file',
server.tunnel.svn_conf_path, '-r', svn_server.root
]
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 assert expected_command == server.tunnel.command()
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 @pytest.mark.parametrize('permissions, action, code', [
({}, 'pull', -2),
({'test-svn': 'repository.read'}, 'pull', 0),
({'test-svn': 'repository.read'}, 'push', -2),
({'test-svn': 'repository.write'}, 'push', 0),
({'test-svn': 'repository.admin'}, 'push', 0),
])
def test_permission_checks(self, svn_server, permissions, action, code):
server = svn_server.create(user_permissions=permissions)
result = server._check_permissions(action)
assert result is code
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 def test_run_returns_executes_command(self, svn_server):
ssh: embedded ssh support...
r2043 server = svn_server.create()
ssh-support: enabled full handling of all backends via SSH....
r2187 from rhodecode.apps.ssh_support.lib.backends.svn import SubversionTunnelWrapper
with mock.patch.object(
SubversionTunnelWrapper, 'get_first_client_response',
return_value={'url': 'http://server/test-svn'}):
with mock.patch.object(
SubversionTunnelWrapper, 'patch_first_client_response',
return_value=0):
with mock.patch.object(
SubversionTunnelWrapper, 'sync',
return_value=0):
with mock.patch.object(
SubversionTunnelWrapper, 'command',
svn: fixed tests for svn backend.
r2603 return_value=['date']):
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 exit_code = server.run()
# SVN has this differently configured, and we get in our mock env
# None as return code
assert exit_code == (None, False)
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 def test_run_returns_executes_command_that_cannot_extract_repo_name(self, svn_server):
server = svn_server.create()
from rhodecode.apps.ssh_support.lib.backends.svn import SubversionTunnelWrapper
with mock.patch.object(
SubversionTunnelWrapper, 'command',
svn: fixed tests for svn backend.
r2603 return_value=['date']):
ssh-support: enabled full handling of all backends via SSH....
r2187 with mock.patch.object(
SubversionTunnelWrapper, 'get_first_client_response',
return_value=None):
exit_code = server.run()
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 assert exit_code == (1, False)