def create_default_objects(): ''' Creates a list of default users and accounts for testing purposes ''' # Create a default Admin user Admin(username="******", password="******", first_name="Jack").save() print("Default Admin Created") cust1 = Customer(username="******", password="******", first_name="John") cust1.save() print("Default Customer Created") Checking_Account(account_number="1", owner=cust1).save() print("Default Checking Account Created") Savings_Account(account_number="2", owner=cust1).save() print("Default Savings Account Created") cust2 = Customer(username="******", password="******", first_name="Clark") cust2.save() print("Default Customer2 Created") Savings_Account(account_number="3", owner=cust2).save() print("Default Savings Account Created") Brokerage_Account(account_number="4", owner=cust1).save() print("Default Brokerage Account Created")
def create_account(self, account_type, account_number): ''' Creates and returns a new account object with the given account type and account number Takes two strings as parameters ''' # Try to retrieve an account with the same account number and, if it succeeds, we know # that number is already in use. account_number_exists = False try: Checking_Account.get(account_number=account_number) account_number_exists = True except: try: Savings_Account.get(account_number=account_number) account_number_exists = True except: try: Brokerage_Account.get_account(account_number) acount_number_exists = True except: pass # Throw exception if account number is already in use if account_number_exists: raise Exception("Account Number is already in use") # Create a checking account if that's the account type if account_type == "checking": acct = Checking_Account(account_number=account_number).save() # Create a savings account if that's the account type elif account_type == "savings": acct = Savings_Account(account_number=account_number).save() # Create a brokerage account if that's the account type elif account_type == "brokerage": acct = Brokerage_Account(account_number=account_number).save() # If we don't have a matching account type, raise an exception else: raise Exception("Invalid Account Type") return acct