def main_menu(user): #TODO: Complete this function while True: view.print_main_menu(user) choice = view.main_prompt() """ TODO: add bad input message """ if choice == "1": #1 is check balance view.show_balance( user ) ###TODO - 1 - Currently brings you to user menu - add Would you like to do anything else? Y (main user menu) / N (quit / goodbye) elif choice == "2": #2 is Withdraw Funds amount = view.withdrawal_amount() try: user.withdraw(amount) #funct is in model view.post_withdrawal( amount, user.balance ) ###TODO - 1 -same as above. Note with the break it brings you back to 1st menu (not user) except ValueError: view.not_positive( ) #print("The amount must be positive") #move the print to views except model.InsufficientFundsError: view.insufficient_funds() #break elif choice == "3": amount = view.deposit_amount() user.deposit(amount) #funct is in model view.post_deposit( amount, user.balance ) ###TODO - 1 -same as above. Note with the break it brings you back to 1st menu (not user) #break elif choice == "4": #4 is sign out - ###TODO - 1B - give goodbye message not bring you back to 1st menu break
def testBuy_and_sell(self): print("""\n========================= UNIT TEST testBuy_and_sell() This test will ALWAYS say Insufficient Funds or Shares for Buy and Sell, respectively by design. Testing graceceful error/exception handling \n""") account_data = Account(username="******", balance=20000000, first_name="John", last_name="Smith", email_address="*****@*****.**") account_data.set_password_hash("password") account_data.save() ticker = view.ticker_info() trade = view.buy_sell_choice() if trade not in ("1", "2"): view.bad_choice_input() return elif trade == "1": volume = float(view.enter_buy_info()) with self.assertRaises(InsufficientFundsError, msg="should raise InsufficientFundsError"): view.insufficient_funds() account_data.buy(ticker, 1000000) elif trade == "2": volume = float(view.enter_sell_info()) with self.assertRaises(InsufficientSharesError, msg="should raise InsufficientSharesError"): view.insufficient_shares() account_data.sell(ticker, 1000000)
def main_menu(user): while True: if user.username == 'admin': view.print_admin_menu(user) choice = view.main_prompt() else: view.print_main_menu(user) choice = view.main_prompt() if choice == "1": view.show_balance(user) #Check Balance pass elif choice == "2": #Withdraw Funds amount = view.withdrawal_amount() try: user.withdraw(amount) #func is in account.py view.post_withdrawal(amount, user.balance) except ValueError: view.not_positive() except account.InsufficientFundsError: view.insufficient_funds() elif choice == "3": #Deposit Funds amount = view.deposit_amount() try: user.deposit(amount) view.post_deposit(amount, user.balance) except ValueError: view.not_positive() elif choice == "4": #Trading Menu trading_menu(user) elif choice == "5": #Sign Out #exits to first login menu break elif choice == "6": #Admin - Leaderboard if user.username == 'admin': admin_leaderboard() else: view.bad_menu_input() elif choice == "7": if user.username == 'admin': username = view.select_username() toggle_admin(username) else: view.bad_menu_input() else: #loops back view.bad_menu_input() continue
def trading_menu(user): while True: view.print_trading_menu(user) choice = view.trading_menu_prompt() if choice == "1": #GetQuote ticker = view.ticker_prompt() try: quote = account.get_quote(ticker) # print(quote) #shows whole quote as json dictionary print(f""" Company Name: {quote['companyName']} Symbol: {quote['symbol']} Latest Price: {quote['latestPrice']} IEX Bid Price: {quote['iexBidPrice']} IEX Ask Price: {quote['iexAskPrice']} High: {quote['high']} Low: {quote['low']} 52 Week High: {quote['week52High']} 52 Week Low: {quote['week52Low']} PE Ratio {quote['peRatio']}\n\n""") except ConnectionError: view.connection_error() elif choice == "2": #Buy Shares NOT COMPLETE view.buy_intro() ticker = view.ticker_prompt() quantity = view.quantity() try: quantity = int(quantity) if quantity < 0: view.negative_quantity_error( ) #TODO: fix this so it doesn't send you back to trading menu elif quantity == 0: view.zero_quantity_error() else: try: market_value = user.trade(ticker, quantity) view.sucessful_buy_trade(ticker, quantity, market_value) except InsufficientFundsError: view.insufficient_funds() except ConnectionError: view.connection_error() except ValueError: view.not_number_error() elif choice == "3": #Sell Shares view.sell_intro() ticker = view.ticker_prompt() quantity = view.quantity() try: quantity = int(quantity) if quantity < 0: view.negative_quantity_error( ) #TODO: fix this so it doesn't send you back to trading menu elif quantity == 0: view.zero_quantity_error() else: quantity = quantity * -1 try: market_value = user.trade(ticker, quantity) view.sucessful_sell_trade(ticker, quantity, market_value) except InsufficientSharesError: view.insufficient_shares() except ConnectionError: view.connection_error() except ValueError: view.not_number_error() # except account.NegativeQuantityError: # view.negative_quantity_error() elif choice == "4": #See Holdings user.show_holdings_by_account() elif choice == "5": #Show Trade History while True: selection = view.trade_history_prompt() if selection.lower() == "quit": break elif selection.lower() == "total": user.show_trades_by_account() break else: user.show_trades_by_account_and_ticker(selection) break elif choice == "6": #Exit to Menu break else: view.bad_menu_input()