Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_investments(self):
with open(os.path.join('fixtures', 'fidelity.ofx'), 'rb') as ofx_file:
ofx = OfxParser.parse(ofx_file)
converter = OfxConverter(
account=ofx.account,
name="Foo",
security_list=SecurityList(ofx))
self.assertEqualLedgerPosting(
converter.convert(
ofx.account.statement.transactions[0]).format(),
"""2012/07/20 YOU BOUGHT
Foo 100.00000 INTC @ $25.635000000
; ofxid: 7776.01234567890.0123456789020201120120720
Assets:Unknown -$2563.50
""")
# test no payee/memo
self.assertEqualLedgerPosting(
converter.convert(
ofx.account.statement.transactions[1]).format(),
def testThatParseWorksWithoutErrors(self):
with open_file('bank_medium.ofx') as f:
OfxParser.parse(f)
def test_investments_custom_payee(self):
with open(os.path.join('fixtures', 'investment_401k.ofx'), 'rb') as ofx_file:
ofx = OfxParser.parse(ofx_file)
converter = OfxConverter(
account=ofx.account,
name="Foo",
payee_format="{txntype}")
self.assertEqual(
converter.format_payee(ofx.account.statement.transactions[1]),
'transfer')
converter = OfxConverter(
account=ofx.account,
name="Foo",
payee_format="{tferaction}")
self.assertEqual(
converter.format_payee(ofx.account.statement.transactions[1]),
'in')
def test_indent(self):
with open(os.path.join('fixtures', 'checking.ofx'), 'rb') as ofx_file:
ofx = OfxParser.parse(ofx_file)
converter = OfxConverter(account=ofx.account, name="Foo", indent=4)
# testing indent, so do not use the string collapsing version of assert
self.assertEqual(
converter.convert(
ofx.account.statement.transactions[0]).format(),
"""2011/03/31 DIVIDEND EARNED FOR PERIOD OF 03/01/2011 THROUGH 03/31/2011 ANNUAL PERCENTAGE YIELD EARNED IS 0.05%
Foo $0.01
def test_fresh_sync(self):
ledger = Ledger(os.path.join('fixtures', 'empty.lgr'))
sync = OfxSynchronizer(ledger)
with open(os.path.join('fixtures', 'checking.ofx'), 'rb') as ofx_file:
ofx = OfxParser.parse(ofx_file)
txns1 = ofx.account.statement.transactions
txns2 = sync.filter(txns1, ofx.account.account_id)
self.assertEqual(txns1, txns2)
def test_balance_assertion(self):
with open(os.path.join('fixtures', 'checking.ofx'), 'rb') as ofx_file:
ofx = OfxParser.parse(ofx_file)
ledger = Ledger(os.path.join('fixtures', 'checking.lgr'))
converter = OfxConverter(
account=ofx.account,
name="Assets:Foo",
ledger=ledger)
self.assertEqualLedgerPosting(
converter.format_balance(
ofx.account.statement),
"""2013/05/25 * --Autosync Balance Assertion
Assets:Foo $0.00 = $100.99
def parse_file(path):
with open(path, 'rb') as ofx_file:
return OfxParser.parse(ofx_file)
def import_qfx(self, user, filename, handle):
""" Import transactions from a qfx file. """
try:
self.files += 1
transactions = []
log.info('Importing transactions qfx file: %s' % filename)
qfx = OfxParser.parse(handle)
fid = int(qfx.account.institution.fid)
if fid not in self._accounts:
raise Exception('Not tracking account fid: %s' % fid)
account = self._accounts[fid]
# Update transactions
for trx in qfx.account.statement.transactions:
trx = trx.__dict__
trx['trxid'] = trx['id']
trx['accountfid'] = fid
if not self._transaction_exists(trx, addit=True):
transactions.append(Transaction(
user=user,
account_id=account.id,
trxid=trx['id'],
payee=trx[account.payee or 'payee'],
amount=trx['amount'],