How to use disable_user method in tempest

Best Python code snippet using tempest_python

profile.py

Source:profile.py Github

copy

Full Screen

1from flask import Blueprint, render_template, request, redirect, session, flash , url_for2from flask_wtf import FlaskForm3from capstone.models.request import BuyRequest ,UpgradeRequest4from capstone.models.user import User5from capstone.models.item import Item , Category6from capstone.forms.items import AddCategoryForm7from bson.objectid import ObjectId8from .user import disable_user , login_required , maintenance9profile_bp = Blueprint('profile', __name__)10@profile_bp.route("/" , methods = ['POST' , 'GET'])11@profile_bp.route('/profile', methods=['POST', 'GET'])12@login_required13@maintenance14@disable_user15def profile():16 """This function displays the logged in user's information."""17 user = User.objects(id = session["user"]['id']).first()18 return render_template('profile/profile.html' , user = user)19@profile_bp.route('/display-users', methods=['POST', 'GET'])20@login_required21@maintenance22@disable_user23def display_users():24 """This function sets the "disable" attribute of the user to "True".25 Such user can't access anything on the site (because of the decorator)."""26 27 items = Item.objects()28 seller_user = User.objects(role = 1)29 buyer_user = User.objects(role = 0)30 users = User.objects()31 return render_template('profile/display-users.html' , buyer_user = buyer_user , seller_user = seller_user , users = users , items = items)32@profile_bp.route('/remove_user/<user_id>', methods=['POST', 'GET'])33@login_required34@maintenance35@disable_user36def remove_user(user_id):37 """This function removes the user specified from the database."""38 User.objects(id = user_id).first().delete()39 return redirect(url_for('profile.display_users'))40@profile_bp.route('/disable_user/<user_id>', methods=['POST', 'GET'])41@login_required42@maintenance43@disable_user 44def disable_user_list(user_id) :45 """This function sets the "disable" attribute of the user to "True".46 Such user can't access anything on the site (because of the decorator)."""47 48 user = User.objects(id = user_id).first()49 50 user.disable = True51 user.save()52 return redirect(url_for('profile.display_users'))53@profile_bp.route('/unlock_disable_user/<user_id>', methods=['POST', 'GET'])54@login_required55@maintenance 56@disable_user 57def unlock_disable_user_user_list(user_id) :58 """This function sets the "disable" attribute of the user to "False".59 Such user can now use the site as usual with no restrictions.""" 60 61 user = User.objects(id = user_id).first()62 63 user.disable = False64 user.save()65 flash(f"Account '{user.username}' has been unlocked.!")66 return redirect(url_for('profile.display_users'))67@profile_bp.route('/profile/maintenance', methods=['POST', 'GET'])68@maintenance 69@maintenance70@disable_user 71def maintenance_mode() :72 """This function sets the "maintenance" attribute of all users to "True".73 All users will see the Maintenance Page when trying to access any page on the site."""74 User.objects(role = 0 and 1).update(maintenance = True) 75 76 return redirect(url_for('profile.profile'))77@profile_bp.route('/profile/remove_maintenance_mode', methods=['POST', 'GET'])78@login_required79@maintenance80@disable_user 81def remove_maintenance_mode() :82 """This function sets the "maintenance" attribute of all users to "False".83 All users will be able to access any page on the site normally."""84 85 User.objects(role = 0 and 1).update(maintenance = False) 86 87 return redirect(url_for('profile.profile'))88@profile_bp.route('/user/favorite_list', methods=['GET', 'POST'])89@login_required90@maintenance91@disable_user92def view_favorite():93 """This function lets the Buyer user see their favorited items."""94 favorite_items = User.objects(id = session['user']['id']).get().favorites95 96 items = []97 for i in range(0 ,len(favorite_items)):98 item = Item.objects(id = favorite_items[i]).first()99 items.append(item)100 print(items)101 102 103 return render_template("profile/user-favorite.html" , items = items)104@profile_bp.route('/disable_users_list', methods=['POST', 'GET'])105@login_required106@maintenance 107@disable_user108def disabled_list():109 """This function can be accessed by the Admin user to view which users they have locked(disable)."""110 users = User.objects(disable = True)111 return render_template('profile/blocked-list.html' , users = users, title = "Blocked-List" , icon = 'fas fa-users')112 113@profile_bp.route('/buy_request_list/<user_id>', methods=['POST', 'GET'])114@login_required115@maintenance116@disable_user 117def buy_request_list(user_id):118 """This function is accessed by the Buyer user to view their Buy Requests and their status."""119 list_request = BuyRequest.objects(user = session['user']['id'])120 return render_template('profile/buy-request-list.html' , list_request = list_request)121@profile_bp.route('/request_upgrade', methods=['GET', 'POST'])122@login_required123@maintenance 124@disable_user125def request_upgrade():126 """This function is available for the Admin user to preview Upgrade Requests to choose to Approve or Decline."""127 request = UpgradeRequest.objects(user = session['user']['id']).first()128 if not request:129 upgrade_request = UpgradeRequest(user = session['user']['id'], status = "Pending")130 upgrade_request.save()131 else:132 flash("You have already requested an upgrade.")133 return redirect(url_for('profile.profile'))134@profile_bp.route('/add_category', methods=['GET', 'POST'])135@login_required136@maintenance137@disable_user138def add_category():139 """This function is accessed by the Admin only, it lets them add a new category for items.140 The changes made here can be viewed when a Seller user chooses a category when adding a new item."""141 add_category_form = AddCategoryForm()142 if add_category_form.validate_on_submit():143 category_value = add_category_form.value.data144 category_label = add_category_form.label.data145 new_category = Category( value = category_value, label = category_label)146 new_category.save()147 148 flash('New Category has been added.!')149 return redirect(url_for("profile.profile"))...

