Example #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'))
Example #2
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'))
Example #3
0
    def testDecimalParsingWithCommas(self):
        # open files
        ofx_standard = OfxParser.parse(open_file('bank_medium.ofx'))
        ofx_w_commas = OfxParser.parse(open_file('bank_medium_with_commas.ofx'))

        # extract transactions
        t1 = list(t.amount for t in ofx_standard.account.statement.transactions)
        t2 = list(t.amount for t in ofx_w_commas.account.statement.transactions)

        # compare
        self.assertEquals(t1, t2)
Example #4
0
    def testSuccess(self):
        ofx = OfxParser.parse(open_file('signon_success.ofx'), True)
        self.assertTrue(ofx.signon.success)
        self.assertEquals(ofx.signon.code, 0)
        self.assertEquals(ofx.signon.severity, 'INFO')
        self.assertEquals(ofx.signon.message, 'Login successful')

        ofx = OfxParser.parse(open_file('signon_success_no_message.ofx'), True)
        self.assertTrue(ofx.signon.success)
        self.assertEquals(ofx.signon.code, 0)
        self.assertEquals(ofx.signon.severity, 'INFO')
        self.assertEquals(ofx.signon.message, '')
Example #5
0
    def testSuccess(self):
        ofx = OfxParser.parse(open_file('signon_success.ofx'), True)
        self.assertTrue(ofx.signon.success)
        self.assertEquals(ofx.signon.code, 0)
        self.assertEquals(ofx.signon.severity, 'INFO')
        self.assertEquals(ofx.signon.message, 'Login successful')

        ofx = OfxParser.parse(open_file('signon_success_no_message.ofx'), True)
        self.assertTrue(ofx.signon.success)
        self.assertEquals(ofx.signon.code, 0)
        self.assertEquals(ofx.signon.severity, 'INFO')
        self.assertEquals(ofx.signon.message, '')
Example #6
0
    def testEmptyBalance(self):
        ''' The test file contains empty or blank strings in the balance
        fields. Fail nicely on those.
        '''
        ofx = OfxParser.parse(open_file('fail_nice/empty_balance.ofx'), False)
        self.assertEquals(len(ofx.account.statement.transactions), 1)
        self.assertEquals(len(ofx.account.statement.discarded_entries), 0)
        self.assertFalse(hasattr(ofx.account.statement, 'balance'))
        self.assertFalse(hasattr(ofx.account.statement, 'available_balance'))

        # Test that it raises an error otherwise.
        self.assertRaises(OfxParserException, OfxParser.parse,
                          open_file('fail_nice/empty_balance.ofx'))
Example #7
0
    def testEmptyBalance(self):
        ''' The test file contains empty or blank strings in the balance
        fields. Fail nicely on those.
        '''
        ofx = OfxParser.parse(open_file('fail_nice/empty_balance.ofx'), False)
        self.assertEquals(len(ofx.account.statement.transactions), 1)
        self.assertEquals(len(ofx.account.statement.discarded_entries), 0)
        self.assertFalse(hasattr(ofx.account.statement, 'balance'))
        self.assertFalse(hasattr(ofx.account.statement, 'available_balance'))

        # Test that it raises an error otherwise.
        self.assertRaises(OfxParserException, OfxParser.parse,
                          open_file('fail_nice/empty_balance.ofx'))
Example #8
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'))
Example #9
0
    def testForFourAccounts(self):
        ofx = OfxParser.parse(open_file('account_listing_aggregation.ofx'))
        self.assertTrue(hasattr(ofx, 'accounts'))
        self.assertEquals(len(ofx.accounts), 4)

        # first account
        account = ofx.accounts[0]
        self.assertEquals(account.account_type, 'SAVINGS')
        self.assertEquals(account.desc, 'USAA SAVINGS')
        self.assertEquals(account.institution.organization, 'USAA')
        self.assertEquals(account.number, '0000000001')
        self.assertEquals(account.routing_number, '314074269')

        # second
        account = ofx.accounts[1]
        self.assertEquals(account.account_type, 'CHECKING')
        self.assertEquals(account.desc, 'FOUR STAR CHECKING')
        self.assertEquals(account.institution.organization, 'USAA')
        self.assertEquals(account.number, '0000000002')
        self.assertEquals(account.routing_number, '314074269')

        # third
        account = ofx.accounts[2]
        self.assertEquals(account.account_type, 'CREDITLINE')
        self.assertEquals(account.desc, 'LINE OF CREDIT')
        self.assertEquals(account.institution.organization, 'USAA')
        self.assertEquals(account.number, '00000000000003')
        self.assertEquals(account.routing_number, '314074269')

        # fourth
        account = ofx.accounts[3]
        self.assertEquals(account.account_type, '')
        self.assertEquals(account.desc, 'MY CREDIT CARD')
        self.assertEquals(account.institution.organization, 'USAA')
        self.assertEquals(account.number, '4111111111111111')
