예제 #1
0
 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()
예제 #2
0
 def get_bank_closing(self, account, username, password):
     """Sends an OFX request for the given user's bank account
     statement, and returns that statement as an OFX document if
     the request is successful."""
     acct_type = account.get_ofx_accttype()
     request = Request()
     self.request_msg = request.bank_closing(account, username, password)
     return self._send_request(account.institution.ofx_url, self.request_msg)
예제 #3
0
 def get_creditcard_closing(self, account, username, password):
     """Sends an OFX request for the given user's credit card
     statement, and returns that statement if the request is
     successful.  If the OFX server returns an error, the client
     will throw an OfxException indicating the error code and
     message."""
     request = Request()
     self.request_msg = request.creditcard_closing(account, username, password)
     return self._send_request(account.institution.ofx_url, self.request_msg)
예제 #4
0
 def get_creditcard_statement(self, account, username, password):
     """Sends an OFX request for the given user's credit card
     statement, and returns that statement if the request is
     successful.  If the OFX server returns an error, the client
     will throw an OfxException indicating the error code and
     message."""
     # See comments in get_bank_statement, above, which explain these try/catch
     # blocks.
     request = Request()
     try:
         self.request_msg = request.creditcard_stmt(account, username, password, daysago=365)
         return self._send_request(account.institution.ofx_url, self.request_msg)
     except Error as detail:
         try:
             self.request_msg = request.creditcard_stmt(account, username, password, daysago=90)
             return self._send_request(account.institution.ofx_url, self.request_msg)
         except Error as detail:
             self.request_msg = request.creditcard_stmt(account, username, password, daysago=30)
             return self._send_request(account.institution.ofx_url, self.request_msg)
예제 #5
0
 def get_bank_statement(self, account, username, password):
     """Sends an OFX request for the given user's bank account
     statement, and returns that statement as an OFX document if
     the request is successful."""
     request = Request()
     # I'm breaking out these retries by statement type since I'm assuming that bank,
     # credit card, and investment OFX servers may each have different behaviors.
     try:
         # First, try to get a statement for the full year.  The USAA and American Express
         # OFX servers return a valid statement, although USAA only includes 90 days and
         # American Express seems to only include back to the first of the year.
         self.request_msg = request.bank_stmt(account, username, password, daysago=365)
         return self._send_request(account.institution.ofx_url, self.request_msg)
     except Error as detail:
         try:
             # If that didn't work, try 90 days back.
             self.request_msg = request.bank_stmt(account, username, password, daysago=90)
             return self._send_request(account.institution.ofx_url, self.request_msg)
         except Error as detail:
             # If that also didn't work, try 30 days back, which has been our default and
             # which always seems to work across all OFX servers.
             self.request_msg = request.bank_stmt(account, username, password, daysago=30)
             return self._send_request(account.institution.ofx_url, self.request_msg)
예제 #6
0
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"])
예제 #7
0
 def get_account_info(self, institution, username, password):
     request = Request()
     self.request_msg = request.account_info(institution, username, password)
     return self._send_request(institution.ofx_url, self.request_msg)
예제 #8
0
 def get_fi_profile(self, institution,
                    username="******",
                    password="******"):
     request = Request()
     self.request_msg = request.fi_profile(institution, username, password)
     return self._send_request(institution.ofx_url, self.request_msg)