1 from unittest
import main
3 from gnucash
import Transaction, Book, Account, Split
4 from unittest_support
import *
5 from datetime
import datetime, timezone
7 from test_book
import BookSession
12 self.
domain2 =
"gnc.engine.scrub" 13 level = G_LOG_LEVEL_CRITICAL
15 check1.log_domain = self.
domain1 16 check1.log_level = level
17 check1.msg =
"[xaccScrubUtilityGetOrMakeAccount()] No currency specified!" 18 test_add_error(check1)
20 check2.log_domain = self.
domain1 21 check2.log_level = level
22 check2.msg =
"[xaccTransScrubSplits()] Transaction doesn't have a currency!" 23 test_add_error(check2)
24 self.
hdlr1 = test_set_list_handler(self.
domain1, level,
None)
26 check3.log_domain =
"gnc.engine.scrub" 27 check3.log_level = level
28 check3.msg =
"[xaccScrubUtilityGetOrMakeAccount()] No currency specified!" 29 self.
hdlr2 = test_set_checked_handler(self.
domain2, level, check3)
30 BookSession.setUp(self)
42 test_clear_error_list ()
47 self.assertTrue( TRANS.Equal(self.
trans,
True,
False,
False,
False) )
49 SPLIT = Split(self.
book)
50 SPLIT.SetParent(TRANS)
51 self.assertTrue( self.
trans == SPLIT.GetParent() )
52 self.assertTrue( self.
trans != Transaction(self.
book) )
56 level = G_LOG_LEVEL_WARNING
58 check.log_domain = domain
59 check.log_level = level
60 check.msg =
"[xaccTransEqual()] GUIDs differ" 61 hdlr = test_set_checked_handler(domain, level, check)
63 TRANS = self.
trans.Clone()
65 self.assertFalse( TRANS.Equal(self.
trans,
True,
False,
False,
False) )
67 self.assertTrue( TRANS.Equal(self.
trans,
False,
False,
True,
False) )
69 g_log_remove_handler(domain, hdlr)
71 def test_setcurrency(self):
72 self.assertTrue( self.
currency.equal( self.
trans.GetCurrency() ) )
75 self.assertFalse( self.
trans.IsOpen() )
76 self.
trans.BeginEdit()
77 self.assertTrue( self.
trans.IsOpen() )
78 self.
trans.CommitEdit()
79 self.assertFalse( self.
trans.IsOpen() )
81 def test_rollback(self):
82 self.assertEqual(
'', self.
trans.GetDescription() )
83 self.
trans.BeginEdit()
85 self.
trans.SetDescription(DESC)
86 self.assertEqual( DESC, self.
trans.GetDescription() )
87 self.
trans.RollbackEdit()
88 self.assertEqual(
'', self.
trans.GetDescription() )
90 def test_findsplit(self):
91 ACCT = Account(self.
book)
93 self.
split.SetAccount( ACCT )
94 SPLIT = self.
trans.FindSplitByAccount( ACCT )
95 self.assertTrue( SPLIT.Equal(self.
split,
True,
False,
False) )
97 def test_getsplit(self):
98 SPLIT = self.
trans.GetSplit(0)
99 self.assertTrue( SPLIT.Equal(self.
split,
True,
False,
False) )
101 def test_getsplitindex(self):
102 self.assertEqual( 0, self.
trans.GetSplitIndex(self.
split) )
104 def test_countsplits(self):
105 self.assertEqual( 1, self.
trans.CountSplits() )
107 def test_readonly(self):
108 self.assertEqual(
None, self.
trans.GetReadOnly() )
110 self.
trans.SetReadOnly(REASON)
111 self.assertEqual( REASON, self.
trans.GetReadOnly() )
112 self.
trans.ClearReadOnly()
113 self.assertEqual(
None, self.
trans.GetReadOnly() )
117 self.assertEqual(
'', self.
trans.GetNum() )
118 self.
trans.SetNum(NUM)
119 self.assertEqual( NUM, self.
trans.GetNum() )
121 def test_description(self):
123 self.assertEqual(
'', self.
trans.GetDescription() )
124 self.
trans.SetDescription(DESCR)
125 self.assertEqual( DESCR, self.
trans.GetDescription() )
127 def test_notes(self):
128 NOTE =
'For dinner party' 129 self.assertEqual(
None, self.
trans.GetNotes() )
130 self.
trans.SetNotes(NOTE)
131 self.assertEqual( NOTE, self.
trans.GetNotes() )
134 ZERODATE=datetime(1970, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
135 DATE=datetime(2020, 2, 20, 10, 59, 0, tzinfo=timezone.utc)
136 self.assertEqual(ZERODATE, self.
trans.GetDate().astimezone(timezone.utc))
137 self.
trans.SetDate(DATE.day, DATE.month, DATE.year)
138 self.assertEqual(DATE, self.
trans.GetDate().astimezone(timezone.utc))
140 if __name__ ==
'__main__':
Struct to pass as user_data for the handlers.