summaryrefslogtreecommitdiff
path: root/ofxhome
diff options
context:
space:
mode:
Diffstat (limited to 'ofxhome')
-rw-r--r--ofxhome/__init__.py7
-rw-r--r--ofxhome/tests/__init__.py0
-rw-r--r--ofxhome/tests/test_suite.py109
3 files changed, 114 insertions, 2 deletions
diff --git a/ofxhome/__init__.py b/ofxhome/__init__.py
index 6ca3aeb..c18a369 100644
--- a/ofxhome/__init__.py
+++ b/ofxhome/__init__.py
@@ -2,7 +2,7 @@ import urllib
from datetime import datetime
from xml.dom.minidom import parseString
-__version__ = '0.3.1'
+__version__ = '0.3.2'
API_URL='http://www.ofxhome.com/api.php'
@@ -61,7 +61,10 @@ def _attr(node,name):
def _text(parent,name):
rc = []
- for node in parent.getElementsByTagName(name)[0].childNodes:
+ elements = parent.getElementsByTagName(name)
+ if not elements:
+ return ''
+ for node in elements[0].childNodes:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
return ''.join(rc)
diff --git a/ofxhome/tests/__init__.py b/ofxhome/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ofxhome/tests/__init__.py
diff --git a/ofxhome/tests/test_suite.py b/ofxhome/tests/test_suite.py
new file mode 100644
index 0000000..92f0b98
--- /dev/null
+++ b/ofxhome/tests/test_suite.py
@@ -0,0 +1,109 @@
+import sys, os, os.path
+from ofxhome import OFXHome, Institution, InstitutionList
+import unittest
+import datetime
+
+class InstitutionTestCase(unittest.TestCase):
+
+ def testGoodParse(self):
+ xml = testfile('scottrade.xml').read()
+ i = Institution(xml)
+ self.assertEquals(i.id,'623')
+ self.assertEquals(i.name,'Scottrade, Inc.')
+ self.assertEquals(i.fid,'777')
+ self.assertEquals(i.org,'Scottrade')
+ self.assertEquals(i.brokerid,'www.scottrade.com')
+ self.assertEquals(i.url,'https://ofxstl.scottsave.com')
+ self.assertEquals(i.ofxfail,'0')
+ self.assertEquals(i.sslfail,'4')
+ self.assertEquals(i.lastofxvalidation,datetime.datetime(2012,8,13,22,28,10))
+ self.assertEquals(i.lastsslvalidation,datetime.datetime(2011,9,28,22,22,22))
+ self.assertEquals(i.xml, xml)
+
+ def testOptionalBroker(self):
+ xml = testfile('jpmorgan.xml').read()
+ i = Institution(xml)
+ self.assertEquals(i.id,'435')
+ self.assertEquals(i.name,'JPMorgan Chase Bank')
+ self.assertEquals(i.fid,'1601')
+ self.assertEquals(i.org,'Chase Bank')
+ self.assertEquals(i.brokerid,'')
+ self.assertEquals(i.url,'https://www.oasis.cfree.com/1601.ofxgp')
+ self.assertEquals(i.ofxfail,'0')
+ self.assertEquals(i.sslfail,'0')
+ self.assertEquals(i.lastofxvalidation,datetime.datetime(2014,8,17,22,23,35))
+ self.assertEquals(i.lastsslvalidation,datetime.datetime(2014,8,17,22,23,34))
+ self.assertEquals(i.xml, xml)
+
+ def testFromFile(self):
+ i = Institution.from_file( testfile_name('scottrade.xml') )
+ self.assertEquals(i.id,'623')
+ self.assertEquals(i['id'],'623')
+
+ def testDictKeys(self):
+ xml = testfile('scottrade.xml').read()
+ i = Institution(xml)
+ self.assertEquals(i['id'],'623')
+ self.assertEquals(i['name'],'Scottrade, Inc.')
+
+ i['id'] = '123'
+ self.assertEquals(i['id'],'123')
+
+ def testBadParse(self):
+ xml = testfile('badxml_bank.xml').read()
+ try:
+ l = Institution(xml)
+ self.assertFalse(0)
+ except Exception:
+ self.assertTrue(1)
+
+class InstitutionListTestCase(unittest.TestCase):
+
+ def testFromFile(self):
+ l = InstitutionList.from_file( testfile_name('search_america.xml') )
+ self.assertEquals(len(l),15)
+
+ def testGoodResult(self):
+ xml = testfile('search_america.xml').read()
+ l = InstitutionList(xml)
+ self.assertEquals(len(l),15)
+ self.assertEquals(l.xml,xml)
+ self.assertEquals(l[0]['id'],'533')
+ self.assertEquals(l[0]['name'],'America First Credit Union')
+
+ def testResultWithPHPError(self):
+ xml = testfile('search_noexist.xml').read()
+ l = InstitutionList(xml)
+ self.assertEquals(len(l),0)
+ self.assertEquals(l.xml,xml)
+
+ def testIterator(self):
+ count = 0
+ xml = testfile('search_america.xml').read()
+ l = InstitutionList(xml)
+ for i in l:
+ count += 1
+ self.assertEquals(count,15)
+
+ def testBadXML(self):
+ xml = testfile('badxml_search.xml').read()
+ try:
+ l = InstitutionList(xml)
+ self.assertFalse(0)
+ except Exception:
+ self.assertTrue(1)
+
+def testfile_name(filename):
+ base_path = os.path.dirname(os.path.abspath(__file__))
+
+ path = os.path.join(base_path,'testfiles',filename)
+ if ('tests' in os.listdir('.')):
+ path = os.path.join('tests',path)
+ return path
+
+def testfile(filename):
+ return file(testfile_name(filename))
+
+
+if __name__ == '__main__':
+ unittest.main()