Example #10
0
    def testForFourAccounts(self):
        ofx = OfxParser.parse(open_file("account_listing_aggregation.ofx"))
        self.assertTrue(hasattr(ofx, "accounts"))
        self.assertEquals(len(ofx.accounts), 4)

        # first account
        account = ofx.accounts[0]
        self.assertEquals(account.account_type, "SAVINGS")
        self.assertEquals(account.desc, "USAA SAVINGS")
        self.assertEquals(account.institution.organization, "USAA")
        self.assertEquals(account.number, "0000000001")
        self.assertEquals(account.routing_number, "314074269")

        # second
        account = ofx.accounts[1]
        self.assertEquals(account.account_type, "CHECKING")
        self.assertEquals(account.desc, "FOUR STAR CHECKING")
        self.assertEquals(account.institution.organization, "USAA")
        self.assertEquals(account.number, "0000000002")
        self.assertEquals(account.routing_number, "314074269")

        # third
        account = ofx.accounts[2]
        self.assertEquals(account.account_type, "CREDITLINE")
        self.assertEquals(account.desc, "LINE OF CREDIT")
        self.assertEquals(account.institution.organization, "USAA")
        self.assertEquals(account.number, "00000000000003")
        self.assertEquals(account.routing_number, "314074269")

        # fourth
        account = ofx.accounts[3]
        self.assertEquals(account.account_type, "")
        self.assertEquals(account.desc, "MY CREDIT CARD")
        self.assertEquals(account.institution.organization, "USAA")
        self.assertEquals(account.number, "4111111111111111")
Example #11
0
    def testForFourAccounts(self):
        ofx = OfxParser.parse(open_file('account_listing_aggregation.ofx'))
        self.assertTrue(hasattr(ofx, 'accounts'))
        self.assertEquals(len(ofx.accounts), 4)

        # first account
        account = ofx.accounts[0]
        self.assertEquals(account.account_type, 'SAVINGS')
        self.assertEquals(account.desc, 'USAA SAVINGS')
        self.assertEquals(account.institution.organization, 'USAA')
        self.assertEquals(account.number, '0000000001')
        self.assertEquals(account.routing_number, '314074269')

        # second
        account = ofx.accounts[1]
        self.assertEquals(account.account_type, 'CHECKING')
        self.assertEquals(account.desc, 'FOUR STAR CHECKING')
        self.assertEquals(account.institution.organization, 'USAA')
        self.assertEquals(account.number, '0000000002')
        self.assertEquals(account.routing_number, '314074269')

        # third
        account = ofx.accounts[2]
        self.assertEquals(account.account_type, 'CREDITLINE')
        self.assertEquals(account.desc, 'LINE OF CREDIT')
        self.assertEquals(account.institution.organization, 'USAA')
        self.assertEquals(account.number, '00000000000003')
        self.assertEquals(account.routing_number, '314074269')

        # fourth
        account = ofx.accounts[3]
        self.assertEquals(account.account_type, '')
        self.assertEquals(account.desc, 'MY CREDIT CARD')
        self.assertEquals(account.institution.organization, 'USAA')
        self.assertEquals(account.number, '4111111111111111')
Example #12
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'))
Example #13
0
 def testMultipleAccounts(self):
     ofx = OfxParser.parse(open_file('multiple_accounts2.ofx'))
     self.assertEquals(2, len(ofx.accounts))
     self.assertEquals('9100', ofx.accounts[0].number)
     self.assertEquals('9200', ofx.accounts[1].number)
     self.assertEquals('123', ofx.accounts[0].routing_number)
     self.assertEquals('123', ofx.accounts[1].routing_number)
     self.assertEquals('CHECKING', ofx.accounts[0].account_type)
     self.assertEquals('SAVINGS', ofx.accounts[1].account_type)
Example #14
0
 def testFailure(self):
     ofx = OfxParser.parse(open_file('signon_fail.ofx'), True)
     self.assertFalse(ofx.signon.success)
     self.assertEquals(ofx.signon.code, 15500)
     self.assertEquals(ofx.signon.severity, 'ERROR')
     self.assertEquals(
         ofx.signon.message,
         'Your request could not be processed because you supplied an invalid identification code or your password was incorrect'
     )
