##// END OF EJS Templates
ip-restritions: fix issue with loading empty IP rules for non-logged not-anonymous users....
ip-restritions: fix issue with loading empty IP rules for non-logged not-anonymous users. This case won't have any IP rules set. And we accidentally loaded them becuase of no empty user filter was present. This caused some odd display warnings for users.

File last commit:

r2487:fcee5614 default
r2838:d1dcf373 default
Show More
test_update_repo_group.py
150 lines | 6.2 KiB | text/x-python | PythonLexer
/ rhodecode / api / tests / test_update_repo_group.py
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
release: update copyright year to 2018
r2487 # Copyright (C) 2010-2018 RhodeCode GmbH
project: added all source files and assets
r1 #
# 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/
import os
import pytest
from rhodecode.model.repo_group import RepoGroupModel
from rhodecode.model.user import UserModel
from rhodecode.api.tests.utils import (
build_data, api_call, assert_error, assert_ok)
@pytest.mark.usefixtures("testuser_api", "app")
class TestApiUpdateRepoGroup(object):
repo-group-schemas: refactor repository group schemas....
r1154
project: added all source files and assets
r1 def test_update_group_name(self, user_util):
new_group_name = 'new-group'
initial_name = self._update(user_util, group_name=new_group_name)
assert RepoGroupModel()._get_repo_group(initial_name) is None
repo-group-schemas: refactor repository group schemas....
r1154 new_group = RepoGroupModel()._get_repo_group(new_group_name)
assert new_group is not None
assert new_group.full_path == new_group_name
project: added all source files and assets
r1
repo-group-schemas: refactor repository group schemas....
r1154 def test_update_group_name_change_parent(self, user_util):
project: added all source files and assets
r1 parent_group = user_util.create_repo_group()
repo-group-schemas: refactor repository group schemas....
r1154 parent_group_name = parent_group.name
project: added all source files and assets
r1
repo-group-schemas: refactor repository group schemas....
r1154 expected_group_name = '{}/{}'.format(parent_group_name, 'new-group')
initial_name = self._update(user_util, group_name=expected_group_name)
project: added all source files and assets
r1 repo_group = RepoGroupModel()._get_repo_group(expected_group_name)
repo-group-schemas: refactor repository group schemas....
r1154
project: added all source files and assets
r1 assert repo_group is not None
assert repo_group.group_name == expected_group_name
repo-group-schemas: refactor repository group schemas....
r1154 assert repo_group.full_path == expected_group_name
project: added all source files and assets
r1 assert RepoGroupModel()._get_repo_group(initial_name) is None
repo-group-schemas: refactor repository group schemas....
r1154
project: added all source files and assets
r1 new_path = os.path.join(
RepoGroupModel().repos_path, *repo_group.full_path_splitted)
assert os.path.exists(new_path)
def test_update_enable_locking(self, user_util):
initial_name = self._update(user_util, enable_locking=True)
repo_group = RepoGroupModel()._get_repo_group(initial_name)
assert repo_group.enable_locking is True
def test_update_description(self, user_util):
description = 'New description'
initial_name = self._update(user_util, description=description)
repo_group = RepoGroupModel()._get_repo_group(initial_name)
assert repo_group.group_description == description
def test_update_owner(self, user_util):
owner = self.TEST_USER_LOGIN
initial_name = self._update(user_util, owner=owner)
repo_group = RepoGroupModel()._get_repo_group(initial_name)
assert repo_group.user.username == owner
repo-group-schemas: refactor repository group schemas....
r1154 def test_update_group_name_conflict_with_existing(self, user_util):
group_1 = user_util.create_repo_group()
group_2 = user_util.create_repo_group()
repo_group_name_1 = group_1.group_name
repo_group_name_2 = group_2.group_name
project: added all source files and assets
r1
id_, params = build_data(
repo-group-schemas: refactor repository group schemas....
r1154 self.apikey, 'update_repo_group', repogroupid=repo_group_name_1,
group_name=repo_group_name_2)
response = api_call(self.app, params)
expected = {
'unique_repo_group_name':
'Repository group with name `{}` already exists'.format(
repo_group_name_2)}
assert_error(id_, expected, given=response.body)
def test_api_update_repo_group_by_regular_user_no_permission(self, user_util):
temp_user = user_util.create_user()
temp_user_api_key = temp_user.api_key
parent_group = user_util.create_repo_group()
repo_group_name = parent_group.group_name
id_, params = build_data(
temp_user_api_key, 'update_repo_group', repogroupid=repo_group_name)
project: added all source files and assets
r1 response = api_call(self.app, params)
repo-group-schemas: refactor repository group schemas....
r1154 expected = 'repository group `%s` does not exist' % (repo_group_name,)
assert_error(id_, expected, given=response.body)
def test_api_update_repo_group_regular_user_no_root_write_permissions(
self, user_util):
temp_user = user_util.create_user()
temp_user_api_key = temp_user.api_key
parent_group = user_util.create_repo_group(owner=temp_user.username)
repo_group_name = parent_group.group_name
id_, params = build_data(
temp_user_api_key, 'update_repo_group', repogroupid=repo_group_name,
group_name='at-root-level')
response = api_call(self.app, params)
expected = {
'repo_group': 'You do not have the permission to store '
'repository groups in the root location.'}
project: added all source files and assets
r1 assert_error(id_, expected, given=response.body)
def _update(self, user_util, **kwargs):
repo_group = user_util.create_repo_group()
initial_name = repo_group.name
user = UserModel().get_by_username(self.TEST_USER_LOGIN)
user_util.grant_user_permission_to_repo_group(
repo_group, user, 'group.admin')
id_, params = build_data(
self.apikey, 'update_repo_group', repogroupid=initial_name,
**kwargs)
response = api_call(self.app, params)
repo-group-schemas: refactor repository group schemas....
r1154
repo_group = RepoGroupModel.cls.get(repo_group.group_id)
expected = {
project: added all source files and assets
r1 'msg': 'updated repository group ID:{} {}'.format(
repo_group.group_id, repo_group.group_name),
'repo_group': {
'repositories': [],
'group_name': repo_group.group_name,
'group_description': repo_group.group_description,
'owner': repo_group.user.username,
'group_id': repo_group.group_id,
'parent_group': (
repo_group.parent_group.name
if repo_group.parent_group else None)
}
}
repo-group-schemas: refactor repository group schemas....
r1154 assert_ok(id_, expected, given=response.body)
project: added all source files and assets
r1 return initial_name