def test_apostrophe(self): ofxpath = os.path.join('fixtures', 'apostrophe.ofx') ofx = OfxSynchronizer.parse_file(ofxpath) sync = OfxSynchronizer(self.lgr) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) self.assertEquals(len(txns), 1)
def test_one_settleDate(self): ofxpath = os.path.join('fixtures', 'fidelity-one-dtsettle.ofx') ofx = OfxSynchronizer.parse_file(ofxpath) sync = OfxSynchronizer(self.lgr) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) self.assertEquals(len(txns), 17)
def test_fresh_sync(self): ledger = Ledger(os.path.join('fixtures', 'empty.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxParser.parse(file(os.path.join('fixtures', 'checking.ofx'))) txns1 = ofx.account.statement.transactions txns2 = sync.filter(ofx) self.assertEqual(txns1, txns2)
def test_no_institution(self): ofxpath = os.path.join('fixtures', 'no-institution.ofx') sync = OfxSynchronizer(self.lgr) ofx = OfxSynchronizer.parse_file(ofxpath) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) self.assertEquals(len(txns), 3)
def test_all_new_txns(self): ledger = Ledger(os.path.join('fixtures', 'empty.lgr')) acct = Mock() acct.download = Mock( return_value=file(os.path.join('fixtures', 'checking.ofx'))) sync = OfxSynchronizer(ledger) self.assertEqual(len(sync.get_new_txns(acct, 7, 7)[1]), 3)
def sync(ledger, accounts, args): sync = OfxSynchronizer(ledger, shortenaccount=args.shortenaccount) for acct in accounts: try: (ofx, txns) = sync.get_new_txns(acct, resync=args.resync, max_days=args.max) if ofx is not None: converter = make_ofx_converter( account=ofx.account, name=acct.description, ledger=ledger, indent=args.indent, fid=None, unknownaccount=args.unknownaccount, payee_format=args.payee_format, hardcodeaccount=None, shortenaccount=args.shortenaccount, security_list=SecurityList(ofx), date_format=args.date_format, infer_account=args.infer_account) print_results(converter, ofx, ledger, txns, args) except KeyboardInterrupt: raise except BaseException: sys.stderr.write("Caught exception processing %s\n" % (acct.description)) traceback.print_exc(file=sys.stderr)
def import_ofx(ledger, args): sync = OfxSynchronizer(ledger, hardcodeaccount=args.hardcodeaccount, shortenaccount=args.shortenaccount) ofx = OfxSynchronizer.parse_file(args.PATH) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) accountname = args.account if accountname is None: if ofx.account.institution is not None: accountname = "%s:%s" % (ofx.account.institution.organization, ofx.account.account_id) else: accountname = UNKNOWN_BANK_ACCOUNT # build SecurityList (including indexing by CUSIP and ticker symbol) security_list = SecurityList(ofx) converter = make_ofx_converter(account=ofx.account, name=accountname, ledger=ledger, indent=args.indent, fid=args.fid, unknownaccount=args.unknownaccount, payee_format=args.payee_format, hardcodeaccount=args.hardcodeaccount, shortenaccount=args.shortenaccount, security_list=security_list, date_format=args.date_format, infer_account=args.infer_account) print_results(converter, ofx, ledger, txns, args)
def test_comment_txns(self): ledger = Ledger(os.path.join('fixtures', 'empty.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxSynchronizer.parse_file( os.path.join('fixtures', 'comments.ofx')) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) self.assertEqual(len(txns), 1)
def test_sync_order(self): ledger = Ledger(os.path.join('fixtures', 'empty.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxParser.parse( file(os.path.join('fixtures', 'checking_order.ofx'))) txns = sync.filter(ofx) self.assertTrue(txns[0].date < txns[1].date and txns[1].date < txns[2].date)
def test_partial_sync(self): ledger = Ledger(os.path.join('fixtures', 'checking-partial.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxSynchronizer.parse_file( os.path.join('fixtures', 'checking.ofx')) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) self.assertEqual(len(txns), 1)
def test_sync_order(self): ledger = Ledger(os.path.join('fixtures', 'empty.lgr')) sync = OfxSynchronizer(ledger) ofx = OfxParser.parse( open(os.path.join('fixtures', 'checking_order.ofx'))) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) self.assertTrue(txns[0].date < txns[1].date and txns[1].date < txns[2].date)
def test_accented_characters_latin1(self): ofxpath = os.path.join('fixtures', 'accented_characters_latin1.ofx') ofx = OfxSynchronizer.parse_file(ofxpath) sync = OfxSynchronizer(self.lgr) txns = sync.filter(ofx.account.statement.transactions, ofx.account.account_id) converter = OfxConverter(account=ofx.account, name="Foo") self.assertEqual(converter.format_payee(txns[0]), "Virement Interac à: Jean") self.assertEqual(len(txns), 1)
def import_ofx(ledger, args): sync = OfxSynchronizer(ledger, hardcodeaccount=args.hardcodeaccount, shortenaccount=args.shortenaccount) ofx = OfxSynchronizer.parse_file(args.PATH) if args.account != None and len(args.account) != len(ofx.accounts): sys.stderr.write( "number of account name (--account) does not match the number of accounts in the OFX file\n" ) exit(1) account_idx = 0 for account in ofx.accounts: txns = sync.filter(account.statement.transactions, account.account_id) try: accountname = args.account[account_idx] except (IndexError, TypeError): accountname = None if accountname is None: if account.institution is not None: accountname = "%s:%s" % (account.institution.organization, account.account_id) elif args.account_format is not None: accountname = args.account_format.format( account_id=account.account_id, account_type=account.account_type, routing_number=account.routing_number, branch_id=account.branch_id) else: accountname = "%s:%s" % (UNKNOWN_BANK_ACCOUNT, account_idx) # build SecurityList (including indexing by CUSIP and ticker symbol) security_list = SecurityList(ofx) converter = make_ofx_converter( account=account, name=accountname, ledger=ledger, indent=args.indent, fid=args.fid, unknownaccount=args.unknownaccount, payee_format=args.payee_format, hardcodeaccount=args.hardcodeaccount, #TODO shortenaccount=args.shortenaccount, #TODO security_list=security_list) print_results(converter, ofx, ledger, txns, args, account_idx) account_idx += 1
def import_ofx(ledger, args): sync = OfxSynchronizer(ledger) (ofx, txns) = sync.parse_file(args.PATH) accountname = args.account if accountname is None: if ofx.account.institution is not None: accountname = "%s:%s" % (ofx.account.institution.organization, ofx.account.account_id) else: raise EmptyInstitutionException("Institution provided by OFX is \ empty and no accountname supplied!") converter = OfxConverter(account=ofx.account, name=accountname, ledger=ledger, indent=args.indent, fid=args.fid, unknownaccount=args.unknownaccount) print_results(converter, ofx, ledger, txns, args)
def sync(ledger, accounts, args): sync = OfxSynchronizer(ledger) for acct in accounts: try: (ofx, txns) = sync.get_new_txns(acct, resync=args.resync, max_days=args.max) if ofx is not None: converter = OfxConverter(account=ofx.account, name=acct.description, ledger=ledger, indent=args.indent, unknownaccount=args.unknownaccount) print_results(converter, ofx, ledger, txns, args) except KeyboardInterrupt: raise except: sys.stderr.write("Caught exception processing %s" % (acct.description)) traceback.print_exc(file=sys.stderr)
def import_ofx(ledger, args): sync = OfxSynchronizer(ledger, hardcodeaccount=args.hardcodeaccount, shortenaccount=args.shortenaccount) (ofx, txns) = sync.parse_file(args.PATH) accountname = args.account if accountname is None: if ofx.account.institution is not None: accountname = "%s:%s" % (ofx.account.institution.organization, ofx.account.account_id) else: accountname = UNKNOWN_BANK_ACCOUNT converter = OfxConverter(ofx=ofx, name=accountname, ledger=ledger, indent=args.indent, fid=args.fid, unknownaccount=args.unknownaccount, payee_format=args.payee_format, hardcodeaccount=args.hardcodeaccount, shortenaccount=args.shortenaccount) print_results(converter, ofx, ledger, txns, args)
def test_no_institution(self): ofxpath = os.path.join('fixtures', 'no-institution.ofx') OfxSynchronizer(self.lgr).parse_file(ofxpath)
def test_no_institution_no_accountname(self): ofxpath = os.path.join('fixtures', 'no-institution.ofx') (ofx, txns) = OfxSynchronizer(self.lgr).parse_file(ofxpath) OfxConverter(ofx.account, name=None)
def test_partial_sync(self): ledger = Ledger(os.path.join('fixtures', 'checking-partial.lgr')) sync = OfxSynchronizer(ledger) (ofx, txns) = sync.parse_file(os.path.join('fixtures', 'checking.ofx')) self.assertEqual(len(txns), 1)
def test_fully_synced(self): ledger = Ledger(os.path.join('fixtures', 'checking.lgr')) sync = OfxSynchronizer(ledger) (ofx, txns) = sync.parse_file(os.path.join('fixtures', 'checking.ofx')) self.assertEqual(txns, [])
def test_apostrophe(self): ofxpath = os.path.join('fixtures', 'apostrophe.ofx') OfxSynchronizer(self.lgr).parse_file(ofxpath)
def test_one_settleDate(self): ofxpath = os.path.join('fixtures', 'fidelity-one-dtsettle.ofx') OfxSynchronizer(self.lgr).parse_file(ofxpath)
def test_sync_no_ledger(self): acct = Mock() acct.download = Mock( return_value=file(os.path.join('fixtures', 'checking.ofx'))) sync = OfxSynchronizer(None) self.assertEqual(len(sync.get_new_txns(acct, 7, 7)[1]), 3)
def ofx_sync(ledger): return OfxSynchronizer(ledger)
def test_comment_txns(self): ledger = Ledger(os.path.join('fixtures', 'empty.lgr')) sync = OfxSynchronizer(ledger) (ofx, txns) = sync.parse_file(os.path.join('fixtures', 'comments.ofx')) self.assertEqual(len(txns), 1)