def to_xml(self): ofx102 = self.to_ofx102() if self.debug: sys.stderr.write(ofx102 + "\n") sys.stderr.write("Parsing OFX/1.02.\n") response = Response(ofx102, debug=self.debug) if self.debug: sys.stderr.write("Making OFX/2.0.\n") xml = response.as_xml(original_format="OFC") return xml
def to_xml(self): ofx102 = self.to_ofx102() if self.debug: sys.stderr.write(ofx102 + "\n") sys.stderr.write("Parsing OFX/1.02.\n") response = Response(ofx102) #, debug=self.debug) if self.debug: sys.stderr.write("Making OFX/2.0.\n") if self.dayfirst: date_format = "DD/MM/YY" else: date_format = "MM/DD/YY" xml = response.as_xml(original_format="QIF", date_format=date_format) return xml
class ResponseTests(unittest.TestCase): def setUp(self): self.response_text = get_checking_stmt().decode('utf-8') self.response = Response(get_checking_stmt()) def test_signon_success(self): status = self.response.check_signon_status() self.assertTrue(status) def test_account_list(self): statements = self.response.get_statements() self.assertEqual(1, len(statements)) for stmt in statements: self.assertEqual("USD", stmt.get_currency()) self.assertEqual("20100424", stmt.get_begin_date()) self.assertEqual("20100723", stmt.get_end_date()) self.assertEqual("1129.49", stmt.get_balance()) self.assertEqual("20100723", stmt.get_balance_date()) account = stmt.get_account() self.assertEqual("987987987", account.aba_number) self.assertEqual("58152460", account.acct_number) self.assertEqual("CHECKING", account.get_ofx_accttype()) def test_as_xml(self): # First just sanity-check that ElementTree will throw an error # if given a non-XML document. try: response_elem = ElementTree.fromstring(self.response_text) self.fail("Expected parse exception but did not get one.") except: pass # Then see if we can get a real parse success, with no ExpatError. xml = self.response.as_xml() xml_elem = ElementTree.fromstring(xml) self.assertTrue(isinstance(xml_elem, ElementTree.Element)) # Finally, for kicks, try to get a value out of it. org_iter = xml_elem.getiterator("ORG") for org in org_iter: self.assertEqual("FAKEOFX", org.text)
def convert(filecontent, filetype, verbose=False, fid="UNKNOWN", org="UNKNOWN", bankid="UNKNOWN", accttype="UNKNOWN", acctid="UNKNOWN", balance="UNKNOWN", curdef=None, lang="ENG", dayfirst=False, debug=False): text = os.linesep.join(s for s in filecontent.splitlines() if s) # This finishes a verbosity message started by the caller, where the # caller explains the source command-line option and this explains the # source format. if verbose: sys.stderr.write("Converting from %s format.\n" % filetype) if options.debug and (filetype in ["OFC", "QIF"] or filetype.startswith("OFX")): sys.stderr.write("Starting work on raw text:\n") sys.stderr.write(rawtext + "\n\n") if filetype.startswith("OFX/2"): if verbose: sys.stderr.write("No conversion needed; returning unmodified.\n") # The file is already OFX 2 -- return it unaltered, ignoring # any of the parameters passed to this method. return text elif filetype.startswith("OFX"): if verbose: sys.stderr.write("Converting to OFX/2.0...\n") # This will throw a ParseException if it is unable to recognize # the source format. response = Response(text, debug=debug) return response.as_xml(original_format=filetype) elif filetype == "OFC": if verbose: sys.stderr.write("Beginning OFC conversion...\n") converter = OfcConverter(text, fid=fid, org=org, curdef=curdef, lang=lang, debug=debug) # This will throw a ParseException if it is unable to recognize # the source format. if verbose: sys.stderr.write("Converting to OFX/1.02...\n\n%s\n\n" % converter.to_ofx102()) sys.stderr.write("Converting to OFX/2.0...\n") return converter.to_xml() elif filetype == "QIF": if verbose: sys.stderr.write("Beginning QIF conversion...\n") converter = QifConverter(text, fid=fid, org=org, bankid=bankid, accttype=accttype, acctid=acctid, balance=balance, curdef=curdef, lang=lang, dayfirst=dayfirst, debug=debug) # This will throw a ParseException if it is unable to recognize # the source format. if verbose: sys.stderr.write("Converting to OFX/1.02...\n\n%s\n\n" % converter.to_ofx102()) sys.stderr.write("Converting to OFX/2.0...\n") return converter.to_xml() else: raise TypeError("Unable to convert source format '%s'." % filetype)
def test_statement_as_xml(self): response = Response(self.checking) self.assertEqual('<?xml version="1.0"', response.as_xml()[:19])