def test_illegal_entry_type(self): # Your code here to test that adding an illegal entry type (like 'bananas' # or such - something which is NOT a float) raises a suitable exception. user_number = 'bananas' funds = 100 result = MoneyManager.add_entry('bananas', funds) self.assertFalse(result)
def test_legal_entry(self): # Your code here to test that adding a new entry with a a legal amount subtracts the # funds from the balance. user_number = 123456 funds = 100 result = MoneyManager.add_entry(user_number, funds) self.assertTrue(result)
def test_deposit_funds(self): # Your code here to test that depositing money using the account's # 'deposit_funds' function adds the amount to the balance. user_number = 123456 funds = 100 result = MoneyManager.add_entry(user_number, funds) self.assertTrue(result)
def test_illegal_deposit_raises_exception(self): # Your code here to test that depositing an illegal value (like 'bananas' # or such - something which is NOT a float) results in an exception being # raised. user_number = 'bananas' funds = 100 result = MoneyManager.add_entry(user_number, funds) self.assertFalse(result)
def test_insufficient_funds_entry(self): # Your code here to test that you can only spend funds which are available. # For example, if you have a balance of 500.00 dollars then that is the maximum # that can be spent. If you tried to spend 600.00 then a suitable exception # should be raised and the withdrawal should NOT be applied to the user balance # or the user's transaction list. user_number = 123456 funds = 50000000000 result = MoneyManager.add_entry(user_number, funds) self.assertFalse(result)
class TestMoneyManager(unittest.TestCase): def setUp(self): # Create a test BankAccount object self.user = MoneyManager() # Provide it with some initial balance values self.user.balance = 1000.0 def test_legal_deposit_works(self): # Your code here to test that depsositing money using the account's # 'deposit_funds' function adds the amount to the balance. self.user.deposit_funds(100) self.assertEqual(self.user.balance, 1100) def test_illegal_deposit_raises_exception(self): # Your code here to test that depositing an illegal value (like 'bananas' # or such - something which is NOT a float) results in an exception being # raised. self.assertRaises((TypeError, ValueError), self.user.deposit_funds('bananas')) self.assertRaises((TypeError, ValueError), self.user.deposit_funds('1000')) def test_legal_entry(self): # Your code here to test that adding a new entry with a a legal amount subtracts the # funds from the balance. self.user.add_entry(500, 'food') self.assertEqual(self.user.balance, 500) def test_illegal_entry_amount(self): # Your code here to test that withdrawing an illegal amount (like 'bananas' # or such - something which is NOT a float) raises a suitable exception. self.assertRaises((TypeError, ValueError), self.user.add_entry('bananas', 'food')) self.assertRaises((TypeError, ValueError), self.user.add_entry('500', 'food')) def test_illegal_entry_type(self): # Your code here to test that adding an illegal entry type (like 'bananas' # or such - something which is NOT a float) raises a suitable exception. self.assertRaises((TypeError, ValueError), self.user.add_entry(500, 'bananas')) self.assertRaises((TypeError, ValueError), self.user.add_entry(500, 1200)) def test_insufficient_funds_entry(self): # Your code here to test that you can only spend funds which are available. # For example, if you have a balance of 500.00 dollars then that is the maximum # that can be spent. If you tried to spend 600.00 then a suitable exception # should be raised and the withdrawal should NOT be applied to the user balance # or the user's transaction list. self.assertRaises((TypeError, ValueError), self.user.add_entry(2000, 'food'))
def perform_transaction(): '''Function to add the entry the amount in the amount entry from the user balance and add an entry to the transaction list.''' global user global amount_entry global balance_label global balance_var global entry_type # Try to decrease the account balance and append the deposit to the account file try: # Get the cash amount to use. Note: We check legality inside account's withdraw_funds method balance = balance_var.get() balance = balance.strip() balance = balance.replace(" ", "") file = str(user_number_var.get()) MoneyManager.add_entry(file, balance) fo = open(file + ".txt", "rb") fo.readline() fo.readline() fo.seek(12, 1) bal = fo.readline() bal = str(bal) bal = bal.replace("b", "") bal = bal.replace("r", "") bal = bal.replace("n", "") bal = bal.replace("\\", "") bal = bal.replace("'", "") bal = float(bal) fo.close() # Get the type of entry that will be added ie rent etc global variable v = variable.get() if float(balance) > float(bal): c = Tk() c.title('FedUni Money Manager') l = Label(c, text='No Enough Amount in Account', font=("Helvetica", 16)) l.pack() c.mainloop() return # Withdraw funds from the balance bal = float(bal) - float(balance) # Update the transaction widget with the new transaction by calling user.get_transaction_string() # Note: Configure the text widget to be state='normal' first, then delete contents, then instert new # contents, and finally configure back to state='disabled' so it cannot be user edited. MoneyManager.get_transaction_string(file, bal) # Change the balance label to reflect the new balance global y y.set("Balance : $ " + str(bal)) MoneyManager.save_to_file(file, v, balance) fo = open(file + ".txt", "r") fo.readline().replace("\n", "") fo.readline().replace("\n", "") fo.readline().replace("\n", "") fo.readline().replace("\n", "") x = fo.readline() transaction_list = x while x: x = fo.readline() transaction_list = transaction_list + x fo.close() Textbox.delete(1.0, END) Textbox.insert(END, transaction_list) # Update the graph plot_spending_graph() # Clear the amount entry global balance_entry balance_entry.delete(0, END) # Catch and display any returned exception as a messagebox 'showerror' except: c = Tk() c.title('FedUni Money Manager') l = Label(c, text='Something Went Wrong', font=("Helvetica", 16)) l.pack() c.mainloop()