##// END OF EJS Templates
chore(tests): mark xfail for test that current we don't know why dont work
chore(tests): mark xfail for test that current we don't know why dont work

File last commit:

r5173:95a4b30f default
r5221:13e09fb1 default
Show More
test_admin_repository_groups.py
179 lines | 6.8 KiB | text/x-python | PythonLexer
/ rhodecode / apps / admin / tests / test_admin_repository_groups.py
repo-groups: moved to pyramid
r2175
copyrights: updated for 2023
r5088 # Copyright (C) 2010-2023 RhodeCode GmbH
repo-groups: moved to pyramid
r2175 #
# 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.apps._base import ADMIN_PREFIX
from rhodecode.lib import helpers as h
repository-groups: use lazy loaded admin dashboard
r3623 from rhodecode.model.db import Repository, UserRepoToPerm, User, RepoGroup
repo-groups: moved to pyramid
r2175 from rhodecode.model.meta import Session
from rhodecode.model.repo_group import RepoGroupModel
from rhodecode.tests import (
repository-groups: use lazy loaded admin dashboard
r3623 assert_session_flash, TEST_USER_REGULAR_LOGIN, TESTS_TMP_PATH)
repo-groups: moved to pyramid
r2175 from rhodecode.tests.fixture import Fixture
tests: refactor code to use a single test url generator
r5173 from rhodecode.tests.routes import route_path
repo-groups: moved to pyramid
r2175
tests: refactor code to use a single test url generator
r5173 fixture = Fixture()
repo-groups: moved to pyramid
r2175
def _get_permission_for_user(user, repo):
perm = UserRepoToPerm.query()\
.filter(UserRepoToPerm.repository ==
Repository.get_by_repo_name(repo))\
.filter(UserRepoToPerm.user == User.get_by_username(user))\
.all()
return perm
@pytest.mark.usefixtures("app")
class TestAdminRepositoryGroups(object):
repository-groups: use lazy loaded admin dashboard
r3623
repo-groups: moved to pyramid
r2175 def test_show_repo_groups(self, autologin_user):
repository-groups: use lazy loaded admin dashboard
r3623 self.app.get(route_path('repo_groups'))
def test_show_repo_groups_data(self, autologin_user, xhr_header):
response = self.app.get(route_path(
'repo_groups_data'), extra_environ=xhr_header)
all_repo_groups = RepoGroup.query().count()
assert response.json['recordsTotal'] == all_repo_groups
repo-groups: moved to pyramid
r2175
repository-groups: use lazy loaded admin dashboard
r3623 def test_show_repo_groups_data_filtered(self, autologin_user, xhr_header):
response = self.app.get(route_path(
'repo_groups_data', params={'search[value]': 'empty_search'}),
extra_environ=xhr_header)
all_repo_groups = RepoGroup.query().count()
assert response.json['recordsTotal'] == all_repo_groups
assert response.json['recordsFiltered'] == 0
def test_show_repo_groups_after_creating_group(self, autologin_user, xhr_header):
repo-groups: moved to pyramid
r2175 fixture.create_repo_group('test_repo_group')
repository-groups: use lazy loaded admin dashboard
r3623 response = self.app.get(route_path(
'repo_groups_data'), extra_environ=xhr_header)
grids: fixed tests and added one for permissions to repository group.
r4151 response.mustcontain('<a href=\\"/{}/_edit\\" title=\\"Edit\\">Edit</a>'.format('test_repo_group'))
repo-groups: moved to pyramid
r2175 fixture.destroy_repo_group('test_repo_group')
def test_new(self, autologin_user):
self.app.get(route_path('repo_group_new'))
def test_new_with_parent_group(self, autologin_user, user_util):
gr = user_util.create_repo_group()
self.app.get(route_path('repo_group_new'),
params=dict(parent_group=gr.group_name))
def test_new_by_regular_user_no_permission(self, autologin_regular_user):
self.app.get(route_path('repo_group_new'), status=403)
@pytest.mark.parametrize('repo_group_name', [
'git_repo',
'git_repo_ąć',
'hg_repo',
'12345',
'hg_repo_ąć',
])
def test_create(self, autologin_user, repo_group_name, csrf_token):
tests: fixed all tests for python3 BIG changes
r5087 repo_group_name_non_ascii = repo_group_name
repo-groups: moved to pyramid
r2175 description = 'description for newly created repo group'
response = self.app.post(
route_path('repo_group_create'),
fixture._get_group_create_params(
group_name=repo_group_name,
group_description=description,
csrf_token=csrf_token))
# run the check page that triggers the flash message
repo_gr_url = h.route_path(
'repo_group_home', repo_group_name=repo_group_name)
assert_session_flash(
response,
'Created repository group <a href="%s">%s</a>' % (
tests: fixed all tests for python3 BIG changes
r5087 repo_gr_url, repo_group_name_non_ascii))
repo-groups: moved to pyramid
r2175
# # test if the repo group was created in the database
new_repo_group = RepoGroupModel()._get_repo_group(
tests: fixed all tests for python3 BIG changes
r5087 repo_group_name_non_ascii)
repo-groups: moved to pyramid
r2175 assert new_repo_group is not None
tests: fixed all tests for python3 BIG changes
r5087 assert new_repo_group.group_name == repo_group_name_non_ascii
repo-groups: moved to pyramid
r2175 assert new_repo_group.group_description == description
# test if the repository is visible in the list ?
response = self.app.get(repo_gr_url)
response.mustcontain(repo_group_name)
# test if the repository group was created on filesystem
is_on_filesystem = os.path.isdir(
os.path.join(TESTS_TMP_PATH, repo_group_name))
if not is_on_filesystem:
self.fail('no repo group %s in filesystem' % repo_group_name)
tests: fixed all tests for python3 BIG changes
r5087 RepoGroupModel().delete(repo_group_name_non_ascii)
repo-groups: moved to pyramid
r2175 Session().commit()
@pytest.mark.parametrize('repo_group_name', [
'git_repo',
'git_repo_ąć',
'hg_repo',
'12345',
'hg_repo_ąć',
])
def test_create_subgroup(self, autologin_user, user_util, repo_group_name, csrf_token):
parent_group = user_util.create_repo_group()
parent_group_name = parent_group.group_name
expected_group_name = '{}/{}'.format(
parent_group_name, repo_group_name)
tests: fixed all tests for python3 BIG changes
r5087 expected_group_name_non_ascii = expected_group_name
repo-groups: moved to pyramid
r2175
try:
response = self.app.post(
route_path('repo_group_create'),
fixture._get_group_create_params(
group_name=repo_group_name,
group_parent_id=parent_group.group_id,
group_description='Test desciption',
csrf_token=csrf_token))
assert_session_flash(
response,
u'Created repository group <a href="%s">%s</a>' % (
h.route_path('repo_group_home',
repo_group_name=expected_group_name),
tests: fixed all tests for python3 BIG changes
r5087 expected_group_name_non_ascii))
repo-groups: moved to pyramid
r2175 finally:
tests: fixed all tests for python3 BIG changes
r5087 RepoGroupModel().delete(expected_group_name_non_ascii)
repo-groups: moved to pyramid
r2175 Session().commit()
def test_user_with_creation_permissions_cannot_create_subgroups(
self, autologin_regular_user, user_util):
user_util.grant_user_permission(
TEST_USER_REGULAR_LOGIN, 'hg.repogroup.create.true')
parent_group = user_util.create_repo_group()
parent_group_id = parent_group.group_id
self.app.get(
route_path('repo_group_new',
params=dict(parent_group=parent_group_id), ),
status=403)