GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test_transaction.py
1 from unittest import main
2 
3 from gnucash import Transaction, Book, Account, Split
4 from unittest_support import *
5 
6 from test_book import BookSession
7 
9  def setUp(self):
10  self.domain1 = "gnc.engine"
11  self.domain2 = "gnc.engine.scrub"
12  level = G_LOG_LEVEL_CRITICAL
13  check1 = TestErrorStruct()
14  check1.log_domain = self.domain1
15  check1.log_level = level
16  check1.msg = "[xaccScrubUtilityGetOrMakeAccount()] No currency specified!"
17  test_add_error(check1)
18  check2 = TestErrorStruct()
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)
24  check3 = TestErrorStruct()
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)
30  self.trans = Transaction(self.book)
31  #Evil bug means we must set a split for the transaction before making
32  #any other changes (is slightly useful for later tests)
33  self.split = Split(self.book)
34  self.split.SetParent(self.trans)
35  ############
36  self.trans.SetCurrency(self.currency)
37 
38  def tearDown(self):
39  g_log_remove_handler(self.domain1, self.hdlr1)
40  g_log_remove_handler(self.domain2, self.hdlr2)
41  test_clear_error_list ()
42 
44  def test_equal(self):
45  TRANS = self.trans
46  self.assertTrue( TRANS.Equal(self.trans, True, False, False, False) )
47 
48  def test_clone(self):
49  domain = "gnc.engine"
50  level = G_LOG_LEVEL_WARNING
51  check = TestErrorStruct()
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)
56 
57  TRANS = self.trans.Clone()
58  #Clone and original should have different GUIDs
59  self.assertFalse( TRANS.Equal(self.trans, True, False, False, False) )
60  #Clone and original should have the same balance
61  self.assertTrue( TRANS.Equal(self.trans, False, False, True, False) )
62 
63  g_log_remove_handler(domain, hdlr)
64 
65  def test_setcurrency(self):
66  self.assertTrue( self.currency.equal( self.trans.GetCurrency() ) )
67 
68  def test_edit(self):
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() )
74 
75  def test_rollback(self):
76  self.assertEquals( '', self.trans.GetDescription() )
77  self.trans.BeginEdit()
78  DESC = 'Food'
79  self.trans.SetDescription(DESC)
80  self.assertEquals( DESC, self.trans.GetDescription() )
81  self.trans.RollbackEdit()
82  self.assertEquals( '', self.trans.GetDescription() )
83 
84  def test_findsplit(self):
85  ACCT = Account(self.book)
86  ACCT.SetCommodity(self.currency)
87  self.split.SetAccount( ACCT )
88  SPLIT = self.trans.FindSplitByAccount( ACCT )
89  self.assertTrue( SPLIT.Equal(self.split, True, False, False) )
90 
91  def test_getsplit(self):
92  SPLIT = self.trans.GetSplit(0)
93  self.assertTrue( SPLIT.Equal(self.split, True, False, False) )
94 
95  def test_getsplitindex(self):
96  self.assertEquals( 0, self.trans.GetSplitIndex(self.split) )
97 
98  def test_countsplits(self):
99  self.assertEquals( 1, self.trans.CountSplits() )
100 
101  def test_readonly(self):
102  self.assertEquals( None, self.trans.GetReadOnly() )
103  REASON = 'none'
104  self.trans.SetReadOnly(REASON)
105  self.assertEquals( REASON, self.trans.GetReadOnly() )
106  self.trans.ClearReadOnly()
107  self.assertEquals( None, self.trans.GetReadOnly() )
108 
109  def test_txntype(self):
110  self.assertEquals( '\x00', self.trans.GetTxnType() )
111  TYPE = 'I'
112  self.trans.SetTxnType(TYPE)
113  self.assertEquals( TYPE, self.trans.GetTxnType() )
114  TYPE = 'P'
115  self.trans.SetTxnType(TYPE)
116  self.assertEquals( TYPE, self.trans.GetTxnType() )
117 
118  def test_num(self):
119  NUM = '5'
120  self.assertEquals( '', self.trans.GetNum() )
121  self.trans.SetNum(NUM)
122  self.assertEquals( NUM, self.trans.GetNum() )
123 
124  def test_description(self):
125  DESCR = 'Groceries'
126  self.assertEquals( '', self.trans.GetDescription() )
127  self.trans.SetDescription(DESCR)
128  self.assertEquals( DESCR, self.trans.GetDescription() )
129 
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() )
135 
136 if __name__ == '__main__':
137  main()
struct account_s Account
Account in Gnucash. This is the typename for an account. The actual structure is defined in the priva...
Definition: gnc-engine.h:132
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.
Definition: gnc-engine.h:144
struct transaction_s Transaction
Transaction in Gnucash. A Transaction is a piece of business done; the transfer of money from one acc...
Definition: gnc-engine.h:155