How to use validate_role method in tempest

Best Python code snippet using tempest_python

roles.py

Source:roles.py Github

copy

Full Screen

...48 else:49 validated['invalid'].add(role['role'])50 return validated51def get_roles(role, key, database):52 return validate_role(role[key], database) if key in role else result_default_value()53def get_builtin_role(role, database):54 result = result_default_value()55 is_valid_role = valid_role(role['role'])56 if is_valid_role and role['isBuiltin']:57 result['valid'].add(role['role'])58 elif is_valid_role:59 result['custom'].add(role['role'])60 else:61 result['invalid'].add(role['role'])62 inherited = get_roles(role, 'inherited', database)63 other_roles = get_roles(role, 'roles', database)64 return combine_result(result, combine_result(inherited, other_roles))65def validate_role_dict(role, database):66 if 'role' in role:67 return get_builtin_role(role, database) if 'isBuiltin' in role else \68 validate_role(database.command('rolesInfo', role)['roles'], database)69 if 'roles' in role and bool(role['roles']):70 return validate_role(role['roles'], database)71 else:72 raise Exception('Non exhaustive type case')73def validate_role(role, database):74 """75 Recursively process the different roles that a role implements or inherits76 Args:77 role (list or dict): value returned by database.command 'usersInfo' or 'rolesInfo'78 """79 if isinstance(role, list):80 return reduce(lambda x, y: combine_result(x, y), [validate_role(r, database) for r in role]) \81 if bool(role) else result_default_value()82 elif isinstance(role, dict):83 return validate_role_dict(role, database)84 else:85 raise Exception('Non exhaustive type case')86def get_message(validated, state, text1, text2):87 return text1 + decode_to_string(validated[state]) + text288def validation_result(validated):89 if bool(validated['invalid']):90 # if the profile is invalid91 return TestResult(success=False, message=decode_to_string(validated['invalid']))92 elif bool(validated['custom']):93 # if the profile has custom permissions94 message = get_message(validated, 'valid', 'Your user\'s role set ',95 ' seems to be ok, but we couldn\'t do an exhaustive check.')96 return TestResult(success=True, severity=WARNING, message=message)97 # if everything seems to be ok98 return TestResult(success=True, message=decode_to_string(validated['valid']))99def try_roles(test):100 """101 Verify that the user roles are not administrative102 Returns:103 [bool or 2 , str ]: True Valid role, False invalid role, 2 custome role ,104 """105 database = test.tester.get_db()106 roles = test.tester.get_roles()107 try:108 validated = validate_role(roles, database)109 except pymongo.errors.OperationFailure:110 # if the users doesn't have permission to run the command 'rolesInfo'111 validated = basic_validation(roles)112 if bool(validated['valid']):113 message = get_message(validated, 'valid', 'You user permission ',114 ' didn\'t allow us to do an exhaustive check')115 return TestResult(success=True, severity=WARNING, message=message)...

Full Screen

Full Screen

role.py

Source:role.py Github

copy

Full Screen

...3import cogctl4import cogctl.api5from cogctl.cli import table6from cogctl.cli.permission import parse_permission_name7def validate_role(context, param, value):8 """9 Validates existance of role. Fetches the role by name, returning it10 if it exists; otherwise throws BadParameter11 """12 role = context.obj.api.role_by_name(value)13 if role:14 return role15 else:16 raise click.BadParameter("\"%s\" was not found" % value)17def validate_new_role_name(context, param, value):18 "Validates uniqueness of new role name"19 roles = context.obj.api.roles()20 if any(r for r in roles if r["name"] == value):21 error = "Role with name \"%s\" already exists" % value...

Full Screen

Full Screen

export_routes.py

Source:export_routes.py Github

copy

Full Screen

...10from app.services.ValidationUtil import validate_role11@bp.route('/export_solutions_csv')12@login_required13def export_solutions_csv():14 validate_role(current_user, User.Roles['TEACHER'])15 solutions = Solution.query.filter(Solution.id.in_(request.args.getlist('ids'))).all()16 export = get_csv_solution_export(solutions, current_user)17 return redirect(url_for('teacher.download', domain='export', id=export.id))18@bp.route('/export_statistics_csv')19@login_required20def export_statistics_csv():21 validate_role(current_user, User.Roles['TEACHER'])22 export = get_csv_statistics_export(request.args.getlist('statistics_info'), current_user)23 return redirect(url_for('teacher.download', domain='export', id=export.id))24@bp.route('/export_solutions_pdf')25@login_required26def export_solutions_pdf():27 validate_role(current_user, User.Roles['TEACHER'])28 solutions = Solution.query.filter(Solution.id.in_(request.args.getlist('ids'))).all()29 export = get_pdf_solution_export(solutions, current_user)30 return redirect(url_for('teacher.download', domain='export', id=export.id))31@bp.route('/export_statistics_pdf')32@login_required33def export_statistics_pdf():34 validate_role(current_user, User.Roles['TEACHER'])35 export = get_pdf_statistics_export(request.args.getlist('statistics_info'), current_user)36 return redirect(url_for('teacher.download', domain='export', id=export.id))37@bp.route('/view_exports')38@login_required39def view_exports():40 validate_role(current_user, User.Roles['TEACHER'])41 exports = sorted(current_user.exports, key=lambda export: export.id, reverse=True)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful