def add_stock_cash(self): stock_cash = StockCash() stock_cash.set_symbol(self.entrySymbol.get()) stock_cash.set_amount(self.entryAmount.get()) stock_cash_table = StockCashTable() stock_cash_table.add_stock_cash(stock_cash) self.set_status("Added")
def test_stock_cash_sanity(self): stock_db_connection = get_default_db_connection() reset_table(stock_db_connection) stock_cash_table = StockCashTable(stock_db_connection) stock_cash = StockCash("601398", 1000) stock_cash_table.add_stock_cash(stock_cash) # test the new created line stock_cash = stock_cash_table.get_stock_cash_by_symbol("601398") self.assertEqual(stock_cash.get_symbol(), "601398") self.assertEqual(stock_cash.get_amount(), 1000) # test update stock cash stock_cash.set_amount(23.456) stock_cash_table.update_stock_cash(stock_cash) stock_cash = stock_cash_table.get_stock_cash_by_symbol("601398") self.assertEqual(stock_cash.get_amount(), 23.456) # test an unavailable line stock_cash = stock_cash_table.get_stock_cash_by_symbol("XXXXXX") self.assertEqual(stock_cash, None) # insert a new line, and test get_all function stock_cash = StockCash("601857", 5000) stock_cash_table.add_stock_cash(stock_cash) stock_cash_list = stock_cash_table.get_all_stock_cash() self.assertEqual(len(stock_cash_list), 2) stock_cash = stock_cash_list[0] self.assertEqual(stock_cash.get_symbol(), "601398") self.assertEqual(stock_cash.get_amount(), 23.456) stock_cash = stock_cash_list[1] self.assertEqual(stock_cash.get_symbol(), "601857") self.assertEqual(stock_cash.get_amount(), 5000) # delete a line stock_cash = StockCash("601398", 0) stock_cash_table.delete_stock_cash(stock_cash) stock_cash = stock_cash_table.get_stock_cash_by_symbol("601398") self.assertEqual(stock_cash, None)