##// END OF EJS Templates
files: handle long paths in nicer UI.
files: handle long paths in nicer UI.

File last commit:

r3098:97c1a8b7 default
r3136:7a1508b5 default
Show More
test_server_hg.py
116 lines | 3.9 KiB | text/x-python | PythonLexer
ssh: embedded ssh support...
r2043 # -*- coding: utf-8 -*-
release: update copyright year to 2018
r2487 # Copyright (C) 2016-2018 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.hg import MercurialServer
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 MercurialServerCreator(object):
root = '/tmp/repo/path/'
hg_path = '/usr/local/bin/hg'
config_data = {
'app:main': {
ssh-support: enabled full handling of all backends via SSH....
r2187 'ssh.executable.hg': hg_path,
'vcs.hooks.protocol': 'http',
ssh: embedded ssh support...
r2043 }
}
repo_name = 'test_hg'
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,
ssh: embedded ssh support...
r2043 'ini_path': '',
'user': self.user,
'repo_name': self.repo_name,
'user_permissions': {
ssh-support: enabled full handling of all backends via SSH....
r2187 'test_hg': '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 }
parameters.update(kwargs)
server = MercurialServer(**parameters)
return server
ssh-support: enabled full handling of all backends via SSH....
r2187 @pytest.fixture
def hg_server(app):
return MercurialServerCreator()
ssh: embedded ssh support...
r2043 class TestMercurialServer(object):
ssh-support: enabled full handling of all backends via SSH....
r2187
def test_command(self, hg_server):
ssh: embedded ssh support...
r2043 server = hg_server.create()
expected_command = (
ssh-support: enabled full handling of all backends via SSH....
r2187 'cd {root}; {hg_path} -R {root}{repo_name} serve --stdio'.format(
ssh: embedded ssh support...
r2043 root=hg_server.root, hg_path=hg_server.hg_path,
repo_name=hg_server.repo_name)
)
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_hg': 'repository.read'}, 'pull', 0),
({'test_hg': 'repository.read'}, 'push', -2),
({'test_hg': 'repository.write'}, 'push', 0),
({'test_hg': 'repository.admin'}, 'push', 0),
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 ])
def test_permission_checks(self, hg_server, permissions, action, code):
server = hg_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 @pytest.mark.parametrize('permissions, value', [
({}, False),
({'test_hg': 'repository.read'}, False),
({'test_hg': 'repository.write'}, True),
({'test_hg': 'repository.admin'}, True),
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 ])
def test_has_write_permissions(self, hg_server, permissions, value):
server = hg_server.create(user_permissions=permissions)
result = server.has_write_perm()
assert result is value
ssh: embedded ssh support...
r2043
ssh-support: enabled full handling of all backends via SSH....
r2187 def test_run_returns_executes_command(self, hg_server):
ssh: embedded ssh support...
r2043 server = hg_server.create()
ssh-support: enabled full handling of all backends via SSH....
r2187 from rhodecode.apps.ssh_support.lib.backends.hg import MercurialTunnelWrapper
with mock.patch.object(MercurialTunnelWrapper, 'create_hooks_env') as _patch:
_patch.return_value = 0
with mock.patch.object(MercurialTunnelWrapper, 'command', return_value='date'):
ssh: embedded ssh support...
r2043 exit_code = server.run()
assert exit_code == (0, False)
ssh-support: enabled full handling of all backends via SSH....
r2187