1from unittest import main
2
3from gnucash import Book, Account, Split, Transaction
4from unittest_support import *
5
6from test_book import BookSession
7
8class SplitSession(BookSession):
9    def setUp(self):
10
11        BookSession.setUp(self)
12        self.split = Split(self.book)
13
14    def tearDown(self):
15        pass
16
17class TestSplit(SplitSession):
18    def test_memo(self):
19        MEMO = "cookie monster"
20        self.assertEqual( '', self.split.GetMemo() )
21        self.split.SetMemo(MEMO)
22        self.assertEqual( MEMO, self.split.GetMemo() )
23
24    def test_account(self):
25        ACCT = Account(self.book)
26        ACCT.SetCommodity(self.currency)
27        self.split.SetAccount(ACCT)
28        self.assertTrue( ACCT.Equal(self.split.GetAccount(), True) )
29
30    def test_transaction(self):
31        domain1 = "gnc.engine.scrub"
32        msg1 = "[xaccScrubUtilityGetOrMakeAccount()] No currency specified!"
33        level = G_LOG_LEVEL_CRITICAL
34        check1 = TestErrorStruct()
35        check1.log_domain = domain1
36        check1.log_level = level
37        check1.msg = msg1
38        hdlr1 = test_set_checked_handler(domain1, level, check1)
39        domain2 = "gnc.engine"
40        msg2 = "[xaccTransScrubSplits()] Transaction doesn't have a currency!"
41        level = G_LOG_LEVEL_CRITICAL
42        check2 = TestErrorStruct()
43        check2.log_domain = domain2
44        check2.log_level = level
45        check2.msg = msg2
46        hdlr2 = test_set_checked_handler(domain2, level, check2)
47
48        TRANS = Transaction(self.book)
49        self.split.SetParent(TRANS)
50        TRANS.SetCurrency(self.currency)
51        TRANS.SetDescription("Foo")
52        self.assertEqual( TRANS.GetDescription(), self.split.GetParent().GetDescription() )
53
54        g_log_remove_handler(domain2, hdlr2)
55        g_log_remove_handler(domain1, hdlr1)
56
57    def test_equal(self):
58        COPY = self.split
59        self.assertTrue( self.split.Equal(COPY, True, False, False) )
60        # test __eq__ implementation
61        TRANS = Transaction(self.book)
62        self.split.SetParent(TRANS)
63        self.assertTrue( self.split == TRANS.GetSplitList()[0] )
64        self.assertTrue( self.split != Split(self.book) )
65
66if __name__ == '__main__':
67    main()
68