def __init__(self, response, debug=False): # Bank of America (California) seems to be putting out bad Content-type # headers on manual OFX download. I'm special-casing this out since # B of A is such a large bank. # REVIEW: Check later to see if this is still needed, espcially once # B of A is mechanized. # REVIEW: Checked. Still needed. Feh! if not isinstance(response, str): response = response.decode('utf-8') self.raw_response = response self.raw_response = self.raw_response.replace( 'Content- type:application/ofx', "") # Good god, another one. Regex? self.raw_response = self.raw_response.replace( 'Content-Type: application/x-ofx', "") # I'm seeing this a lot, so here's an ugly workaround. I wonder why multiple # FIs are causing it, though. self.raw_response = self.raw_response.replace( '****OFX download terminated due to exception: Null or zero length FITID****', '') parser = Parser(debug) self.parse_dict = parser.parse(self.raw_response) self.ofx = self.parse_dict["body"]["OFX"][0].asDict()
def setUp(self): parser = Parser() checking_stmt = get_checking_stmt() creditcard_stmt = get_creditcard_stmt() blank_memo_stmt = get_blank_memo_stmt() self.checkparse = parser.parse(checking_stmt) self.creditcardparse = parser.parse(creditcard_stmt) self.blank_memoparse = parser.parse(blank_memo_stmt)
def setUp(self): self.request = Request() self.institution = Institution(ofx_org="fi_name", ofx_fid="1000") self.account = Account(acct_number="00112233", aba_number="12345678", acct_type="Checking", institution=self.institution) self.username = "******" self.password = "******" self.parser = Parser()
def __init__(self, response, debug=False): # Bank of America (California) seems to be putting out bad Content-type # headers on manual OFX download. I'm special-casing this out since # B of A is such a large bank. # REVIEW: Check later to see if this is still needed, espcially once # B of A is mechanized. # REVIEW: Checked. Still needed. Feh! if not isinstance(response, str): response = response.decode('utf-8') self.raw_response = response self.raw_response = self.raw_response.replace('Content- type:application/ofx', "") # Good god, another one. Regex? self.raw_response = self.raw_response.replace('Content-Type: application/x-ofx', "") # I'm seeing this a lot, so here's an ugly workaround. I wonder why multiple # FIs are causing it, though. self.raw_response = self.raw_response.replace('****OFX download terminated due to exception: Null or zero length FITID****', '') parser = Parser(debug) self.parse_dict = parser.parse(self.raw_response) self.ofx = self.parse_dict["body"]["OFX"][0].asDict()
class RequestTests(unittest.TestCase): def setUp(self): self.request = Request() self.institution = Institution(ofx_org="fi_name", ofx_fid="1000") self.account = Account(acct_number="00112233", aba_number="12345678", acct_type="Checking", institution=self.institution) self.username = "******" self.password = "******" self.parser = Parser() # FIXME: Need to add tests for date formatting. def test_header(self): """Test the correctness of an OFX document header by examining some of the dynamically-generated values at the bottom of the header. This test uses a bank statement request, since that is our most common use, and since that will build a full, parsable document, including the header.""" parsetree = self.parser.parse(self.request.bank_stmt(self.account, self.username, self.password)) self.assertEqual("NONE", parsetree["header"]["OLDFILEUID"]) self.assertNotEqual("NONE", parsetree["header"]["NEWFILEUID"]) def test_sign_on(self): """Test the OFX document sign-on block, using a bank statement request again.""" parsetree = self.parser.parse(self.request.bank_stmt(self.account, self.username, self.password)) # FIXME: add DTCLIENT test here. signon = parsetree["body"]["OFX"]["SIGNONMSGSRQV1"]["SONRQ"] self.assertEqual("joeuser", signon["USERID"]) self.assertEqual("mypasswd", signon["USERPASS"]) self.assertEqual("fi_name", signon["FI"]["ORG"]) self.assertEqual("1000", signon["FI"]["FID"]) self.assertEqual("Money", signon["APPID"]) self.assertEqual("1400", signon["APPVER"]) def test_account_info(self): """Test the values sent for an account info request.""" parsetree = self.parser.parse(self.request.account_info(self.institution, self.username, self.password)) info = parsetree["body"]["OFX"]["SIGNUPMSGSRQV1"]["ACCTINFOTRNRQ"] self.assertNotEqual("NONE", info["TRNUID"]) self.assertEqual("4", info["CLTCOOKIE"]) self.assertEqual("19980101", info["ACCTINFORQ"]["DTACCTUP"]) def test_bank_stmt(self): """Test the specific values for a bank statement request.""" parsetree = self.parser.parse(self.request.bank_stmt(self.account, self.username, self.password)) stmt = parsetree["body"]["OFX"]["BANKMSGSRQV1"]["STMTTRNRQ"] self.assertNotEqual("NONE", stmt["TRNUID"]) self.assertEqual("4", stmt["CLTCOOKIE"]) self.assertEqual("12345678", stmt["STMTRQ"]["BANKACCTFROM"]["BANKID"]) self.assertEqual("00112233", stmt["STMTRQ"]["BANKACCTFROM"]["ACCTID"]) self.assertEqual("CHECKING",stmt["STMTRQ"]["BANKACCTFROM"]["ACCTTYPE"]) # FIXME: Add DTSTART and DTEND tests here. def test_creditcard_stmt(self): """Test the specific values for a credit card statement request.""" self.account.acct_number = "412345678901" parsetree = self.parser.parse(self.request.creditcard_stmt(self.account, self.username, self.password)) stmt = parsetree["body"]["OFX"]["CREDITCARDMSGSRQV1"]["CCSTMTTRNRQ"] self.assertNotEqual("NONE", stmt["TRNUID"]) self.assertEqual("4", stmt["CLTCOOKIE"]) self.assertEqual("412345678901", stmt["CCSTMTRQ"]["CCACCTFROM"]["ACCTID"])