Example #15
0
 def testMultipleAccounts(self):
     ofx = OfxParser.parse(open_file('multiple_accounts2.ofx'))
     self.assertEquals(2, len(ofx.accounts))
     self.assertEquals('9100', ofx.accounts[0].number)
     self.assertEquals('9200', ofx.accounts[1].number)
     self.assertEquals('123', ofx.accounts[0].routing_number)
     self.assertEquals('123', ofx.accounts[1].routing_number)
     self.assertEquals('CHECKING', ofx.accounts[0].account_type)
     self.assertEquals('SAVINGS', ofx.accounts[1].account_type)
Example #16
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'))
Example #17
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'))
Example #18
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"))
Example #19
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)
Example #20
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)
Example #21
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(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)
Example #22
0
    def testEverything(self):
        ofx = OfxParser.parse(open_file("bank_medium.ofx"))
        self.assertEquals("12300 000012345678", ofx.bank_account.number)
        self.assertEquals("160000100", ofx.bank_account.routing_number)
        self.assertEquals("382.34", ofx.bank_account.statement.balance)
        # Todo: support values in decimal or int form.
        # self.assertEquals('15', ofx.bank_account.statement.balance_in_pennies)
        self.assertEquals("682.34", ofx.bank_account.statement.available_balance)
        self.assertEquals("20090401", ofx.bank_account.statement.start_date)
        self.assertEquals("20090523122017", ofx.bank_account.statement.end_date)

        self.assertEquals(3, len(ofx.bank_account.statement.transactions))

        transaction = ofx.bank_account.statement.transactions[0]
        self.assertEquals("MCDONALD'S #112", transaction.payee)
        self.assertEquals("pos", transaction.type)
        self.assertEquals("-6.60", transaction.amount)
Example #23
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)
Example #24
0
 def testThatParseReturnsAResultWithABankAccount(self):
     ofx = OfxParser.parse(open_file('bank_medium.ofx'))
     self.assertTrue(ofx.account is not None)
Example #25
0
 def testThatParseWorksWithoutErrors(self):
     OfxParser.parse(open_file('bank_medium.ofx'))
Example #26
0
 def testSecurityListSuccess(self):
     ofx = OfxParser.parse(open_file('fidelity.ofx'))
     self.assertEquals(len(ofx.security_list), 7)
Example #27
0
 def testForUnclosedTags(self):
     ofx = OfxParser.parse(open_file('fidelity.ofx'))
     self.assertTrue(hasattr(ofx.account.statement, 'positions'))
     self.assertEquals(len(ofx.account.statement.positions), 6)
     self.assertEquals(
         ofx.account.statement.positions[0].units, Decimal('128.0'))
Example #28
0
 def testThatParseWorksWithoutErrors(self):
     ofx = OfxParser.parse(open_file("bank_medium.ofx"))
Example #29
0
 def testForUnclosedTags(self):
     ofx = OfxParser.parse(open_file('fidelity.ofx'))
     self.assertTrue(hasattr(ofx.account.statement, 'positions'))
     self.assertEquals(len(ofx.account.statement.positions), 6)
     self.assertEquals(ofx.account.statement.positions[0].units,
                       Decimal('128.0'))
Example #30
0
 def testSecurityListSuccess(self):
     ofx = OfxParser.parse(open_file('fidelity.ofx'))
     self.assertEquals(len(ofx.security_list), 7)
Example #31
0
 def testThatParseWorksWithoutErrors(self):
     OfxParser.parse(open_file('bank_medium.ofx'))
Example #32
0
 def test_write(self):
     test_file = open_file('fidelity.ofx')
     ofx_doc = op.parse(test_file)
     self.assertEqual(str(ofx_doc), "")
Example #33
0
 def testThatParseReturnsAResultWithABankAccount(self):
     ofx = OfxParser.parse(open_file('bank_medium.ofx'))
     self.assertTrue(ofx.account != None)
Example #34
0
 def test_write(self):
     test_file = open_file('fidelity.ofx')
     ofx_doc = op.parse(test_file)
     self.assertEqual(str(ofx_doc), "")
Example #35
0
 def testFailure(self):
     ofx = OfxParser.parse(open_file('signon_fail.ofx'), True)
     self.assertFalse(ofx.signon.success)
     self.assertEquals(ofx.signon.code, 15500)
     self.assertEquals(ofx.signon.severity, 'ERROR')
     self.assertEquals(ofx.signon.message, 'Your request could not be processed because you supplied an invalid identification code or your password was incorrect')