Create three accounts
from scripts.handle_mysql Import HandleMysql # database type from scripts.handle_requsets Import HandleTheRequest # initiate a request class from scripts.handle_config Import do_config # configuration file reading and writing classes from scripts.constants Import CONFIGS_USER_ACCOUTS_DIR # path to create three accounts saved DEF create_new_user (regname, = pwd ' 123456 ' ): "" " called once to create a user account : param regname: registered users of : param pwd: fixed password ,, do not pass the phone number : return: the return of nested dictionary dictionary user_dict, after successfully created an account, account id, regname name, mobilephone phone number, pwd password "" " handle_mysql = HandleMysql () # Create a MySQL session, be sure to turn off the last do_register = HandleTheRequest ( ) # create a class session interface request url = do_config.get_value ( " API " , " prefix " ) + " / Member / the Register " # stitching url # query whether the phone number in the database exist SQL = " the SELECT Member from the WHERE MobilePhone, the above mentioned id = S%; " the while True: # MobilePhone, get an unregistered phone number = handle_mysql.create_not_existed_mobile MobilePhone, () # database phone number is not registered Method # Parameter Data = { " MobilePhone, " : MobilePhone,, " pwd " : pwd, " regname " : regname} do_register.to_request (Method = " POST " , URL = URL , Data = Data) Result = handle_mysql.get_value (SQL = SQL, args = (MobilePhone,,)) IF Result: # If not empty true explanation registration is successful, return a dictionary user_id = the Result [ " the above mentioned id " ] # After successful registration to obtain the user the above mentioned id BREAK # profile area name: regname, preserved id, regname name, mobilephone phone number, password pwd user_dict = { regname: { " ID " : user_id, " regname " : regname, " MobilePhone, " : MobilePhone,, " pwd " : pwd } } handle_mysql.close () # close link MySQL do_register.close () # Close Session request link return user_dict DEF generate_users_config (): "" " information called three times create_new_user, generates three user account : return: " "" users_datas_dict = {} # Update nested into one dictionary Dictionary users_datas_dict.update (create_new_user ( " admin_user " )) # administrator account, return to the dictionary users_datas_dict.update (create_new_user ( " invest_user " )) # investor's account, return to the dictionary users_datas_dict.update (create_new_user ( "borrow_user " )) # borrower's account, return to the dictionary do_config.write_config (users_datas_dict, CONFIGS_USER_ACCOUTS_DIR) # write to the configuration IF __name__ == ' __main__ ' : # generate three account # [admin_user] Administrator # [invest_user] investors # [borrow_user] borrowers generate_users_config ()
After the write random data to create three account profiles (phone numbers are randomly created fake)
[admin_user] id = 179542 regname = admin_user mobilephone = 13982490671 pwd = 123456 [invest_user] id = 179543 regname = invest_user mobilephone = 13226834715 pwd = 123456 [borrow_user] id = 179544 regname = borrow_user mobilephone = 13907468239 pwd = 123456
We just need to execute use cases in the front entrance automation file, add the account in the absence of three profiles of judgment, it can automatically create three accounts
from scripts.constants Import CONFIGS_USER_ACCOUTS_DIR # three account profile path # If the user account where the configuration file does not exist, for the True, the creation account IF not os.path.exists (CONFIGS_USER_ACCOUTS_DIR): generate_users_config ()
******* Please respect the original, as to reprint, please indicate the source: Reprinted from: https://www.cnblogs.com/shouhu/ Thank you! ! *******