def test_delete(self): """ Testing deletion of stock. """ result = Portfolio() result.add_stock("AA", 10, 50, "2010-04-03") self.assertTrue(result.delete_stock("AA"), True)
def test_portfolio(self): """ Testing portfolio creation. initialisation and add stock. """ if DataHandler.check_portfolio_exists(): result = Portfolio() self.assertIsInstance(result.portfolio, dict) else: result = Portfolio() result.add_stock("AA", 10, 50, "2010-04-03") self.assertTrue(result.portfolio['AA'], True)
def test_update(self): """ Testing portfolio creation. initialisation and add stock. """ if DataHandler.check_portfolio_exists(): result = Portfolio() self.assertIsInstance(result.portfolio, dict) else: result = Portfolio() result.add_stock("AA", 10, 50, "2010-04-03") data = StockDataReader.get_data("AA") last_price = StockDataReader.last_price(data) result.update_stock("AA", data) if last_price == result.portfolio['AA']['Last Price $']: assertion = True else: assertion = False self.assertTrue(assertion, True)
main_msg = """ What would you like to do? 1: Add stock to portfolio 2: View portfolio 3: Overall performance 4: Update portfolio 5: Delete stock from portfolio 9: Exit """ while True: print(main_msg) selection = input("Enter your choice: ") if selection == "1": latest_portfolio.add_stock() elif selection == "2": latest_portfolio.print_portfolio() elif selection == "3": print("Performance") elif selection == "4": latest_portfolio.update_portfolio() elif selection == "5": print("Delete stock") elif selection == "9": break else: print("Please enter a valid selection!") DataHandler.save_portfolio(latest_portfolio.portfolio)