1 from unittest
import main
3 from gnucash
import Transaction, Book, Account, Split
4 from unittest_support
import *
6 from test_book
import BookSession
11 self.
domain2 =
"gnc.engine.scrub"
12 level = G_LOG_LEVEL_CRITICAL
14 check1.log_domain = self.
domain1
15 check1.log_level = level
16 check1.msg =
"[xaccScrubUtilityGetOrMakeAccount()] No currency specified!"
17 test_add_error(check1)
19 check2.log_domain = self.
domain1
20 check2.log_level = level
21 check2.msg =
"[xaccTransScrubSplits()] Transaction doesn't have a currency!"
22 test_add_error(check2)
23 self.
hdlr1 = test_set_list_handler(self.
domain1, level,
None)
25 check3.log_domain =
"gnc.engine.scrub"
26 check3.log_level = level
27 check3.msg =
"[xaccScrubUtilityGetOrMakeAccount()] No currency specified!"
28 self.
hdlr2 = test_set_checked_handler(self.
domain2, level, check3)
29 BookSession.setUp(self)
34 self.split.SetParent(self.
trans)
36 self.trans.SetCurrency(self.
currency)
41 test_clear_error_list ()
46 self.assertTrue( TRANS.Equal(self.
trans,
True,
False,
False,
False) )
50 level = G_LOG_LEVEL_WARNING
52 check.log_domain = domain
53 check.log_level = level
54 check.msg =
"[xaccTransEqual()] GUIDs differ"
55 hdlr = test_set_checked_handler(domain, level, check)
57 TRANS = self.trans.Clone()
59 self.assertFalse( TRANS.Equal(self.
trans,
True,
False,
False,
False) )
61 self.assertTrue( TRANS.Equal(self.
trans,
False,
False,
True,
False) )
63 g_log_remove_handler(domain, hdlr)
65 def test_setcurrency(self):
66 self.assertTrue( self.currency.equal( self.trans.GetCurrency() ) )
69 self.assertFalse( self.trans.IsOpen() )
70 self.trans.BeginEdit()
71 self.assertTrue( self.trans.IsOpen() )
72 self.trans.CommitEdit()
73 self.assertFalse( self.trans.IsOpen() )
75 def test_rollback(self):
76 self.assertEquals(
'', self.trans.GetDescription() )
77 self.trans.BeginEdit()
79 self.trans.SetDescription(DESC)
80 self.assertEquals( DESC, self.trans.GetDescription() )
81 self.trans.RollbackEdit()
82 self.assertEquals(
'', self.trans.GetDescription() )
84 def test_findsplit(self):
87 self.split.SetAccount( ACCT )
88 SPLIT = self.trans.FindSplitByAccount( ACCT )
89 self.assertTrue( SPLIT.Equal(self.
split,
True,
False,
False) )
91 def test_getsplit(self):
92 SPLIT = self.trans.GetSplit(0)
93 self.assertTrue( SPLIT.Equal(self.
split,
True,
False,
False) )
95 def test_getsplitindex(self):
96 self.assertEquals( 0, self.trans.GetSplitIndex(self.
split) )
98 def test_countsplits(self):
99 self.assertEquals( 1, self.trans.CountSplits() )
101 def test_readonly(self):
102 self.assertEquals(
None, self.trans.GetReadOnly() )
104 self.trans.SetReadOnly(REASON)
105 self.assertEquals( REASON, self.trans.GetReadOnly() )
106 self.trans.ClearReadOnly()
107 self.assertEquals(
None, self.trans.GetReadOnly() )
109 def test_txntype(self):
110 self.assertEquals(
'\x00', self.trans.GetTxnType() )
112 self.trans.SetTxnType(TYPE)
113 self.assertEquals( TYPE, self.trans.GetTxnType() )
115 self.trans.SetTxnType(TYPE)
116 self.assertEquals( TYPE, self.trans.GetTxnType() )
120 self.assertEquals(
'', self.trans.GetNum() )
121 self.trans.SetNum(NUM)
122 self.assertEquals( NUM, self.trans.GetNum() )
124 def test_description(self):
126 self.assertEquals(
'', self.trans.GetDescription() )
127 self.trans.SetDescription(DESCR)
128 self.assertEquals( DESCR, self.trans.GetDescription() )
130 def test_notes(self):
131 NOTE =
'For dinner party'
132 self.assertEquals(
None, self.trans.GetNotes() )
133 self.trans.SetNotes(NOTE)
134 self.assertEquals( NOTE, self.trans.GetNotes() )
136 if __name__ ==
'__main__':
struct account_s Account
Account in Gnucash. This is the typename for an account. The actual structure is defined in the priva...
struct split_s Split
Split in Gnucash. A "split" is more commonly referred to as a "entry" in a "transaction". Each split belongs to one Account and one Transaction. The split is one out of several parts a Transaction is divided into.
struct transaction_s Transaction
Transaction in Gnucash. A Transaction is a piece of business done; the transfer of money from one acc...