2 '''Generate SQL statements for CU''' 5 from faker
import Faker
13 TIMEFORMAT =
'%Y-%m-%d %H:%M:%S ' 17 '''Generate test data''' 21 tmpdir = tempfile.gettempdir()
22 with open(os.path.join(tmpdir,
"gatling.users.json"),
"w")
as users_json:
23 print(json.dumps(gatling_data, indent=4), file=users_json)
24 with open(os.path.join(tmpdir,
"gatling.users.sql"),
"w")
as users_sql:
26 print(s, file=users_sql)
27 print(
'\n\n\n', file=users_sql)
31 '''Generate profiles''' 41 profiles = list(generate())
42 return ([x[0]
for x
in profiles], [x[1]
for x
in profiles])
46 '''Generate CU SQL inserts''' 56 return '\n'.join(sqls)
60 '''return Y or N, ugh...''' 61 return 'Y' if b
else 'N' 65 '''return random bool as str''' 70 '''Generate CU user information, return dictionary''' 74 profile = faker.simple_profile(sex=
None)
75 if USERNAMES.get(profile[
'username'])
is None:
76 USERNAMES[profile[
'username']] = 1
79 account_balance = r.random() * r.randint(10, 100)
80 return {**profile, **{
83 'account_number': uid,
84 'account_description': faker.sentence(nb_words=3),
85 'account_balance': account_balance,
86 'account_ytdinterest': r.random() * r.randint(1, 12),
87 'account_lastyrinterest': r.random() * r.randint(1, 12),
88 'account_available': account_balance - r.random() * r.randint(1, 3),
90 'password': faker.password(length=10),
91 'primary_accounts': uid,
92 'billpayid': uid + r.randint(1, 20),
97 'forceremain': r.randint(0, 100),
98 'lastlogin': faker.past_datetime().strftime(TIMEFORMAT),
99 'priorlogin': faker.past_datetime().strftime(TIMEFORMAT),
100 'pwchange': faker.past_datetime().strftime(TIMEFORMAT),
104 'confidence': faker.text(max_nb_chars=20),
105 'challenge_quest_id': 0,
116 '''Generate statement for cusuer''' 117 TEMPLATE = (
'INSERT INTO {cu}user VALUES(' 123 '{primary_accounts},' 136 '{challenge_quest_id},' 145 return TEMPLATE.format(**{**profile, **{
146 'passwd': bcrypt.hashpw(profile[
'password'].encode(
'utf8'),
147 bcrypt.gensalt()).decode(
'utf8'),
148 'mfaquest': json.dumps(profile[
'mfaquest']),
153 '''Generate statement for cugroup''' 154 TEMPLATE = (
"INSERT INTO {cu}group VALUES ({group}, '{group}', 200, 0);")
155 return TEMPLATE.format(**profile)
159 '''Generate statement for cu member accounts''' 160 TEMPLATE = (
'INSERT INTO {cu}memberacct VALUES(' 162 "'{account_number}'," 169 return TEMPLATE.format(**profile)
173 '''Generate INSERT statement for cu member account balance''' 174 TEMPLATE = (
'INSERT INTO {cu}accountbalance VALUES(' 175 "'{account_number}'," 179 "'{account_description}'," 181 '{account_ytdinterest},' 182 '{account_lastyrinterest},' 183 '{account_available},' 195 return TEMPLATE.format(**profile)
199 '''Generate SQL insert statements for account history''' 202 TEMPLATE = (
'INSERT INTO {cu}accounthistory VALUES(' 203 "'{account_number}'," 217 INT_MAX = int((2 ** 32 - 1) / 2)
218 for i
in range(1, r.randint(2, 6)):
219 amount = r.random() * r.randint(10, 20)
220 yield TEMPLATE.format(**{**profile, **{
221 'trace_number': str(r.randint(1, INT_MAX)).zfill(20),
222 'date': FAKER.past_datetime().strftime(TIMEFORMAT),
224 'balance': profile[
'account_balance'] - amount,
225 'description': FAKER.sentence(nb_words=6),
226 'sortkey': str(r.randint(1, INT_MAX)).zfill(16),
228 return '\n'.join(generate())
232 '''Generate statement for cu member account rights''' 233 TEMPLATE = (
'INSERT INTO {cu}memberacctrights VALUES(' 235 "'{account_number}'," 239 return TEMPLATE.format(**profile)
243 '''Generate statement for cu user accounts''' 244 TEMPLATE = (
'INSERT INTO {cu}useraccounts VALUES(' 246 "'{account_number}'," 260 return TEMPLATE.format(**profile)
264 '''filter fields for gatling test harness''' 267 'mail':
lambda x: (
'email', x),
269 'cu':
lambda x: (
'cu', x.upper()),
270 'account_number':
lambda x: (
'account_id', x),
271 'mfaquest':
lambda x: (
'mfa', x[
'answers'][
'54']),
274 def filter_keys(profile, keys):
275 '''Filter out keys, based on KEYS dictionary''' 276 for k, f
in keys.items():
278 yield (k, profile[k])
281 return dict(filter_keys(profile, KEYS))
284 if __name__ ==
'__main__':
286 if len(sys.argv[1:]) > 0:
def generate_cuaccountbalance_sql(profile)
def generate_cugroup_sql(profile)
def gatling_test_data(profile)
def generate_cumemberacct_sql(profile)
def generate_cuuser_sql(profile)
def generate_cumemberacctrights_sql(profile)
def random_bool_to_str(faker)
def generate_cuuseraccounts_sql(profile)
def generate_cuuser(index, faker, cu, USERNAMES)
def generate_cuaccounthistory_sql(profile)
def generate_profile_sql(profile)
def generate_test_data(N=1000)
def generate_profiles(faker, cu, N=1000)