Full Screen

Full Screen

admin.py

Source:admin.py Github

copy

Full Screen

...22 """ 用户名脱敏处理 """23 return obj.username[0:3] + '***'24 # 修改脱敏后的列名显示25 format_username.short_description = '用户名'26 def disable_user(self, request, queryset):27 """ 批量禁用选中的用户 """28 queryset.update(is_active=False)29 disable_user.short_description = '批量禁用用户'30 def enable_user(self, request, queryset):31 """ 批量禁用选中的用户 """32 queryset.update(is_active=True)33 enable_user.short_description = '批量启用用户'34# admin.site.register(User, UserAdmin)35@admin.register(UserProfile)36class UserProfile(admin.ModelAdmin):37 """ 用户详细信息 """38 list_display = ('user', 'phone_no', 'sex')39@admin.register(UserAddress)40class UserAddressAdmin(admin.ModelAdmin):...

Full Screen

Full Screen

test_aws_iam_account_inactive_90_days.py

Source:test_aws_iam_account_inactive_90_days.py Github

copy

Full Screen

1# pylint: disable-all2import os3from datetime import datetime4import time5from unittest import TestCase6from json import loads7from jsonpath_ng import parse8class TestAWSIAMAccountInactive90Days(TestCase):9 def setUp(self):10 fp = open(os.getcwd() + "/test/data/test_aws_resources.json", "r")11 content = fp.read()12 fp.close()13 self.resources = loads(content)14 self.days_threshold = 9015 def test_if_password_is_not_used_from_90_days(self):16 """17 Check if user password is not used from 90 days18 """19 iams_criteria = 'serviceAccount[*].self.source_data'20 iams = [match.value for match in parse(iams_criteria)\21 .find(self.resources)]22 disable_user = False23 for iam in iams:24 if not iam["PasswordEnable"]:25 continue26 last_used = iam.get("PasswordLastUsed")27 if last_used is None:28 last_used = iam.get("CreateDate")29 dt = datetime.strptime(last_used.replace(' GMT','Z'),"%a, %d %b %Y %H:%M:%S%z")30 diff = time.time() - datetime.timestamp(dt)31 days = diff/(60*60*24)32 if days>=self.days_threshold:33 disable_user = True34 self.assertEqual(False, disable_user, msg=f"some of the user password\35 is not used from last {self.days_threshold} days")36 def test_if_access_key_is_not_used_from_90_days(self):37 """38 Check if access key is not used from 90 days39 """40 keys_criteria = 'serviceAccount[*].self.source_data.AccessKeys[*]'41 keys = [match.value for match in parse(keys_criteria)\42 .find(self.resources)]43 disable_user = False44 for key in keys:45 if key["Status"]!="Active":46 continue47 last_used = key.get("AccessKeyLastUsed")48 if last_used is None:49 last_used = key.get("CreateDate")50 dt = datetime.strptime(last_used.replace(' GMT','Z'),"%a, %d %b %Y %H:%M:%S%z")51 diff = time.time() - datetime.timestamp(dt)52 days = diff/(60*60*24)53 if days>=self.days_threshold:54 disable_user = True55 self.assertEqual(False, disable_user, msg=f"Some of the user key\56 is not used from last {self.days_threshold} days")...

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