1from unittest import main 2from datetime import datetime 3from gnucash import Book, Account, Split, GncCommodity, GncNumeric, \ 4 Transaction 5 6from test_book import BookSession 7 8class AccountSession(BookSession): 9 def setUp(self): 10 BookSession.setUp(self) 11 self.account = Account(self.book) 12 13class TestAccount(AccountSession): 14 def test_name(self): 15 NAME = "Money" 16 self.assertEqual( '', self.account.GetName() ) 17 self.account.SetName(NAME) 18 self.assertEqual( NAME, self.account.GetName() ) 19 20 def test_split(self): 21 SPLIT = Split(self.book) 22 self.assertTrue(self.account.insert_split(SPLIT)) 23 self.assertTrue(self.account.remove_split(SPLIT)) 24 25 def test_assignlots(self): 26 abc = GncCommodity(self.book, 'ABC Fund', 27 'COMMODITY','ABC','ABC',100000) 28 self.table.insert(abc) 29 self.account.SetCommodity(abc) 30 31 other = Account(self.book) 32 other.SetCommodity(self.currency) 33 34 tx = Transaction(self.book) 35 tx.BeginEdit() 36 tx.SetCurrency(self.currency) 37 tx.SetDateEnteredSecs(datetime.now()) 38 tx.SetDatePostedSecs(datetime.now()) 39 40 s1a = Split(self.book) 41 s1a.SetParent(tx) 42 s1a.SetAccount(self.account) 43 s1a.SetAmount(GncNumeric(1.3)) 44 s1a.SetValue(GncNumeric(100.0)) 45 46 s1b = Split(self.book) 47 s1b.SetParent(tx) 48 s1b.SetAccount(other) 49 s1b.SetAmount(GncNumeric(-100.0)) 50 s1b.SetValue(GncNumeric(-100.0)) 51 52 s2a = Split(self.book) 53 s2a.SetParent(tx) 54 s2a.SetAccount(self.account) 55 s2a.SetAmount(GncNumeric(-1.3)) 56 s2a.SetValue(GncNumeric(-100.0)) 57 58 s2b = Split(self.book) 59 s2b.SetParent(tx) 60 s2b.SetAccount(other) 61 s2b.SetAmount(GncNumeric(100.0)) 62 s2b.SetValue(GncNumeric(100.0)) 63 64 tx.CommitEdit() 65 66 self.account.ScrubLots() 67 self.assertEqual(len(self.account.GetLotList()),1) 68 69if __name__ == '__main__': 70 main() 71