mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-10-30 18:10:06 -05:00
Promote the OFX/HBCI online_id to named engine accessors:
xaccSplitGetOnlineID / SetOnlineID / HasOnlineID
xaccAccountGetOnlineID / SetOnlineID
The getters return an instance-owned const char* (mirroring
xaccTransGetDocLink / xaccTransGetNotes), so the existing
add_methods_with_prefix auto-wrapper exposes them in the Python bindings
with no .i changes and no %newobject. They write to the same engine KVP
slot ("online_id") the desktop importer uses, so there is no data or
behavior change.
With the accessors in place the gnc_import_*_online_id wrappers in
import-utilities are redundant, so replace every call site (OFX,
AqBanking, and the generic matcher/backend) with them, delete
import-utilities.cpp, and drop the online_id declarations from
import-utilities.h (its importer preference-key macros are retained).
- The engine getters return an instance-owned const char* instead of a
g_strdup'd copy, so callers no longer free the result; the affected
locals are retyped const and their g_free()s dropped.
hash_account_online_ids() g_strdups before inserting, since its hash
table owns its keys (g_free key-destructor).
- xaccAccountSetOnlineID(acc, "") clears the slot, matching the OFX
"delete the online_id" intent (the old wrapper stored an empty string).
- Drop the two unused wrappers: gnc_import_set_trans_online_id (marked
"Not actually used") and gnc_import_trans_has_online_id (no callers).
- Add xaccSplitGet/SetOnlineID to the Split gmock so test-import-backend
links without import-utilities.
81 lines
2.7 KiB
Python
81 lines
2.7 KiB
Python
from unittest import main
|
|
|
|
from gnucash import Book, Account, Split, Transaction
|
|
from unittest_support import *
|
|
|
|
from test_book import BookSession
|
|
|
|
class SplitSession(BookSession):
|
|
def setUp(self):
|
|
|
|
BookSession.setUp(self)
|
|
self.split = Split(self.book)
|
|
|
|
def tearDown(self):
|
|
pass
|
|
|
|
class TestSplit(SplitSession):
|
|
def test_memo(self):
|
|
MEMO = "cookie monster"
|
|
self.assertEqual( '', self.split.GetMemo() )
|
|
self.split.SetMemo(MEMO)
|
|
self.assertEqual( MEMO, self.split.GetMemo() )
|
|
|
|
def test_online_id(self):
|
|
FITID = "20240131-0001-1234567890"
|
|
# Unset online_id reads back as None (no KVP slot present).
|
|
self.assertEqual( None, self.split.GetOnlineID() )
|
|
self.assertFalse( self.split.HasOnlineID() )
|
|
self.split.SetOnlineID(FITID)
|
|
self.assertEqual( FITID, self.split.GetOnlineID() )
|
|
self.assertTrue( self.split.HasOnlineID() )
|
|
# Passing "" (or None) clears it.
|
|
self.split.SetOnlineID("")
|
|
self.assertEqual( None, self.split.GetOnlineID() )
|
|
self.assertFalse( self.split.HasOnlineID() )
|
|
|
|
def test_account(self):
|
|
ACCT = Account(self.book)
|
|
ACCT.SetCommodity(self.currency)
|
|
self.split.SetAccount(ACCT)
|
|
self.assertTrue( ACCT.Equal(self.split.GetAccount(), True) )
|
|
|
|
def test_transaction(self):
|
|
domain1 = "gnc.engine.scrub"
|
|
msg1 = "[xaccScrubUtilityGetOrMakeAccount()] No currency specified!"
|
|
level = G_LOG_LEVEL_CRITICAL
|
|
check1 = TestErrorStruct()
|
|
check1.log_domain = domain1
|
|
check1.log_level = level
|
|
check1.msg = msg1
|
|
hdlr1 = test_set_checked_handler(domain1, level, check1)
|
|
domain2 = "gnc.engine"
|
|
msg2 = "[xaccTransScrubSplits()] Transaction doesn't have a currency!"
|
|
level = G_LOG_LEVEL_CRITICAL
|
|
check2 = TestErrorStruct()
|
|
check2.log_domain = domain2
|
|
check2.log_level = level
|
|
check2.msg = msg2
|
|
hdlr2 = test_set_checked_handler(domain2, level, check2)
|
|
|
|
TRANS = Transaction(self.book)
|
|
self.split.SetParent(TRANS)
|
|
TRANS.SetCurrency(self.currency)
|
|
TRANS.SetDescription("Foo")
|
|
self.assertEqual( TRANS.GetDescription(), self.split.GetParent().GetDescription() )
|
|
|
|
g_log_remove_handler(domain2, hdlr2)
|
|
g_log_remove_handler(domain1, hdlr1)
|
|
|
|
def test_equal(self):
|
|
COPY = self.split
|
|
self.assertTrue( self.split.Equal(COPY, True, False, False) )
|
|
# test __eq__ implementation
|
|
TRANS = Transaction(self.book)
|
|
self.split.SetParent(TRANS)
|
|
self.assertTrue( self.split == TRANS.GetSplitList()[0] )
|
|
self.assertTrue( self.split != Split(self.book) )
|
|
|
|
if __name__ == '__main__':
|
|
main()
|