python interface to automation, the registration interface randomly generated phone number

As you know in the registration interface, the phone number of parameters that need to be unregistered phone number, and in the test case, you write the phone number is not necessarily unregistered. So then it needs to be done to deal with registration interface incoming phone number. Here I will share a file handle py phone number of a course which learned. And share learning!

Specific code as follows:

Random Import 
# The first step in creating a random phone number
DEF get_mobilephone ():
'' '
: return: return a random phone number

' ''
FIRST_NUM = [ '130.', '131 is', '132', '133', '134', '135', '136', '137', '138', '139',
'150', '151', '152', '153', '155', '156', '157 ',' 158 ',' 159 ',
' 180 ',' 181 ',' 182 ',' 183 ',' 184 ',' 185 ',' 186 ',' 187 ',' 188 ',' 189 ']
start_mobile = random.choice (first_num) # randomly selected value list
num_str = '012345678'
end_mobile = '' .join (random.sample (num_str, 8)) # 8 times randomly from a string
new_mobile = start_mobile + end_mobile # spliced into a phone number
return new_mobile
whether the determination Step # randomly generated phone number database has
def is_exit_mobile (self, mobile ):
'' '
mobile: def get_mobilephone () randomly generated phone number
: return: if there are randomly generated phone number # Analyzing database
'' '
Data =' the SELECT * the FROM Member the WHERE MobilePhone, =% S '
IF Self (Data, Arg = ( mobile,)): # __call__ method call
return True
the else:
return False
# the third step if the phone number is randomly generated database does not exist, it returns
DEF creat_is_not_exit_mobile (Self):
'' '
: return:
' ''
# cycle to determine whether a randomly generated phone number before the database does not exist inside
the while True:
Mobile self.get_mobilephone = () # function call to the phone number randomly generated, randomly generated phone number
if not self.is_exit_mobile (mobile): # If before the phone number of the database there is no stopping the circulation, return phone number
BREAK
return Mobile

Guess you like

Origin www.cnblogs.com/yiruiwan/p/12209801.html