Пример #1
0
 def testDecimalConversionError(self):
     ''' The test file contains a transaction that has a poorly formatted
     decimal number ($20). Test that we catch this.
     '''
     ofx = OfxParser.parse(open_file('fail_nice/decimal_error.ofx'), False)
     self.assertEquals(len(ofx.account.statement.transactions), 0)
     self.assertEquals(len(ofx.account.statement.discarded_entries), 1)
     
     # Test that it raises an error otherwise.
     self.assertRaises(OfxParserException, OfxParser.parse, open_file('fail_nice/decimal_error.ofx'))
Пример #2
0
 def parse_file(self, _account, f):
     parsed_file = OfxParser.parse(f)
     transactions = []
     for account in parsed_file.accounts:
         transactions.extend(account.statement.transactions)
     try:
         balance = parsed_file.account.statement.balance
     except:
         balance = parsed_file.account.statement.available_balance
     return Statement(_account, transactions, balance)
Пример #3
0
 def testForUnclosedTags(self):
     ofx = OfxParser.parse(open_file('vanguard.ofx'))
     self.assertTrue(hasattr(ofx, 'account'))
     self.assertTrue(hasattr(ofx.account, 'statement'))
     self.assertTrue(hasattr(ofx.account.statement, 'transactions'))
     self.assertEquals(len(ofx.account.statement.transactions), 1)
     self.assertEquals(ofx.account.statement.transactions[0].id, '01234567890.0123.07152011.0')
     self.assertEquals(ofx.account.statement.transactions[0].tradeDate, datetime(2011, 7, 15, 21))
     self.assertEquals(ofx.account.statement.transactions[0].settleDate, datetime(2011, 7, 15, 21))
     self.assertTrue(hasattr(ofx.account.statement, 'positions'))
     self.assertEquals(len(ofx.account.statement.positions), 2)
     self.assertEquals(ofx.account.statement.positions[0].units, Decimal('102.0'))
Пример #4
0
 def testHeaders(self):
     expect = { "OFXHEADER": u"100",
                "DATA": u"OFXSGML",
                "VERSION": u"102",
                "SECURITY": None,
                "ENCODING": u"USASCII",
                "CHARSET": u"1252",
                "COMPRESSION":None,
                "OLDFILEUID": None,
                "NEWFILEUID": None,
                }
     ofx = OfxParser.parse(open_file('bank_medium.ofx'))
     self.assertEquals(expect, ofx.headers)
Пример #5
0
 def testDateFieldMissing(self):
     ''' The test file contains three transactions in a single
     statement. 
     
     They fail due to:
     1) No date
     2) Empty date
     3) Invalid date
     '''
     ofx = OfxParser.parse(open_file('fail_nice/date_missing.ofx'), False)
     self.assertEquals(len(ofx.account.statement.transactions), 0)
     self.assertEquals(len(ofx.account.statement.discarded_entries), 3)
     self.assertEquals(len(ofx.account.statement.warnings), 0)
     
     # Test that it raises an error otherwise.
     self.assertRaises(OfxParserException, OfxParser.parse, open_file('fail_nice/date_missing.ofx'))
Пример #6
0
 def testEverything(self):
     ofx = OfxParser.parse(open_file('bank_medium.ofx'))
     self.assertEquals('12300 000012345678', ofx.account.number)
     self.assertEquals('160000100', ofx.account.routing_number)
     self.assertEquals('CHECKING', ofx.account.account_type)
     self.assertEquals(Decimal('382.34'), ofx.account.statement.balance)
     # Todo: support values in decimal or int form.
     #self.assertEquals('15', ofx.bank_account.statement.balance_in_pennies)
     self.assertEquals(Decimal('682.34'), ofx.account.statement.available_balance)
     self.assertEquals(datetime(2009, 4, 1), ofx.account.statement.start_date)
     self.assertEquals(datetime(2009, 5, 23, 12, 20, 17), ofx.account.statement.end_date)
     
     self.assertEquals(3, len(ofx.account.statement.transactions))
     
     transaction = ofx.account.statement.transactions[0]
     self.assertEquals("MCDONALD'S #112", transaction.payee)
     self.assertEquals('pos', transaction.type)
     self.assertEquals(Decimal('-6.60'), transaction.amount)
Пример #7
0
from ofxparse.ofxparse import OfxParser
from .db import db
from .service import import_ofx
import sys

with open(sys.argv[1], 'rb') as f:
    ofx = OfxParser.parse(f)
    import_ofx(ofx)
    db.session.commit()
Пример #8
0
 def testThatParseReturnsAResultWithABankAccount(self):
     ofx = OfxParser.parse(open_file('bank_medium.ofx'))
     self.assertTrue(ofx.account != None)
Пример #9
0
 def testThatParseWorksWithoutErrors(self):
     OfxParser.parse(open_file('bank_medium.ofx'))
Пример #10
0
 def testThatParseCanCreateAnInvestmentAccount(self):
     OfxParser.parse(StringIO(self.sample))