##// END OF EJS Templates
build(deps): removed infrae.cache dependency as it's no longer used
build(deps): removed infrae.cache dependency as it's no longer used

File last commit:

r5173:95a4b30f default
r5230:2785eb92 default
Show More
test_admin_user_groups.py
152 lines | 5.3 KiB | text/x-python | PythonLexer
/ rhodecode / apps / admin / tests / test_admin_user_groups.py
user-groups: moved the display of user group into a pyramid view
r1980
copyrights: updated for 2023
r5088 # Copyright (C) 2010-2023 RhodeCode GmbH
user-groups: moved the display of user group into a pyramid view
r1980 #
# 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 pytest
from rhodecode.model.db import UserGroup, User
from rhodecode.model.meta import Session
from rhodecode.tests import (
tests: refactor code to use a single test url generator
r5173 TestController, assert_session_flash)
user-groups: moved the display of user group into a pyramid view
r1980 from rhodecode.tests.fixture import Fixture
tests: refactor code to use a single test url generator
r5173 from rhodecode.tests.routes import route_path
user-groups: moved the display of user group into a pyramid view
r1980
fixture = Fixture()
class TestAdminUserGroupsView(TestController):
def test_show_users(self):
self.log_user()
self.app.get(route_path('user_groups'))
def test_show_user_groups_data(self, xhr_header):
self.log_user()
response = self.app.get(route_path(
'user_groups_data'), extra_environ=xhr_header)
all_user_groups = UserGroup.query().count()
assert response.json['recordsTotal'] == all_user_groups
def test_show_user_groups_data_filtered(self, xhr_header):
self.log_user()
response = self.app.get(route_path(
'user_groups_data', params={'search[value]': 'empty_search'}),
extra_environ=xhr_header)
all_user_groups = UserGroup.query().count()
assert response.json['recordsTotal'] == all_user_groups
assert response.json['recordsFiltered'] == 0
def test_usergroup_escape(self, user_util, xhr_header):
self.log_user()
xss_img = '<img src="/image1" onload="alert(\'Hello, World!\');">'
user = user_util.create_user()
user.name = xss_img
user.lastname = xss_img
Session().add(user)
Session().commit()
user_group = user_util.create_user_group()
user_group.users_group_name = xss_img
user_group.user_group_description = '<strong onload="alert();">DESC</strong>'
response = self.app.get(
route_path('user_groups_data'), extra_environ=xhr_header)
response.mustcontain(
'&lt;strong onload=&#34;alert();&#34;&gt;DESC&lt;/strong&gt;')
response.mustcontain(
'&lt;img src=&#34;/image1&#34; onload=&#34;'
'alert(&#39;Hello, World!&#39;);&#34;&gt;')
def test_edit_user_group_autocomplete_empty_members(self, xhr_header, user_util):
self.log_user()
ug = user_util.create_user_group()
response = self.app.get(
route_path('user_group_members_data', user_group_id=ug.users_group_id),
extra_environ=xhr_header)
assert response.json == {'members': []}
def test_edit_user_group_autocomplete_members(self, xhr_header, user_util):
self.log_user()
members = [u.user_id for u in User.get_all()]
ug = user_util.create_user_group(members=members)
response = self.app.get(
user-groups: rewrote the app to pyramid...
r2068 route_path('user_group_members_data',
user_group_id=ug.users_group_id),
user-groups: moved the display of user group into a pyramid view
r1980 extra_environ=xhr_header)
assert len(response.json['members']) == len(members)
user-groups: rewrote the app to pyramid...
r2068
def test_creation_page(self):
self.log_user()
self.app.get(route_path('user_groups_new'), status=200)
def test_create(self):
from rhodecode.lib import helpers as h
self.log_user()
users_group_name = 'test_user_group'
response = self.app.post(route_path('user_groups_create'), {
'users_group_name': users_group_name,
'user_group_description': 'DESC',
'active': True,
'csrf_token': self.csrf_token})
user_group_id = UserGroup.get_by_group_name(
users_group_name).users_group_id
user_group_link = h.link_to(
users_group_name,
route_path('edit_user_group', user_group_id=user_group_id))
assert_session_flash(
response,
'Created user group %s' % user_group_link)
fixture.destroy_user_group(users_group_name)
def test_create_with_empty_name(self):
self.log_user()
response = self.app.post(route_path('user_groups_create'), {
'users_group_name': '',
'user_group_description': 'DESC',
'active': True,
'csrf_token': self.csrf_token}, status=200)
response.mustcontain('Please enter a value')
def test_create_duplicate(self, user_util):
self.log_user()
user_group = user_util.create_user_group()
duplicate_name = user_group.users_group_name
response = self.app.post(route_path('user_groups_create'), {
'users_group_name': duplicate_name,
'user_group_description': 'DESC',
'active': True,
'csrf_token': self.csrf_token}, status=200)
response.mustcontain(
tests: made few tests handle database transactions better.
r2786 'User group `{}` already exists'.format(duplicate_name))