Best Python code snippet using tempest_python
tenant_data.py
Source:tenant_data.py
1from OpenAPI.Data.source_data.source_tenant_data import *2from OpenAPI.Lib.get_data_list import *3from OpenAPI.Lib.run_case import *4from OpenAPI.Data.init_data.init_tenant import *5# æ·»å ç§å®¢6empty_file('add_tenant_cmd')7add_tenant_class = GetDataList(right_add_tenant, wrong_add_tenant, [], add_tenant, 'post')8add_tenant_cmd = add_tenant_class.get_all_http_cmd([0],9 [14001, 14001, 14001, 14001, 14001, 15004, 14001, 14001, 14001, 14001, 14001, 14001, 14001, 17007, 14001, 14001,10 17007])11add_tenant_cmd.append([add_tenant, add_tenant + '-openapi-S-ä¼ å
¥uuidï¼ä¸ä¼ room_id', 'post',12 {'uuid': lock_uuid, 'tenant_name': get_string(3), 'tenant_phone': '18566260535', 'start_time': now_ms, 'end_time': after_ms}, 0, 0])13add_tenant_cmd.append([add_tenant, add_tenant + '-openapi-S-ä¼ å
¥uuidï¼ä¼ å
¥room_id', 'post',14 {'room_id': room_1001, 'uuid': lock_uuid, 'tenant_name': get_string(3), 'tenant_phone': '18566260535', 'start_time': now_ms,15 'end_time': after_ms}, 0, 0])16add_tenant_cmd.append([add_tenant, add_tenant + '-openapi-S-ä¼ å
¥é误uuidï¼æ£ç¡®room_id', 'post',17 {'room_id': room_1001, 'uuid': get_string(10), 'tenant_name': get_string(3), 'tenant_phone': '18566260535', 'start_time': now_ms,18 'end_time': after_ms}, 0, 0])19add_tenant_cmd.append([add_tenant, add_tenant + '-openapi-F-ä¼ å
¥uuidï¼ä¼ å
¥é误room_id', 'post',20 {'room_id': get_string(10), 'uuid': lock_uuid, 'tenant_name': get_string(3), 'tenant_phone': '18566260535', 'start_time': now_ms,21 'end_time': after_ms}, 15004, 0])22# write_print_list_dic(add_tenant_cmd)23# æ´æ°ç§å®¢24empty_file('update_tenant_cmd')25update_tenant_class = GetDataList(right_update_tenant, wrong_update_tenant, [], update_tenant, 'post')26update_tenant_cmd = update_tenant_class.get_all_http_cmd([0, 0, 0, 0, 0, 14001], [14001, 15904, 15004, 14001, 14001, 14001, 14001, 17007, 14001, 17007, 14001])27update_tenant_cmd.append([update_tenant, update_tenant + '-openapi-S-æ´æ°ç§å®¢ååï¼å·ç åå¨', 'post',28 {'room_id': room_1001, 'tenant_name': 'xxtt', 'tenant_phone': '18512124545'}, 0, 0])29update_tenant_cmd.append([update_tenant, update_tenant + '-openapi-S-æ´æ°ç§å®¢ææºå·ï¼å·ç åå¨', 'post',30 {'room_id': room_1001, 'tenant_name': 'test', 'tenant_phone': '18076488260'}, 0, 0])31update_tenant_cmd.append([update_tenant, update_tenant + '-openapi-S-æ´æ°ç§çº¦æ¶é´ï¼å·ç åå¨', 'post',32 {'room_id': room_1001, 'tenant_name': 'xxtt', 'tenant_phone': '18566260535', 'start_time': now_ms,33 'end_time': now_ms + 30 * 24 * 3600 * 1000}, 0, 0])34update_tenant_cmd.append([update_tenant, update_tenant + '-openapi-S-æ´æ°ç§å®¢åç§çº¦ï¼å·ç ä¸åå¨', 'post',35 {'room_id': room_1001, 'tenant_name': 'xxttyr', 'tenant_phone': '18567675654'}, 0, 0])36update_tenant_cmd.append([update_tenant, update_tenant + '-openapi-S-åªä¼ uuidï¼ä¸ä¼ room_id', 'post',37 {'uuid': lock_uuid, 'tenant_name': get_string(3), 'tenant_phone': '18566260535'}, 0, 0])38update_tenant_cmd.append([update_tenant, update_tenant + '-openapi-S-ä¼ å
¥uuidï¼ä¼ å
¥room_id', 'post',39 {'uuid': lock_uuid, 'room_id': room_1001, 'tenant_name': get_string(3), 'tenant_phone': '18566260535'}, 0, 0])40update_tenant_cmd.append([update_tenant, update_tenant + '-openapi-S-ä¼ é误uuidï¼ä¼ æ£ç¡®room_id', 'post',41 {'uuid': get_string(10), 'room_id': room_1001, 'tenant_name': get_string(3), 'tenant_phone': '18566260535'}, 0, 0])42update_tenant_cmd.append([update_tenant, update_tenant + '-openapi-F-ä¼ é误room_idï¼ä¼ æ£ç¡®uuid', 'post',43 {'uuid': lock_uuid, 'room_id': get_string(10), 'tenant_name': get_string(3), 'tenant_phone': '18566260535'}, 15004, 0])44# write_print_list_dic(update_tenant_cmd)45# æ ¹æ®æ¿æºidè·åç§å®¢å表46empty_file('list_tenants_by_homeid_cmd')47list_tenants_by_homeid_class = GetDataList(right_list_tenants_by_homeid, wrong_list_tenants_by_homeid, [], list_tenants_by_homeid, 'get')48list_tenants_by_homeid_cmd = list_tenants_by_homeid_class.get_all_http_cmd([0], [14001, 15006, 15006, 14001])49# write_print_list_dic(list_tenants_by_homeid_cmd)50# æ ¹æ®room_idè·åç§å®¢ä¿¡æ¯51empty_file('get_tenant_by_roomid_cmd')52get_tenant_by_roomid_class = GetDataList(right_get_tenant_by_roomid, wrong_get_tenant_by_roomid, [], get_tenant_by_roomid, 'get')53get_tenant_by_roomid_cmd = get_tenant_by_roomid_class.get_all_http_cmd([0], [14001, 15004, 15004, 14001])54# write_print_list_dic(get_tenant_by_roomid_cmd)55# å é¤ç§å®¢56empty_file('delete_tenant_cmd')57delete_tenant_class = GetDataList(right_delete_tenant, wrong_delete_tenant, [], delete_tenant, 'post')58delete_tenant_cmd = delete_tenant_class.get_all_http_cmd([0], [14001, 15904, 15004, 14001, 14001])...
tenant_update.py
Source:tenant_update.py
1from rest_framework.views import APIView2from core.models.users import User3from core.models.tenant import Tenant4from core.helpers import api_response5from job.models.job_applications import JobApplication6from job.models.job_status import JobStatus7from resume.models.work import Work8from resume.models.certificate import Certification9from resume.models.education import Education10from resume.models.achievement import Achievement11from job.models.jobs import Job12from resume.models.profile import Profile13from resume.models.skill import Skills14from core.models.profile_setting import ProfileSetting15from core.models.partner_setting import PartnerSetting16class TenantUpdate(APIView):17 def post(self, request):18 source_tenant = request.data.get("source_tenant")19 update_tenant = request.data.get("update_tenant")20 user_data = User.objects.filter(tenant_id=source_tenant).values("tenant_id", "id")21 for user_id in user_data:22 tenant_data = Tenant.objects.get(id=update_tenant)23 user_update = User.objects.filter(id=user_id["id"]).update(tenant_id=tenant_data)24 application_data = JobApplication.objects.filter(tenant_id=source_tenant).values("tenant_id", "id")25 for user_id in application_data:26 tenant_data = Tenant.objects.get(id=update_tenant)27 application = JobApplication.objects.filter(id=user_id["id"]).update(tenant_id=tenant_data)28 application_data_npp = JobApplication.objects.filter(job_tenant=source_tenant).values("job_tenant", "id")29 for user_id in application_data_npp:30 tenant_data = Tenant.objects.get(id=update_tenant)31 application = JobApplication.objects.filter(id=user_id["id"]).update(job_tenant=tenant_data.id)32 status_data_npp = JobStatus.objects.filter(job_tenant=source_tenant).values("job_tenant", "id")33 for user_id in status_data_npp:34 tenant_data = Tenant.objects.get(id=update_tenant)35 status = JobStatus.objects.filter(id=user_id["id"]).update(job_tenant=tenant_data.id)36 status_data = JobStatus.objects.filter(tenant_id=source_tenant).values("tenant_id", "id")37 for user_id in status_data:38 tenant_data = Tenant.objects.get(id=update_tenant)39 status = JobStatus.objects.filter(id=user_id["id"]).update(tenant_id=tenant_data)40 job_data = Job.objects.filter(tenant_id=source_tenant).values("tenant_id", "id")41 for user_id in job_data:42 tenant_data = Tenant.objects.get(id=update_tenant)43 detail = Job.objects.filter(id=user_id["id"]).update(tenant_id=tenant_data)44 profile_data = Profile.objects.filter(tenant_id=source_tenant).values("tenant_id", "id")45 for user_id in profile_data:46 tenant_data = Tenant.objects.get(id=update_tenant)47 detail = Profile.objects.filter(id=user_id["id"]).update(tenant_id=tenant_data)48 work_data = Work.objects.filter(tenant_id=source_tenant).values("tenant_id", "id")49 for user_id in work_data:50 tenant_data = Tenant.objects.get(id=update_tenant)51 detail = Work.objects.filter(id=user_id["id"]).update(tenant_id=tenant_data)52 certification_data = Certification.objects.filter(tenant_id=source_tenant).values("tenant_id", "id")53 for user_id in certification_data:54 tenant_data = Tenant.objects.get(id=update_tenant)55 detail = Certification.objects.filter(id=user_id["id"]).update(tenant_id=tenant_data)56 education_data = Education.objects.filter(tenant_id=source_tenant).values("tenant_id", "id")57 for user_id in education_data:58 tenant_data = Tenant.objects.get(id=update_tenant)59 detail = Education.objects.filter(id=user_id["id"]).update(tenant_id=tenant_data)60 achievement_data = Achievement.objects.filter(tenant_id=source_tenant).values("tenant_id", "id")61 for user_id in achievement_data:62 tenant_data = Tenant.objects.get(id=update_tenant)63 detail = Achievement.objects.filter(id=user_id["id"]).update(tenant_id=tenant_data)64 skill_data = Skills.objects.filter(tenant_id=source_tenant).values("tenant_id", "id")65 for user_id in skill_data:66 tenant_data = Tenant.objects.get(id=update_tenant)67 detail = Skills.objects.filter(id=user_id["id"]).update(tenant_id=tenant_data)68 profile_setting = ProfileSetting.objects.filter(tenant_id=source_tenant).values("tenant_id", "id")69 for user_id in profile_setting:70 tenant_data = Tenant.objects.get(id=update_tenant)71 detail = ProfileSetting.objects.filter(id=user_id["id"]).update(tenant_id=tenant_data)72 partner_setting = PartnerSetting.objects.filter(tenant_id=source_tenant).values("tenant_id", "id")73 for user_id in partner_setting:74 tenant_data = Tenant.objects.get(id=update_tenant)75 detail = PartnerSetting.objects.filter(id=user_id["id"]).update(tenant_id=tenant_data)...
displayAptInfo.py
Source:displayAptInfo.py
1#!/usr/bin/python22import os3import json4import sys5import getopt6import shutil7from datetime import datetime8aptJsonFile = "apt.json"9aptJsonFile_tmp = "apt_tmp.json"10update_tenant = False11update_visitor = False12update_car = False13# --------------------------------------------------14# Usage15# --------------------------------------------------16def usage():17 print ("-----------------------------------------------------------------")18 print ("Usage: update.py <options>")19 print ("Options:")20 print (" -t, --tenant Update tenants")21 print (" -v, --vistor Update visitor")22 print (" -c, --car Update visitor's car")23 print (" -n NUMBER, --number=NUMBER Specify the APT number")24 print (" -h, --help Show help information and exit")25# --------------------------------------------------26# Take an arg27# --------------------------------------------------28def check_args():29 aptNum = None30 found = 031 global update_tenant32 global update_visitor33 global update_car34 try:35 opts, args = getopt.getopt(sys.argv[1:], "tvcn:h", ["tenant", "visitor", "number=", "help"])36 except getopt.GetoptError as err:37 print(err)38 usage()39 sys.exit(2)40 for opt, arg in opts:41 if opt in ("-h", "--help"):42 usage()43 sys.exit(0)44 elif opt in ("-t", "--tenant"):45 update_tenant = True46 update_item = "tenants"47 elif opt in ("-v", "--visitor"):48 update_visitor = True49 update_item = "visitors"50 elif opt in ("-c", "--car"):51 update_car = True52 update_item = "car_plates"53 elif opt in ("-n", "--number"):54 aptNum = arg55 else:56 print ("Unhandled option")57 usage()58 sys.exit(1)59 # Validate aptNum60 if aptNum is None: # Error #1 - it's empty61 print ("Error: You have to specify an APT number")62 usage()63 sys.exit(2)64 else: # Error #2 - it's not an integer65 try:66 int(aptNum)67 except ValueError:68 print ("Error: You have to specify a 3 digit APT number")69 usage()70 sys.exit(2)71 if (int(aptNum) < 100 or int(aptNum) > 350): # Error #3 - it's not in range72 print ("Error: APT number is not in range")73 usage()74 sys.exit(2) 75 76 # Check to see how many args are true, should be only one77 for item in [update_tenant, update_visitor, update_car]:78 if item:79 found = found + 180 81 if found != 1:82 print ("Error: You have to use one of the three options [-t|-v|-c] followed by -n <aptNum>")83 usage()84 sys.exit(2)85 return(update_item, aptNum)86# --------------------------------------------------87# Display the current values for the item to update88# --------------------------------------------------89def display_current(data, update_item, anum):90 for unit in data:91 if unit["aptnum"] == int(anum):92 print ("Here is the current " + update_item + " info for apt " + str(anum))93 print ("In display: " + json.dumps(unit[update_item])) 94# tkinterstring = f'{json.dumps(unit[update_item])}'95 return json.dumps(unit[update_item])96 #return tkinterstring97# --------------------------------------------------98# main()99# --------------------------------------------------100def main():101 # Open the json file and assign it to data102 with open(aptJsonFile) as file:103 data = json.load(file)104 update_item, anum = check_args()105 106 display_current(data, update_item, anum)107 sys.exit(0)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!