def testThatParseTransactionReturnsATransaction(self): input = ''' <STMTTRN><TRNTYPE>POS<DTPOSTED>20090401122017.000[-5:EST]<TRNAMT>-6.60<FITID>0000123456782009040100001<NAME>MCDONALD'S #112<MEMO>POS MERCHANDISE;MCDONALD'S #112</STMTTRN> ''' txn = BeautifulStoneSoup(input) transaction = OfxParser.parseTransaction(txn.find('stmttrn')) self.assertEquals('pos', transaction.type) self.assertEquals(datetime(2009, 4, 1, 12, 20, 17) - timedelta(hours=-5), transaction.date) self.assertEquals(Decimal('-6.60'), transaction.amount) self.assertEquals('0000123456782009040100001', transaction.id) self.assertEquals("MCDONALD'S #112", transaction.payee) self.assertEquals("POS MERCHANDISE;MCDONALD'S #112", transaction.memo)
def testThatParseTransactionReturnsATransaction(self): input = ''' <STMTTRN><TRNTYPE>POS<DTPOSTED>20090401122017.000[-5:EST]<TRNAMT>-6.60<FITID>0000123456782009040100001<NAME>MCDONALD'S #112<MEMO>POS MERCHANDISE;MCDONALD'S #112</STMTTRN> ''' txn = BeautifulStoneSoup(input) transaction = OfxParser.parseTransaction(txn.find('stmttrn')) self.assertEquals('pos', transaction.type) self.assertEquals(datetime(2009, 4, 1, 12, 20, 17) - timedelta(hours=-5), transaction.date) self.assertEquals(Decimal('-6.60'), transaction.amount) self.assertEquals('0000123456782009040100001', transaction.id) self.assertEquals("MCDONALD'S #112", transaction.payee) self.assertEquals("POS MERCHANDISE;MCDONALD'S #112", transaction.memo)
def testThatParseTransactionWithFieldCheckNum(self): input = ''' <STMTTRN> <TRNTYPE>DEP <DTPOSTED>20130306 <TRNAMT>1000.00 <FITID>2013030601009100 <CHECKNUM>700 <MEMO>DEPOSITO ONLINE </STMTTRN> ''' txn = soup_maker(input) transaction = OfxParser.parseTransaction(txn.find('stmttrn')) self.assertEquals('700', transaction.checknum)
def testThatParseTransactionWithCommaAsDecimalPointAndDotAsSeparator(self): input = ''' <STMTTRN> <TRNTYPE>POS <DTPOSTED>20090401122017.000[-5:EST] <TRNAMT>-1.006,60 <FITID>0000123456782009040100001 <NAME>MCDONALD'S #112 <MEMO>POS MERCHANDISE;MCDONALD'S #112 </STMTTRN> ''' txn = soup_maker(input) with self.assertRaises(OfxParserException): transaction = OfxParser.parseTransaction(txn.find('stmttrn'))
def testThatParseTransactionWithCommaAsDecimalPoint(self): input = ''' <STMTTRN> <TRNTYPE>POS <DTPOSTED>20090401122017.000[-5:EST] <TRNAMT>-1006,60 <FITID>0000123456782009040100001 <NAME>MCDONALD'S #112 <MEMO>POS MERCHANDISE;MCDONALD'S #112 </STMTTRN> ''' txn = soup_maker(input) transaction = OfxParser.parseTransaction(txn.find('stmttrn')) self.assertEquals(Decimal('-1006.60'), transaction.amount)
def testThatParseTransactionWithFieldCheckNum(self): input = ''' <STMTTRN> <TRNTYPE>DEP <DTPOSTED>20130306 <TRNAMT>1000.00 <FITID>2013030601009100 <CHECKNUM>700 <MEMO>DEPOSITO ONLINE </STMTTRN> ''' txn = soup_maker(input) transaction = OfxParser.parseTransaction(txn.find('stmttrn')) self.assertEquals('700', transaction.checknum)
def testThatParseTransactionWithCommaAsDecimalPointAndDotAsSeparator(self): input = ''' <STMTTRN> <TRNTYPE>POS <DTPOSTED>20090401122017.000[-5:EST] <TRNAMT>-1.006,60 <FITID>0000123456782009040100001 <NAME>MCDONALD'S #112 <MEMO>POS MERCHANDISE;MCDONALD'S #112 </STMTTRN> ''' txn = soup_maker(input) transaction = OfxParser.parseTransaction(txn.find('stmttrn')) self.assertEqual(Decimal('-1006.60'), transaction.amount)
def testThatParseTransactionWithDotAsDecimalPointAndCommaAsSeparator(self): " The exact opposite of the previous test. Why are numbers so hard?" input = ''' <STMTTRN> <TRNTYPE>POS <DTPOSTED>20090401122017.000[-5:EST] <TRNAMT>-1,006.60 <FITID>0000123456782009040100001 <NAME>MCDONALD'S #112 <MEMO>POS MERCHANDISE;MCDONALD'S #112 </STMTTRN> ''' txn = soup_maker(input) transaction = OfxParser.parseTransaction(txn.find('stmttrn')) self.assertEqual(Decimal('-1006.60'), transaction.amount)
def testThatParseTransactionWithDotAsDecimalPointAndCommaAsSeparator(self): " The exact opposite of the previous test. Why are numbers so hard?" input = ''' <STMTTRN> <TRNTYPE>POS <DTPOSTED>20090401122017.000[-5:EST] <TRNAMT>-1,006.60 <FITID>0000123456782009040100001 <NAME>MCDONALD'S #112 <MEMO>POS MERCHANDISE;MCDONALD'S #112 </STMTTRN> ''' txn = soup_maker(input) transaction = OfxParser.parseTransaction(txn.find('stmttrn')) self.assertEqual(Decimal('-1006.60'), transaction.amount)
def testThatParseTransactionWithSpaces(self): " Parse numbers with a space separating the thousands. " input = ''' <STMTTRN> <TRNTYPE>POS <DTPOSTED>20090401122017.000[-5:EST] <TRNAMT>+1 006,60 <FITID>0000123456782009040100001 <NAME>MCDONALD'S #112 <MEMO>POS MERCHANDISE;MCDONALD'S #112 </STMTTRN> ''' txn = soup_maker(input) transaction = OfxParser.parseTransaction(txn.find('stmttrn')) self.assertEqual(Decimal('1006.60'), transaction.amount)
def testThatParseTransactionWithFieldRefNum(self): input = ''' <STMTTRN> <TRNTYPE>POS <DTPOSTED>20090401122017.000[-5:EST] <TRNAMT>-6.60 <FITID>0000123456782009040100001 <NAME>MCDONALD'S #112 <MEMO>POS MERCHANDISE;MCDONALD'S #112 <REFNUM>123.456 </STMTTRN> ''' txn = soup_maker(input) transaction = OfxParser.parseTransaction(txn.find('stmttrn')) self.assertEquals("123.456", transaction.refnum)
def testThatParseTransactionReturnsATransaction(self): input = """ <STMTTRN> <TRNTYPE>POS <DTPOSTED>20090401122017.000[-5:EST] <TRNAMT>-6.60 <FITID>0000123456782009040100001 <NAME>MCDONALD'S #112 <MEMO>POS MERCHANDISE;MCDONALD'S #112 </STMTTRN> """ txn = soup_maker(input) transaction = OfxParser.parseTransaction(txn.find("stmttrn")) self.assertEquals("pos", transaction.type) self.assertEquals(datetime(2009, 4, 1, 12, 20, 17) - timedelta(hours=-5), transaction.date) self.assertEquals(Decimal("-6.60"), transaction.amount) self.assertEquals("0000123456782009040100001", transaction.id) self.assertEquals("MCDONALD'S #112", transaction.payee) self.assertEquals("POS MERCHANDISE;MCDONALD'S #112", transaction.memo)
def testThatParseTransactionWithNullAmountIgnored(self): """A null transaction value is converted to 0. Some banks use a null transaction to include interest rate changes on statements. """ input_template = ''' <STMTTRN> <TRNTYPE>DEP <DTPOSTED>20130306 <TRNAMT>{amount} <FITID>2013030601009100 <CHECKNUM>700 <MEMO>DEPOSITO ONLINE </STMTTRN> ''' for amount in ("null", "-null"): input = input_template.format(amount=amount) txn = soup_maker(input) transaction = OfxParser.parseTransaction(txn.find('stmttrn')) self.assertEqual(0, transaction.amount)
def testThatParseTransactionWithNullAmountIgnored(self): """A null transaction value is converted to 0. Some banks use a null transaction to include interest rate changes on statements. """ input_template = ''' <STMTTRN> <TRNTYPE>DEP <DTPOSTED>20130306 <TRNAMT>{amount} <FITID>2013030601009100 <CHECKNUM>700 <MEMO>DEPOSITO ONLINE </STMTTRN> ''' for amount in ("null", "-null"): input = input_template.format(amount=amount) txn = soup_maker(input) transaction = OfxParser.parseTransaction(txn.find('stmttrn')) self.assertEqual(0, transaction.amount)