GnuCash c935c2f+
Loading...
Searching...
No Matches
test_account.py
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
9 def setUp(self):
10 BookSession.setUp(self)
11 self.account = Account(self.book)
12
14 def test_name(self):
15 NAME = "Money"
16 self.assertEqual( '', self.accountaccount.GetName() )
17 self.accountaccount.SetName(NAME)
18 self.assertEqual( NAME, self.accountaccount.GetName() )
19
20 def test_online_id(self):
21 ONLINE_ID = "061000104:0123456789:CHECKING"
22 self.assertEqual( None, self.accountaccount.GetOnlineID() )
23 self.accountaccount.SetOnlineID(ONLINE_ID)
24 self.assertEqual( ONLINE_ID, self.accountaccount.GetOnlineID() )
25 # Passing None (or "") clears it.
26 self.accountaccount.SetOnlineID(None)
27 self.assertEqual( None, self.accountaccount.GetOnlineID() )
28
29 def test_split(self):
30 SPLIT = Split(self.book)
31 self.assertTrue(self.accountaccount.insert_split(SPLIT))
32 self.assertTrue(self.accountaccount.remove_split(SPLIT))
33
34 def test_assignlots(self):
35 abc = GncCommodity(self.book, 'ABC Fund',
36 'COMMODITY','ABC','ABC',100000)
37 self.table.insert(abc)
38 self.accountaccount.SetCommodity(abc)
39
40 other = Account(self.book)
41 other.SetCommodity(self.currencycurrency)
42
43 tx = Transaction(self.book)
44 tx.BeginEdit()
45 tx.SetCurrency(self.currencycurrency)
46 tx.SetDateEnteredSecs(datetime.now())
47 tx.SetDatePostedSecs(datetime.now())
48
49 s1a = Split(self.book)
50 s1a.SetParent(tx)
51 s1a.SetAccount(self.accountaccount)
52 s1a.SetAmount(GncNumeric(1.3))
53 s1a.SetValue(GncNumeric(100.0))
54
55 s1b = Split(self.book)
56 s1b.SetParent(tx)
57 s1b.SetAccount(other)
58 s1b.SetAmount(GncNumeric(-100.0))
59 s1b.SetValue(GncNumeric(-100.0))
60
61 s2a = Split(self.book)
62 s2a.SetParent(tx)
63 s2a.SetAccount(self.accountaccount)
64 s2a.SetAmount(GncNumeric(-1.3))
65 s2a.SetValue(GncNumeric(-100.0))
66
67 s2b = Split(self.book)
68 s2b.SetParent(tx)
69 s2b.SetAccount(other)
70 s2b.SetAmount(GncNumeric(100.0))
71 s2b.SetValue(GncNumeric(100.0))
72
73 tx.CommitEdit()
74
75 self.accountaccount.ScrubLots()
76 self.assertEqual(len(self.accountaccount.GetLotList()),1)
77
78if __name__ == '__main__':
79 main()