GnuCash
7574033+
Loading...
Searching...
No Matches
bindings
python
tests
test_account.py
1
from
unittest
import
main
2
from
datetime
import
datetime
3
from
gnucash
import
Book, Account, Split, GncCommodity, GncNumeric, \
4
Transaction
5
6
from
test_book
import
BookSession
7
8
class
AccountSession
(
BookSession
):
9
def
setUp(self):
10
BookSession.setUp(self)
11
self.
account
=
Account
(self.
book
)
12
13
class
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_online_id(self):
21
ONLINE_ID =
"061000104:0123456789:CHECKING"
22
self.assertEqual(
None
, self.
account
.GetOnlineID() )
23
self.
account
.SetOnlineID(ONLINE_ID)
24
self.assertEqual( ONLINE_ID, self.
account
.GetOnlineID() )
25
# Passing None (or "") clears it.
26
self.
account
.SetOnlineID(
None
)
27
self.assertEqual(
None
, self.
account
.GetOnlineID() )
28
29
def
test_split
(self):
30
SPLIT = Split(self.
book
)
31
self.assertTrue(self.
account
.insert_split(SPLIT))
32
self.assertTrue(self.
account
.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.
account
.SetCommodity(abc)
39
40
other =
Account
(self.
book
)
41
other.SetCommodity(self.
currency
)
42
43
tx = Transaction(self.
book
)
44
tx.BeginEdit()
45
tx.SetCurrency(self.
currency
)
46
tx.SetDateEnteredSecs(datetime.now())
47
tx.SetDatePostedSecs(datetime.now())
48
49
s1a = Split(self.
book
)
50
s1a.SetParent(tx)
51
s1a.SetAccount(self.
account
)
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.
account
)
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.
account
.ScrubLots()
76
self.assertEqual(len(self.
account
.GetLotList()),1)
77
78
if
__name__ ==
'__main__'
:
79
main()
GncNumeric
The primary numeric class for representing amounts and values.
Definition
gnc-numeric.hpp:61
test_account.AccountSession
Definition
test_account.py:8
test_account.AccountSession.account
account
Definition
test_account.py:11
test_account.TestAccount
Definition
test_account.py:13
test_book.BookSession
Definition
test_book.py:5
test_book.BookSession.table
table
Definition
test_book.py:9
test_book.BookSession.book
book
Definition
test_book.py:8
test_split
Definition
test_split.py:1
Account
STRUCTS.
Generated by
1.15.0