-
Notifications
You must be signed in to change notification settings - Fork 0
/
testCase.py
146 lines (117 loc) · 5.28 KB
/
testCase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import random
# A class for generating test cases (text for the text fields of the sign up form).
class TestCase:
def __init__(self, isValidFirstName=True, isValidLastName=True, isValidPhone=True, isValidEmail=True, isValidPassword=True, isValidConfirmedPassword=True, registeredEmail=[]):
self.charPool = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-*/.~=_)(^%$#@!'
self.numPool = '0123456789'
self.validPhonePool = ['+201280099665',
'+201286845566', '+201005023056', '+201112569887']
# These emails where generated by an online tool.
self.validEmailPool = [
'posotab886@homedepinst.com', 'jojorabbit1918@mailsac.com',
'verydagger85@mailsac.com', 'themailman1997@mailsac.com',
'chefcurry@mailsac.com', 'thebeard13@mailsac.com',
'mjthegoat23@mailsac.com', 'hisairness23@mailsac.com',
'hakeemthedream33@mailsac.com', 'timduncunfundamentals@mailsac.com',
'kawhitheclaw@mailsac.com', 'isaacnewton1600@mailsac.com']
self.firstName = self.generateFirstName(isValidFirstName)
self.lastName = self.generateLastName(isValidLastName)
self.mobileNumber = self.generatePhoneNumber(isValidPhone)
self.emailAddress = self.generateEmail(isValidEmail, registeredEmail)
self.password = self.generatePassword(isValidPassword)
self.confirmedPassword = self.generateConfirmedPassword(
isValidConfirmedPassword)
def generateFirstName(self, isValid):
# A list for building the text character by character.
firstName = []
firstNameAsString = ''
indx = 0
nameLen = random.randrange(3, 15)
if isValid:
# Must start with a capital letter.
indx = random.randrange(0, 26)
firstName.append(self.charPool[indx])
else:
# Must start with a non capital letter or any character.
indx = random.randrange(26, len(self.charPool))
firstName.append(self.charPool[indx])
for i in range(nameLen - 1):
indx = random.randrange(0, len(self.charPool))
firstName.append(self.charPool[indx])
firstNameAsString = ''.join(map(str, firstName))
return firstNameAsString
def generateLastName(self, isValid):
lastName = ''
# determines if the code would generate a different invalid format or exactly the same valid format to first name.
coinFlip = random.randrange(0, 1)
if isValid:
lastName = self.generateFirstName(isValid)
else:
if coinFlip:
lastName = self.firstName
return lastName
else:
lastName = self.generateFirstName(isValid)
return lastName
def generatePhoneNumber(self, isValid):
# A list for building the number digit by digit.
# This generator sticks with the Egyption format.
phoneNumber = []
phoneNumberAsString = ''
indx = 0
if isValid:
indx = random.randrange(0, len(self.validPhonePool))
phoneNumberAsString = self.validPhonePool[indx]
return phoneNumberAsString
else:
phoneNumber.append(random.randrange(0, len(self.numPool)))
for i in range(11):
indx = random.randrange(0, len(self.numPool))
phoneNumber.append(self.numPool[indx])
phoneNumberAsString = ''.join(map(str, phoneNumber))
return phoneNumberAsString
def generateEmail(self, isValid, registeredEmail):
email = []
emailAsString = ''
indx = 0
# determines if the code would generate a different invalid format or an existing email.
coinFlip = random.randrange(0, 1)
emailLen = random.randrange(8, 20)
if isValid:
for i in range(len(self.validEmailPool)):
if self.validEmailPool[i] not in registeredEmail:
emailAsString = self.validEmailPool[i]
return emailAsString
if coinFlip:
emailAsString = registeredEmail[0]
return emailAsString
for i in range(emailLen):
indx = random.randrange(0, len(self.charPool))
email.append(self.charPool[indx])
emailAsString = ''.join(map(str, email))
return emailAsString
def generatePassword(self, isValid):
password = []
passwordAsString = ''
indx = 0
passwordLen = 0
if isValid:
indx = random.randrange(0, 26)
password.append(self.charPool[indx])
indx = random.randrange(26, 52)
password.append(self.charPool[indx])
passwordLen = random.randrange(0, 7)
else:
passwordLen = random.randrange(9, 20)
for i in range(passwordLen):
indx = random.randrange(0, len(self.charPool))
password.append(self.charPool[indx])
passwordAsString = ''.join(map(str, password))
return passwordAsString
def generateConfirmedPassword(self, isValid):
confirmedPassword = ''
if isValid:
confirmedPassword = self.password
else:
confirmedPassword = self.generatePassword(isValid)
return confirmedPassword