Finish working on CLI Implementation
This commit is contained in:
@@ -5,15 +5,13 @@
|
||||
# This adds 50 clients, each with 2 accounts. Each account has 40 transactions.
|
||||
|
||||
from faker import Faker
|
||||
from connection import add_client, add_account, add_transaction
|
||||
from connection import add_client, add_account, add_transaction, modify_balance
|
||||
import random
|
||||
import datetime
|
||||
import hashlib
|
||||
import time
|
||||
|
||||
def generate_hash(): # Creates a hash for a password
|
||||
seed = str(random.random()).encode('utf-8')
|
||||
return hashlib.sha512(seed).hexdigest()
|
||||
passwd = "Happymeal1"
|
||||
|
||||
|
||||
def timestamp(): # Returns the current timestamp
|
||||
return (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
||||
@@ -23,8 +21,8 @@ def generate_test_database(client_id, password):
|
||||
|
||||
all_account_ids = [] # List to store all account IDs
|
||||
|
||||
for i in range(50): # Generate 50 clients
|
||||
password = generate_hash()
|
||||
for i in range(3): # Generate 50 clients
|
||||
password = passwd
|
||||
name = fake.name()
|
||||
birthdate = fake.date_of_birth(minimum_age=18, maximum_age=90)
|
||||
address = fake.address()
|
||||
@@ -34,8 +32,9 @@ def generate_test_database(client_id, password):
|
||||
|
||||
client_response = add_client(name, birthdate, address, phone_number, email, password, notes)
|
||||
client_id = client_response['message']
|
||||
print(f"Client {client_id} added successfully. Password: {password}")
|
||||
for j in range(2): # Each client has 2 accounts
|
||||
balance = 1000 # Initialize balance to 1000
|
||||
|
||||
account_type = random.choice(['Spending', 'Savings'])
|
||||
account_notes = fake.text(max_nb_chars=50)
|
||||
|
||||
@@ -43,14 +42,16 @@ def generate_test_database(client_id, password):
|
||||
|
||||
response_dict = account_response
|
||||
account_id = response_dict['message']
|
||||
print(f"Account {account_id} added successfully.")
|
||||
balance = float(1000)
|
||||
balance_response = modify_balance(account_id, balance)
|
||||
|
||||
|
||||
for k in range(40): # Each account has 40 transactions
|
||||
for k in range(3): # Each account has 40 transactions
|
||||
if not all_account_ids: # Skip creating a transaction if there are no accounts yet
|
||||
continue
|
||||
|
||||
transaction_type = random.choice(['Deposit', 'Withdrawal'])
|
||||
amount = random.randint(1, 200)
|
||||
amount = float(random.randint(1, 200))
|
||||
|
||||
if transaction_type == 'Withdrawal' and balance - amount < 0: # Skip withdrawal if it would make balance negative
|
||||
continue
|
||||
@@ -64,9 +65,8 @@ def generate_test_database(client_id, password):
|
||||
recipient_account_id = random.choice(all_account_ids)
|
||||
|
||||
transaction_response = add_transaction(amount=amount, account_id=account_id, recipient_account_id=recipient_account_id, otp_code=123456, description=transaction_description)
|
||||
print(f"Transaction response: {transaction_response}")
|
||||
time.sleep(1)
|
||||
time.sleep(0.1)
|
||||
|
||||
all_account_ids.append(account_id)
|
||||
|
||||
print("Test database generated successfully.")
|
||||
print("Test data added successfully.")
|
||||
|
||||
Reference in New Issue
Block a user