コード例 #1
0
ファイル: test_models.py プロジェクト: EliRibble/ofxtools
    def test_sonrs(self):
        sonrs = ofx[0][0]

        # Test missing required elements
        c = deepcopy(sonrs)
        c.remove(c[1]) # dtserver
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(sonrs)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        sonrs = Aggregate.from_etree(sonrs)
        self.assertIsInstance(sonrs, SONRS)
        self.assertEqual(sonrs.code, 0)
        self.assertEqual(sonrs.severity, 'INFO')
        self.assertEqual(sonrs.dtserver, datetime(2005, 10, 29, 10, 10, 03))
        self.assertEqual(sonrs.language, 'ENG')
        self.assertEqual(sonrs.dtprofup, datetime(1999, 10, 29, 10, 10, 03))
        self.assertEqual(sonrs.dtacctup, datetime(2003, 10, 29, 10, 10, 03))
        self.assertEqual(sonrs.org, 'NCH')
        self.assertEqual(sonrs.fid, '1001')
コード例 #2
0
    def test_sonrs(self):
        sonrs = ofx[0][0]

        # Test missing required elements
        c = deepcopy(sonrs)
        c.remove(c[1])  # dtserver
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(sonrs)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        sonrs = Aggregate.from_etree(sonrs)
        self.assertIsInstance(sonrs, SONRS)
        self.assertEqual(sonrs.code, 0)
        self.assertEqual(sonrs.severity, 'INFO')
        self.assertEqual(sonrs.dtserver, datetime(2005, 10, 29, 10, 10, 03))
        self.assertEqual(sonrs.language, 'ENG')
        self.assertEqual(sonrs.dtprofup, datetime(1999, 10, 29, 10, 10, 03))
        self.assertEqual(sonrs.dtacctup, datetime(2003, 10, 29, 10, 10, 03))
        self.assertEqual(sonrs.org, 'NCH')
        self.assertEqual(sonrs.fid, '1001')
コード例 #3
0
ファイル: Response.py プロジェクト: turicas/ofxtools
    def _init(self, stmtrs):
        # BANKTRANLIST
        tranlist = stmtrs.find('BANKTRANLIST')
        if tranlist is not None:
            self.transactions = BANKTRANLIST(tranlist)
        else:
            self.transactions = []

        # LEDGERBAL - mandatory
        self.ledgerbal = Aggregate.from_etree(stmtrs.find('LEDGERBAL'))

        # AVAILBAL
        availbal = stmtrs.find('AVAILBAL')
        if availbal is not None:
            self.availbal = Aggregate.from_etree(availbal)
        else:
            self.availbal = None

        # BALLIST
        ballist = stmtrs.find('BALLIST')
        if ballist:
            self.other_balances = [Aggregate.from_etree(bal) for bal in ballist]
        else:
            self.other_balances = []

        # Unsupported subaggregates
        for tag in ('MKTGINFO', ):
            child = stmtrs.find(tag)
            if child:
                stmtrs.remove
コード例 #4
0
ファイル: Response.py プロジェクト: thonly/ofxtools
    def _init(self, stmtrs):
        # BANKTRANLIST
        tranlist = stmtrs.find('BANKTRANLIST')
        if tranlist is not None:
            self.transactions = BANKTRANLIST(tranlist)
        else:
            self.transactions = []

        # LEDGERBAL - mandatory
        self.ledgerbal = Aggregate.from_etree(stmtrs.find('LEDGERBAL'))

        # AVAILBAL
        availbal = stmtrs.find('AVAILBAL')
        if availbal is not None:
            self.availbal = Aggregate.from_etree(availbal)
        else:
            self.availbal = None

        # BALLIST
        ballist = stmtrs.find('BALLIST')
        if ballist:
            self.other_balances = [
                Aggregate.from_etree(bal) for bal in ballist
            ]
        else:
            self.other_balances = []

        # Unsupported subaggregates
        for tag in ('MKTGINFO', ):
            child = stmtrs.find(tag)
            if child:
                stmtrs.remove
コード例 #5
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
 def testExtraElement(self):
     """
     Adding an extra Element not in the spec makes Aggregate.__init__()
     throw a ValueError.
     """
     root = self.root.copy()
     SubElement(root, 'FAKEELEMENT').text = 'garbage'
     with self.assertRaises(ValueError):
         Aggregate.from_etree(root)
コード例 #6
0
 def testExtraElement(self):
     """
     Adding an extra Element not in the spec makes Aggregate.__init__()
     throw a ValueError.
     """
     root = self.root.copy()
     SubElement(root, 'FAKEELEMENT').text = 'garbage'
     with self.assertRaises(ValueError):
         Aggregate.from_etree(root)
コード例 #7
0
 def testOptional(self):
     if self.optionalElements:
         for tag in self.optionalElements:
             root = self.root.copy()
             parent = root.find('.//%s/..' % tag)
             if parent is None:
                 raise ValueError("Can't find parent of %s" % tag)
             optional = parent.find('./%s' % tag)
             parent.remove(optional)
             Aggregate.from_etree(root)
コード例 #8
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
 def testOptional(self):
     if self.optionalElements:
         for tag in self.optionalElements:
             root = self.root.copy()
             parent = root.find('.//%s/..' % tag)
             if parent is None:
                 raise ValueError("Can't find parent of %s" % tag)
             optional = parent.find('./%s' % tag)
             parent.remove(optional)
             Aggregate.from_etree(root)
コード例 #9
0
    def test_invbal(self):
        invbal = invstmtrs[5]
        # Remove <BALLIST>, which blows up _flatten()
        ballist = invbal[3]
        invbal.remove(ballist)

        # Test missing required elements
        c = deepcopy(invbal)
        c.remove(c[0])  # availcash
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(invbal)
        c.remove(c[1])  # marginbalance
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(invbal)
        c.remove(c[2])  # shortbalance
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(invbal)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        invbal = Aggregate.from_etree(invbal)
        self.assertEqual(invbal.availcash, Decimal('200.00'))
        self.assertEqual(invbal.marginbalance, Decimal('-50.00'))
        self.assertEqual(invbal.shortbalance, Decimal('0'))
コード例 #10
0
ファイル: test_models.py プロジェクト: EliRibble/ofxtools
    def test_invbal(self):
        invbal = invstmtrs[5]
        # Remove <BALLIST>, which blows up _flatten()
        ballist = invbal[3]
        invbal.remove(ballist)

        # Test missing required elements
        c = deepcopy(invbal)
        c.remove(c[0]) # availcash
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(invbal)
        c.remove(c[1]) # marginbalance
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(invbal)
        c.remove(c[2]) # shortbalance
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(invbal)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        invbal = Aggregate.from_etree(invbal)
        self.assertEqual(invbal.availcash, Decimal('200.00'))
        self.assertEqual(invbal.marginbalance, Decimal('-50.00'))
        self.assertEqual(invbal.shortbalance, Decimal('0'))
コード例 #11
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
 def testRequired(self):
     if self.requiredElements:
         for tag in self.requiredElements:
             root = self.root.copy()
             parent = root.find('.//%s/..' % tag)
             if parent is None:
                 raise ValueError("Can't find parent of %s" % tag)
             required = parent.find('./%s' % tag)
             parent.remove(required)
             with self.assertRaises(ValueError):
                 Aggregate.from_etree(root)
コード例 #12
0
 def testRequired(self):
     if self.requiredElements:
         for tag in self.requiredElements:
             root = self.root.copy()
             parent = root.find('.//%s/..' % tag)
             if parent is None:
                 raise ValueError("Can't find parent of %s" % tag)
             required = parent.find('./%s' % tag)
             parent.remove(required)
             with self.assertRaises(ValueError):
                 Aggregate.from_etree(root)
コード例 #13
0
    def oneOfTest(self, tag, texts):
        # Make sure OneOf validator allows all legal values and disallows
        # illegal values
        for text in texts:
            root = self.root.copy()
            target = root.find('.//%s' % tag)
            target.text = text
            Aggregate.from_etree(root)

        root = self.root.copy()
        target = root.find('.//%s' % tag)
        target.text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(root)
コード例 #14
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
    def oneOfTest(self, tag, texts):
        # Make sure OneOf validator allows all legal values and disallows
        # illegal values
        for text in texts:
            root = self.root.copy()
            target = root.find('.//%s' % tag)
            target.text = text
            Aggregate.from_etree(root)

        root = self.root.copy()
        target = root.find('.//%s' % tag)
        target.text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(root)
コード例 #15
0
 def testConvert(self):
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, DEBTINFO)
     self.assertEqual(root.uniqueid, '123456789')
     self.assertEqual(root.uniqueidtype, 'CUSIP')
     self.assertEqual(root.secname, 'Acme Development, Inc.')
     self.assertEqual(root.ticker, 'ACME')
     self.assertEqual(root.fiid, 'AC.ME')
     self.assertEqual(root.rating, 'Aa')
     self.assertEqual(root.unitprice, Decimal('94.5'))
     self.assertEqual(root.dtasof, datetime(2013, 6, 15))
     self.assertEqual(root.cursym, 'USD')
     self.assertEqual(root.currate, Decimal('1.45'))
     self.assertEqual(root.memo, 'Foobar')
     self.assertEqual(root.parvalue, Decimal('1000'))
     self.assertEqual(root.debttype, 'COUPON')
     self.assertEqual(root.debtclass, 'CORPORATE')
     self.assertEqual(root.couponrt, Decimal('5.125'))
     self.assertEqual(root.dtcoupon, datetime(2003, 12, 1))
     self.assertEqual(root.couponfreq, 'QUARTERLY')
     self.assertEqual(root.callprice, Decimal('1000'))
     self.assertEqual(root.yieldtocall, Decimal('6.5'))
     self.assertEqual(root.dtcall, datetime(2005, 12, 15))
     self.assertEqual(root.calltype, 'CALL')
     self.assertEqual(root.yieldtomat, Decimal('6.0'))
     self.assertEqual(root.dtmat, datetime(2006, 12, 15))
     self.assertEqual(root.assetclass, 'INTLBOND')
     self.assertEqual(root.fiassetclass, 'Fixed to floating bond')
コード例 #16
0
ファイル: Response.py プロジェクト: turicas/ofxtools
 def __init__(self, tranlist):
     # Initialize with *TRANLIST Element
     dtstart, dtend = tranlist[0:2]
     tranlist = tranlist[2:]
     self.dtstart = DateTime.convert(dtstart.text)
     self.dtend = DateTime.convert(dtend.text)
     self.extend([Aggregate.from_etree(tran) for tran in tranlist])
コード例 #17
0
ファイル: Response.py プロジェクト: thonly/ofxtools
 def __init__(self, tranlist):
     # Initialize with *TRANLIST Element
     dtstart, dtend = tranlist[0:2]
     tranlist = tranlist[2:]
     self.dtstart = DateTime().convert(dtstart.text)
     self.dtend = DateTime().convert(dtend.text)
     self.extend([Aggregate.from_etree(tran) for tran in tranlist])
コード例 #18
0
 def testConvert(self):
     # Make sure Aggregate.from_etree() calls Element.convert() and sets
     # Aggregate instance attributes with the result
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, INVACCTFROM)
     self.assertEqual(root.brokerid, '111000614')
     self.assertEqual(root.acctid, '123456789123456789')
コード例 #19
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
 def testConvert(self):
     # Make sure Aggregate.from_etree() calls Element.convert() and sets
     # Aggregate instance attributes with the result
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, INVACCTFROM)
     self.assertEqual(root.brokerid, '111000614')
     self.assertEqual(root.acctid, '123456789123456789')
コード例 #20
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
 def testConvert(self):
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, DEBTINFO)
     self.assertEqual(root.uniqueid, '123456789')
     self.assertEqual(root.uniqueidtype, 'CUSIP')
     self.assertEqual(root.secname, 'Acme Development, Inc.')
     self.assertEqual(root.ticker, 'ACME')
     self.assertEqual(root.fiid, 'AC.ME')
     self.assertEqual(root.rating, 'Aa')
     self.assertEqual(root.unitprice, Decimal('94.5'))
     self.assertEqual(root.dtasof, datetime(2013, 6, 15))
     self.assertEqual(root.cursym, 'USD')
     self.assertEqual(root.currate, Decimal('1.45'))
     self.assertEqual(root.memo, 'Foobar')
     self.assertEqual(root.parvalue, Decimal('1000'))
     self.assertEqual(root.debttype, 'COUPON')
     self.assertEqual(root.debtclass, 'CORPORATE')
     self.assertEqual(root.couponrt, Decimal('5.125'))
     self.assertEqual(root.dtcoupon, datetime(2003, 12, 1))
     self.assertEqual(root.couponfreq, 'QUARTERLY')
     self.assertEqual(root.callprice, Decimal('1000'))
     self.assertEqual(root.yieldtocall, Decimal('6.5'))
     self.assertEqual(root.dtcall, datetime(2005, 12, 15))
     self.assertEqual(root.calltype, 'CALL')
     self.assertEqual(root.yieldtomat, Decimal('6.0'))
     self.assertEqual(root.dtmat, datetime(2006, 12, 15))
     self.assertEqual(root.assetclass, 'INTLBOND')
     self.assertEqual(root.fiassetclass, 'Fixed to floating bond')
コード例 #21
0
 def testConvert(self):
     # Make sure Aggregate.from_etree() calls Element.convert() and sets
     # Aggregate instance attributes with the result
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, AVAILBAL)
     self.assertEqual(root.balamt, Decimal('12345.67'))
     self.assertEqual(root.dtasof, datetime(2005, 10, 29, 10, 10, 3))
コード例 #22
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
 def testConvert(self):
     # Make sure Aggregate.from_etree() calls Element.convert() and sets
     # Aggregate instance attributes with the result
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, AVAILBAL)
     self.assertEqual(root.balamt, Decimal('12345.67'))
     self.assertEqual(root.dtasof, datetime(2005, 10, 29, 10, 10, 3))
コード例 #23
0
ファイル: test_models.py プロジェクト: EliRibble/ofxtools
    def test_acctfrom(self):
        acctfrom = invstmtrs[2]

        # Test missing required elements
        c = deepcopy(acctfrom)
        c.remove(c[0]) # brokerid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(acctfrom)
        c.remove(c[1]) # acctid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(acctfrom)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        acctfrom = Aggregate.from_etree(acctfrom)
        self.assertIsInstance(acctfrom, INVACCTFROM)
        self.assertEqual(acctfrom.brokerid, '121099999')
        self.assertEqual(acctfrom.acctid, '999988')
コード例 #24
0
    def test_acctfrom(self):
        acctfrom = invstmtrs[2]

        # Test missing required elements
        c = deepcopy(acctfrom)
        c.remove(c[0])  # brokerid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(acctfrom)
        c.remove(c[1])  # acctid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(acctfrom)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        acctfrom = Aggregate.from_etree(acctfrom)
        self.assertIsInstance(acctfrom, INVACCTFROM)
        self.assertEqual(acctfrom.brokerid, '121099999')
        self.assertEqual(acctfrom.acctid, '999988')
コード例 #25
0
ファイル: Response.py プロジェクト: thonly/ofxtools
 def copyTRNRS(self, trnrs):
     """ Attach the data fields from the *TRNRS wrapper to the STMT """
     self.uid = String(36).convert(trnrs.find('TRNUID').text)
     self.status = Aggregate.from_etree(trnrs.find('STATUS'))
     cltcookie = trnrs.find('CLTCOOKIE')
     if cltcookie is not None:
         self.cookie = String(36).convert(cltcookie.text)
     else:
         self.cookie = None
コード例 #26
0
 def testConvert(self):
     # Make sure Aggregate.from_etree() calls Element.convert() and sets
     # Aggregate instance attributes with the result
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, INVBAL)
     self.assertEqual(root.availcash, Decimal('12345.67'))
     self.assertEqual(root.marginbalance, Decimal('23456.78'))
     self.assertEqual(root.shortbalance, Decimal('34567.89'))
     self.assertEqual(root.buypower, Decimal('45678.90'))
コード例 #27
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
 def testConvert(self):
     # Make sure Aggregate.from_etree() calls Element.convert() and sets
     # Aggregate instance attributes with the result
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, INVBAL)
     self.assertEqual(root.availcash, Decimal('12345.67'))
     self.assertEqual(root.marginbalance, Decimal('23456.78'))
     self.assertEqual(root.shortbalance, Decimal('34567.89'))
     self.assertEqual(root.buypower, Decimal('45678.90'))
コード例 #28
0
ファイル: Response.py プロジェクト: turicas/ofxtools
 def copyTRNRS(self, trnrs):
     """ Attach the data fields from the *TRNRS wrapper to the STMT """
     self.uid = String(36).convert(trnrs.find('TRNUID').text)
     self.status = Aggregate.from_etree(trnrs.find('STATUS'))
     cltcookie = trnrs.find('CLTCOOKIE')
     if cltcookie is not None:
         self.cookie = String(36).convert(cltcookie.text)
     else:
         self.cookie = None
コード例 #29
0
 def testConvert(self):
     # Make sure Aggregate.from_etree() calls Element.convert() and sets
     # Aggregate instance attributes with the result
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, BANKACCTFROM)
     self.assertEqual(root.bankid, '111000614')
     self.assertEqual(root.branchid, '11223344')
     self.assertEqual(root.acctid, '123456789123456789')
     self.assertEqual(root.accttype, 'CHECKING')
     self.assertEqual(root.acctkey, 'DEADBEEF')
コード例 #30
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
 def testConvert(self):
     # Make sure Aggregate.from_etree() calls Element.convert() and sets
     # Aggregate instance attributes with the result
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, BANKACCTFROM)
     self.assertEqual(root.bankid, '111000614')
     self.assertEqual(root.branchid, '11223344')
     self.assertEqual(root.acctid, '123456789123456789')
     self.assertEqual(root.accttype, 'CHECKING')
     self.assertEqual(root.acctkey, 'DEADBEEF')
コード例 #31
0
ファイル: Response.py プロジェクト: thonly/ofxtools
    def _init(self, invstmtrs):
        dtasof = invstmtrs.find('DTASOF').text
        self.datetime = DateTime().convert(dtasof)

        # INVTRANLIST
        tranlist = invstmtrs.find('INVTRANLIST')
        if tranlist is not None:
            self.transactions = INVTRANLIST(tranlist)
        else:
            self.transactions = []

        # INVPOSLIST
        poslist = invstmtrs.find('INVPOSLIST')
        if poslist is not None:
            self.positions = [Aggregate.from_etree(pos) for pos in poslist]
        else:
            self.positions = []

        # INVBAL
        invbal = invstmtrs.find('INVBAL')
        if invbal is not None:
            # First strip off BALLIST & process it
            ballist = invbal.find('BALLIST')
            if ballist is not None:
                invbal.remove(ballist)
                self.other_balances = [
                    Aggregate.from_etree(bal) for bal in ballist
                ]
            else:
                self.other_balances = []
            # Now we can flatten the rest of INVBAL
            self.balances = Aggregate.from_etree(invbal)
        else:
            self.balances = []
            self.other_balances = []

        # Unsupported subaggregates
        for tag in ('INVOOLIST', 'INV401K', 'INV401KBAL', 'MKTGINFO'):
            child = invstmtrs.find(tag)
            if child is not None:
                invstmtrs.remove
コード例 #32
0
 def testConvert(self):
     # Make sure Aggregate.from_etree() calls Element.convert() and sets
     # Aggregate instance attributes with the result
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, BAL)
     self.assertEqual(root.name, 'PETTYCASH')
     self.assertEqual(root.desc, 'Walking around money')
     self.assertEqual(root.baltype, 'DOLLAR')
     self.assertEqual(root.value, Decimal('1234567.89'))
     self.assertEqual(root.dtasof, datetime(2014, 6, 15))
     self.assertEqual(root.cursym, 'USD')
     self.assertEqual(root.currate, Decimal('1.57'))
コード例 #33
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
 def testConvert(self):
     # Make sure Aggregate.from_etree() calls Element.convert() and sets
     # Aggregate instance attributes with the result
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, BAL)
     self.assertEqual(root.name, 'PETTYCASH')
     self.assertEqual(root.desc, 'Walking around money')
     self.assertEqual(root.baltype, 'DOLLAR')
     self.assertEqual(root.value, Decimal('1234567.89'))
     self.assertEqual(root.dtasof, datetime(2014, 6, 15))
     self.assertEqual(root.cursym, 'USD')
     self.assertEqual(root.currate, Decimal('1.57'))
コード例 #34
0
ファイル: Response.py プロジェクト: turicas/ofxtools
    def __init__(self, tree, strict=True):
        """
        Initialize with ofx.ElementTree instance containing parsed OFX.

        The strict argument determines whether to throw an error for certain
        OFX data validation violations.
        """
        # Keep a copy of the parse tree
        self.tree = tree

        # SONRS - server response to signon request
        sonrs = self.tree.find('SIGNONMSGSRSV1/SONRS')
        self.sonrs = Aggregate.from_etree(sonrs, strict=strict)

        # TRNRS - transaction response, which is the main section
        # containing account statements
        self.statements = []

        # N.B. This iteration method doesn't preserve the original
        # ordering of the statements within the OFX response
        for stmtClass in (BankStatement, CreditCardStatement, InvestmentStatement):
            tagname = stmtClass._tagName
            for trnrs in self.tree.findall('*/%sTRNRS' % tagname):
                # *STMTTRNRS may have no *STMTRS (in case of error).
                # Don't blow up; skip silently.
                stmtrs = trnrs.find('%sRS' % tagname)
                if stmtrs is not None:
                    stmt = stmtClass(stmtrs)
                    # Staple the TRNRS wrapper data onto the STMT
                    stmt.copyTRNRS(trnrs)
                    self.statements.append(stmt)

        # SECLIST - list of description of securities referenced by
        # INVSTMT (investment account statement)
        self.securities = []
        seclist = self.tree.find('SECLISTMSGSRSV1/SECLIST')
        if seclist is None:
            return
        for sec in seclist:
            self.securities.append(Aggregate.from_etree(sec, strict=strict))
コード例 #35
0
ファイル: Response.py プロジェクト: turicas/ofxtools
    def _init(self, invstmtrs):
        dtasof = invstmtrs.find('DTASOF').text
        self.datetime = DateTime.convert(dtasof)

        # INVTRANLIST
        tranlist = invstmtrs.find('INVTRANLIST')
        if tranlist is not None:
            self.transactions = INVTRANLIST(tranlist)
        else:
            self.transactions = []

        # INVPOSLIST
        poslist = invstmtrs.find('INVPOSLIST')
        if poslist is not None:
            self.positions = [Aggregate.from_etree(pos) for pos in poslist]
        else:
            self.positions = []

        # INVBAL
        invbal = invstmtrs.find('INVBAL')
        if invbal is not None:
            # First strip off BALLIST & process it
            ballist = invbal.find('BALLIST')
            if ballist is not None:
                invbal.remove(ballist)
                self.other_balances = [Aggregate.from_etree(bal) for bal in ballist]
            else:
                self.other_balances = []
            # Now we can flatten the rest of INVBAL
            self.balances = Aggregate.from_etree(invbal)
        else:
            self.balances = []
            self.other_balances = []

        # Unsupported subaggregates
        for tag in ('INVOOLIST', 'INV401K', 'INV401KBAL', 'MKTGINFO'):
            child = invstmtrs.find(tag)
            if child is not None:
                invstmtrs.remove
コード例 #36
0
ファイル: Response.py プロジェクト: thonly/ofxtools
    def __init__(self, tree):
        """
        Initialize with ofx.ElementTree instance containing parsed OFX.
        """
        # Keep a copy of the parse tree
        self.tree = tree

        # SONRS - server response to signon request
        sonrs = self.tree.find('SIGNONMSGSRSV1/SONRS')
        self.sonrs = Aggregate.from_etree(sonrs)

        # TRNRS - transaction response, which is the main section
        # containing account statements
        self.statements = []

        # N.B. This iteration method doesn't preserve the original
        # ordering of the statements within the OFX response
        for stmtClass in (BankStatement, CreditCardStatement,
                          InvestmentStatement):
            tagname = stmtClass._tagName
            for trnrs in self.tree.findall('*/%sTRNRS' % tagname):
                # *STMTTRNRS may have no *STMTRS (in case of error).
                # Don't blow up; skip silently.
                stmtrs = trnrs.find('%sRS' % tagname)
                if stmtrs is not None:
                    stmt = stmtClass(stmtrs)
                    # Staple the TRNRS wrapper data onto the STMT
                    stmt.copyTRNRS(trnrs)
                    self.statements.append(stmt)

        # SECLIST - list of description of securities referenced by
        # INVSTMT (investment account statement)
        self.securities = []
        seclist = self.tree.find('SECLISTMSGSRSV1/SECLIST')
        if seclist is None:
            return
        for sec in seclist:
            self.securities.append(Aggregate.from_etree(sec))
コード例 #37
0
 def testConvert(self):
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, OTHERINFO)
     self.assertEqual(root.uniqueid, '123456789')
     self.assertEqual(root.uniqueidtype, 'CUSIP')
     self.assertEqual(root.secname, 'Acme Development, Inc.')
     self.assertEqual(root.ticker, 'ACME')
     self.assertEqual(root.fiid, 'AC.ME')
     self.assertEqual(root.rating, 'Aa')
     self.assertEqual(root.unitprice, Decimal('94.5'))
     self.assertEqual(root.dtasof, datetime(2013, 6, 15))
     self.assertEqual(root.cursym, 'USD')
     self.assertEqual(root.currate, Decimal('1.45'))
     self.assertEqual(root.memo, 'Foobar')
     self.assertEqual(root.typedesc, 'Securitized baseball card pool')
     self.assertEqual(root.assetclass, 'SMALLSTOCK')
     self.assertEqual(root.fiassetclass, 'FOO')
コード例 #38
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
 def testConvert(self):
     # Make sure Aggregate.from_etree() calls Element.convert() and sets
     # Aggregate instance attributes with the result
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, SONRS)
     self.assertEqual(root.code, 0)
     self.assertEqual(root.severity, 'INFO')
     self.assertEqual(root.dtserver, datetime(2005, 10, 29, 10, 10, 3))
     self.assertEqual(root.userkey, 'DEADBEEF')
     self.assertEqual(root.tskeyexpire, datetime(2005, 12, 31))
     self.assertEqual(root.language, 'ENG')
     self.assertEqual(root.dtprofup, datetime(2005, 1, 1))
     self.assertEqual(root.dtacctup, datetime(2005, 1, 2))
     self.assertEqual(root.org, 'NCH')
     self.assertEqual(root.fid, '1001')
     self.assertEqual(root.sesscookie, 'BADA55')
     self.assertEqual(root.accesskey, 'CAFEBABE')
コード例 #39
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
 def testConvert(self):
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, OTHERINFO)
     self.assertEqual(root.uniqueid, '123456789')
     self.assertEqual(root.uniqueidtype, 'CUSIP')
     self.assertEqual(root.secname, 'Acme Development, Inc.')
     self.assertEqual(root.ticker, 'ACME')
     self.assertEqual(root.fiid, 'AC.ME')
     self.assertEqual(root.rating, 'Aa')
     self.assertEqual(root.unitprice, Decimal('94.5'))
     self.assertEqual(root.dtasof, datetime(2013, 6, 15))
     self.assertEqual(root.cursym, 'USD')
     self.assertEqual(root.currate, Decimal('1.45'))
     self.assertEqual(root.memo, 'Foobar')
     self.assertEqual(root.typedesc, 'Securitized baseball card pool')
     self.assertEqual(root.assetclass, 'SMALLSTOCK')
     self.assertEqual(root.fiassetclass, 'FOO')
コード例 #40
0
 def testConvert(self):
     # Make sure Aggregate.from_etree() calls Element.convert() and sets
     # Aggregate instance attributes with the result
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, SONRS)
     self.assertEqual(root.code, 0)
     self.assertEqual(root.severity, 'INFO')
     self.assertEqual(root.dtserver, datetime(2005, 10, 29, 10, 10, 3))
     self.assertEqual(root.userkey, 'DEADBEEF')
     self.assertEqual(root.tskeyexpire, datetime(2005, 12, 31))
     self.assertEqual(root.language, 'ENG')
     self.assertEqual(root.dtprofup, datetime(2005, 1, 1))
     self.assertEqual(root.dtacctup, datetime(2005, 1, 2))
     self.assertEqual(root.org, 'NCH')
     self.assertEqual(root.fid, '1001')
     self.assertEqual(root.sesscookie, 'BADA55')
     self.assertEqual(root.accesskey, 'CAFEBABE')
コード例 #41
0
    def test_stockinfo(self):
        stockinfo = seclist[1]

        # Test missing required elements
        c = deepcopy(stockinfo)
        secid = c[0][0]
        secid.remove(secid[0])  # uniqueid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(stockinfo)
        secid = c[0][0]
        secid.remove(secid[1])  # uniqueidtype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(stockinfo)
        secinfo = c[0]
        secinfo.remove(secinfo[1])  # secname
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(stockinfo)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        stockinfo = Aggregate.from_etree(stockinfo)
        self.assertEqual(stockinfo.uniqueid, '666678578')
        self.assertEqual(stockinfo.uniqueidtype, 'CUSIP')
        self.assertEqual(stockinfo.secname, 'Hackson Unlimited, Inc.')
        self.assertEqual(stockinfo.ticker, 'HACK')
        self.assertEqual(stockinfo.fiid, '1027')
        self.assertEqual(stockinfo.yld, Decimal('17'))
        self.assertEqual(stockinfo.assetclass, 'SMALLSTOCK')
コード例 #42
0
ファイル: test_models.py プロジェクト: EliRibble/ofxtools
    def test_stockinfo(self):
        stockinfo = seclist[1]

        # Test missing required elements
        c = deepcopy(stockinfo)
        secid = c[0][0]
        secid.remove(secid[0]) # uniqueid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(stockinfo)
        secid = c[0][0]
        secid.remove(secid[1]) # uniqueidtype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(stockinfo)
        secinfo = c[0]
        secinfo.remove(secinfo[1]) # secname
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(stockinfo)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        stockinfo = Aggregate.from_etree(stockinfo)
        self.assertEqual(stockinfo.uniqueid, '666678578')
        self.assertEqual(stockinfo.uniqueidtype, 'CUSIP')
        self.assertEqual(stockinfo.secname , 'Hackson Unlimited, Inc.')
        self.assertEqual(stockinfo.ticker, 'HACK')
        self.assertEqual(stockinfo.fiid, '1027')
        self.assertEqual(stockinfo.yld, Decimal('17'))
        self.assertEqual(stockinfo.assetclass, 'SMALLSTOCK')
コード例 #43
0
 def testConvert(self):
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, STOCKINFO)
     self.assertEqual(root.uniqueid, '123456789')
     self.assertEqual(root.uniqueidtype, 'CUSIP')
     self.assertEqual(root.secname, 'Acme Development, Inc.')
     self.assertEqual(root.ticker, 'ACME')
     self.assertEqual(root.fiid, 'AC.ME')
     self.assertEqual(root.rating, 'Aa')
     self.assertEqual(root.unitprice, Decimal('94.5'))
     self.assertEqual(root.dtasof, datetime(2013, 6, 15))
     self.assertEqual(root.cursym, 'USD')
     self.assertEqual(root.currate, Decimal('1.45'))
     self.assertEqual(root.memo, 'Foobar')
     self.assertEqual(root.stocktype, 'CONVERTIBLE')
     self.assertEqual(root.yld, Decimal('5.0'))
     self.assertEqual(root.dtyieldasof, datetime(2003, 5, 1))
     self.assertEqual(root.assetclass, 'SMALLSTOCK')
     self.assertEqual(root.fiassetclass, 'FOO')
コード例 #44
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
 def testConvert(self):
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, STOCKINFO)
     self.assertEqual(root.uniqueid, '123456789')
     self.assertEqual(root.uniqueidtype, 'CUSIP')
     self.assertEqual(root.secname, 'Acme Development, Inc.')
     self.assertEqual(root.ticker, 'ACME')
     self.assertEqual(root.fiid, 'AC.ME')
     self.assertEqual(root.rating, 'Aa')
     self.assertEqual(root.unitprice, Decimal('94.5'))
     self.assertEqual(root.dtasof, datetime(2013, 6, 15))
     self.assertEqual(root.cursym, 'USD')
     self.assertEqual(root.currate, Decimal('1.45'))
     self.assertEqual(root.memo, 'Foobar')
     self.assertEqual(root.stocktype, 'CONVERTIBLE')
     self.assertEqual(root.yld, Decimal('5.0'))
     self.assertEqual(root.dtyieldasof, datetime(2003, 5, 1))
     self.assertEqual(root.assetclass, 'SMALLSTOCK')
     self.assertEqual(root.fiassetclass, 'FOO')
コード例 #45
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
    def testConvert(self):
        root = Aggregate.from_etree(self.root)
        self.assertIsInstance(root, MFINFO)
        self.assertEqual(root.uniqueid, '123456789')
        self.assertEqual(root.uniqueidtype, 'CUSIP')
        self.assertEqual(root.secname, 'Acme Development, Inc.')
        self.assertEqual(root.ticker, 'ACME')
        self.assertEqual(root.fiid, 'AC.ME')
        self.assertEqual(root.rating, 'Aa')
        self.assertEqual(root.unitprice, Decimal('94.5'))
        self.assertEqual(root.dtasof, datetime(2013, 6, 15))
        self.assertEqual(root.cursym, 'USD')
        self.assertEqual(root.currate, Decimal('1.45'))
        self.assertEqual(root.memo, 'Foobar')
        self.assertEqual(root.yld, Decimal('5.0'))
        self.assertEqual(root.dtyieldasof, datetime(2003, 5, 1))

        for p in root.mfassetclass:
            self.assertIsInstance(p, PORTION)
        p = root.mfassetclass
        self.assertEqual(p[0].assetclass, 'DOMESTICBOND')
        self.assertEqual(p[0].percent, Decimal('15'))
        self.assertEqual(p[1].assetclass, 'INTLBOND')
        self.assertEqual(p[1].percent, Decimal('15'))
        self.assertEqual(p[2].assetclass, 'LARGESTOCK')
        self.assertEqual(p[2].percent, Decimal('15'))
        self.assertEqual(p[3].assetclass, 'SMALLSTOCK')
        self.assertEqual(p[3].percent, Decimal('15'))
        self.assertEqual(p[4].assetclass, 'INTLSTOCK')
        self.assertEqual(p[4].percent, Decimal('15'))
        self.assertEqual(p[5].assetclass, 'MONEYMRKT')
        self.assertEqual(p[5].percent, Decimal('15'))
        self.assertEqual(p[6].assetclass, 'OTHER')
        self.assertEqual(p[6].percent, Decimal('10'))

        for p in root.fimfassetclass:
            self.assertIsInstance(p, FIPORTION)
        p = root.fimfassetclass
        self.assertEqual(p[0].fiassetclass, 'FOO')
        self.assertEqual(p[0].percent, Decimal('50'))
        self.assertEqual(p[1].fiassetclass, 'BAR')
        self.assertEqual(p[1].percent, Decimal('50'))
コード例 #46
0
    def testConvert(self):
        root = Aggregate.from_etree(self.root)
        self.assertIsInstance(root, MFINFO)
        self.assertEqual(root.uniqueid, '123456789')
        self.assertEqual(root.uniqueidtype, 'CUSIP')
        self.assertEqual(root.secname, 'Acme Development, Inc.')
        self.assertEqual(root.ticker, 'ACME')
        self.assertEqual(root.fiid, 'AC.ME')
        self.assertEqual(root.rating, 'Aa')
        self.assertEqual(root.unitprice, Decimal('94.5'))
        self.assertEqual(root.dtasof, datetime(2013, 6, 15))
        self.assertEqual(root.cursym, 'USD')
        self.assertEqual(root.currate, Decimal('1.45'))
        self.assertEqual(root.memo, 'Foobar')
        self.assertEqual(root.yld, Decimal('5.0'))
        self.assertEqual(root.dtyieldasof, datetime(2003, 5, 1))
        
        for p in root.mfassetclass:
            self.assertIsInstance(p, PORTION)
        p = root.mfassetclass
        self.assertEqual(p[0].assetclass, 'DOMESTICBOND')
        self.assertEqual(p[0].percent, Decimal('15'))
        self.assertEqual(p[1].assetclass, 'INTLBOND')
        self.assertEqual(p[1].percent, Decimal('15'))
        self.assertEqual(p[2].assetclass, 'LARGESTOCK')
        self.assertEqual(p[2].percent, Decimal('15'))
        self.assertEqual(p[3].assetclass, 'SMALLSTOCK')
        self.assertEqual(p[3].percent, Decimal('15'))
        self.assertEqual(p[4].assetclass, 'INTLSTOCK')
        self.assertEqual(p[4].percent, Decimal('15'))
        self.assertEqual(p[5].assetclass, 'MONEYMRKT')
        self.assertEqual(p[5].percent, Decimal('15'))
        self.assertEqual(p[6].assetclass, 'OTHER')
        self.assertEqual(p[6].percent, Decimal('10'))

        for p in root.fimfassetclass:
            self.assertIsInstance(p, FIPORTION)
        p = root.fimfassetclass
        self.assertEqual(p[0].fiassetclass, 'FOO')
        self.assertEqual(p[0].percent, Decimal('50'))
        self.assertEqual(p[1].fiassetclass, 'BAR')
        self.assertEqual(p[1].percent, Decimal('50'))
コード例 #47
0
ファイル: test_models.py プロジェクト: tgoetze/ofxtools
 def testConvert(self):
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, OPTINFO)
     self.assertEqual(root.uniqueid, '123456789')
     self.assertEqual(root.uniqueidtype, 'CUSIP')
     self.assertEqual(root.secname, 'Acme Development, Inc.')
     self.assertEqual(root.ticker, 'ACME')
     self.assertEqual(root.fiid, 'AC.ME')
     self.assertEqual(root.rating, 'Aa')
     self.assertEqual(root.unitprice, Decimal('94.5'))
     self.assertEqual(root.dtasof, datetime(2013, 6, 15))
     self.assertEqual(root.cursym, 'USD')
     self.assertEqual(root.currate, Decimal('1.45'))
     self.assertEqual(root.memo, 'Foobar')
     self.assertEqual(root.opttype, 'CALL')
     self.assertEqual(root.strikeprice, Decimal('25.5'))
     self.assertEqual(root.dtexpire, datetime(2003, 12, 15))
     self.assertEqual(root.shperctrct, 100)
     self.assertEqual(root.assetclass, 'SMALLSTOCK')
     self.assertEqual(root.fiassetclass, 'FOO')
コード例 #48
0
 def testConvert(self):
     root = Aggregate.from_etree(self.root)
     self.assertIsInstance(root, OPTINFO)
     self.assertEqual(root.uniqueid, '123456789')
     self.assertEqual(root.uniqueidtype, 'CUSIP')
     self.assertEqual(root.secname, 'Acme Development, Inc.')
     self.assertEqual(root.ticker, 'ACME')
     self.assertEqual(root.fiid, 'AC.ME')
     self.assertEqual(root.rating, 'Aa')
     self.assertEqual(root.unitprice, Decimal('94.5'))
     self.assertEqual(root.dtasof, datetime(2013, 6, 15))
     self.assertEqual(root.cursym, 'USD')
     self.assertEqual(root.currate, Decimal('1.45'))
     self.assertEqual(root.memo, 'Foobar')
     self.assertEqual(root.opttype, 'CALL')
     self.assertEqual(root.strikeprice, Decimal('25.5'))
     self.assertEqual(root.dtexpire, datetime(2003, 12, 15))
     self.assertEqual(root.shperctrct, 100)
     self.assertEqual(root.assetclass, 'SMALLSTOCK')
     self.assertEqual(root.fiassetclass, 'FOO')
コード例 #49
0
ファイル: Response.py プロジェクト: thonly/ofxtools
 def __init__(self, stmtrs):
     """ Initialize with *STMTRS Element """
     self.currency = stmtrs.find('CURDEF').text
     self.account = Aggregate.from_etree(stmtrs.find(self._acctTag))
     self._init(stmtrs)
コード例 #50
0
    def test_posstock(self):
        posstock = invposlist[0]

        # Test missing required elements
        c = deepcopy(posstock)
        secinfo = c[0][0]
        secinfo.remove(secinfo[0])  # uniqueid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        secinfo = c[0][0]
        secinfo.remove(secinfo[1])  # uniqueidtype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        invpos = c[0]
        invpos.remove(invpos[1])  # heldinacct
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        invpos = c[0]
        invpos.remove(invpos[2])  # postype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        invpos = c[0]
        invpos.remove(invpos[3])  # units
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        invpos = c[0]
        invpos.remove(invpos[4])  # unitprice
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        invpos = c[0]
        invpos.remove(invpos[4])  # mktval
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        invpos = c[0]
        invpos.remove(invpos[4])  # dtpriceasof
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(posstock)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        posstock = Aggregate.from_etree(posstock)
        self.assertEqual(posstock.uniqueid, '123456789')
        self.assertEqual(posstock.uniqueidtype, 'CUSIP')
        self.assertEqual(posstock.heldinacct, 'CASH')
        self.assertEqual(posstock.postype, 'LONG')
        self.assertEqual(posstock.units, Decimal('200'))
        self.assertEqual(posstock.unitprice, Decimal('49.50'))
        self.assertEqual(posstock.mktval, Decimal('9900.00'))
        self.assertEqual(posstock.dtpriceasof, datetime(2005, 8, 27, 1, 0, 0))
        self.assertEqual(posstock.memo, 'Next dividend payable Sept 1')
コード例 #51
0
ファイル: Response.py プロジェクト: turicas/ofxtools
 def __init__(self, stmtrs):
     """ Initialize with *STMTRS Element """
     self.currency = stmtrs.find('CURDEF').text
     self.account = Aggregate.from_etree(stmtrs.find(self._acctTag))
     self._init(stmtrs)
コード例 #52
0
    def test_invtran(self):
        buystock = invtranlist[2]

        # Test missing required elements
        c = deepcopy(buystock)
        invtran = c[0][0]
        invtran.remove(invtran[0])  # fitid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        invtran = c[0][0]
        invtran.remove(invtran[1])  # dttrade
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        secid = c[0][1]
        secid.remove(secid[0])  # uniqueid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        secid = c[0][1]
        secid.remove(secid[1])  # uniqueidtype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        invbuy = c[0]
        invbuy.remove(invbuy[2])  # units
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        invbuy = c[0]
        invbuy.remove(invbuy[3])  # unitprice
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        invbuy = c[0]
        invbuy.remove(invbuy[5])  # total
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        invbuy = c[0]
        invbuy.remove(invbuy[6])  # subacctsec
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        invbuy = c[0]
        invbuy.remove(invbuy[6])  # subacctfund
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        c.remove(c[1])  # buytype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(buystock)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        buystock = Aggregate.from_etree(buystock)
        self.assertEqual(buystock.fitid, '23321')
        self.assertEqual(buystock.dttrade, datetime(2005, 8, 25))
        self.assertEqual(buystock.dtsettle, datetime(2005, 8, 28))
        self.assertEqual(buystock.uniqueid, '123456789')
        self.assertEqual(buystock.uniqueidtype, 'CUSIP')
        self.assertEqual(buystock.units, Decimal('100'))
        self.assertEqual(buystock.unitprice, Decimal('50.00'))
        self.assertEqual(buystock.commission, Decimal('25.00'))
        self.assertEqual(buystock.total, Decimal('-5025.00'))
        self.assertEqual(buystock.subacctsec, 'CASH')
        self.assertEqual(buystock.subacctfund, 'CASH')
コード例 #53
0
ファイル: test_models.py プロジェクト: EliRibble/ofxtools
    def test_optinfo(self):
        optinfo = seclist[2]

        # Test missing required elements
        c = deepcopy(optinfo)
        secid = c[0][0]
        secid.remove(secid[0]) # uniqueid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # @@FIXME - we don't handle two <SECID> aggregates within <OPTINFO>
        c = deepcopy(optinfo)
        secid = c[0][0]
        secid.remove(secid[1]) # uniqueidtype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(optinfo)
        secinfo = c[0]
        secinfo.remove(secinfo[1]) # secname
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(optinfo)
        c.remove(c[1]) # opttype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(optinfo)
        c.remove(c[2]) # strikeprice
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(optinfo)
        c.remove(c[3]) # dtexpire
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(optinfo)
        c.remove(c[4]) # shperctrct
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(optinfo)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        optinfo = Aggregate.from_etree(optinfo)
        self.assertEqual(optinfo.uniqueid, '000342222')
        self.assertEqual(optinfo.uniqueidtype, 'CUSIP')
        self.assertEqual(optinfo.secname , 'Lucky Airlines Jan 97 Put')
        self.assertEqual(optinfo.ticker, 'LUAXX')
        self.assertEqual(optinfo.fiid, '0013')
        self.assertEqual(optinfo.opttype, 'PUT')
        self.assertEqual(optinfo.strikeprice, Decimal('35.00'))
        self.assertEqual(optinfo.dtexpire, datetime(2005, 1, 21))
        self.assertEqual(optinfo.shperctrct, 100)
        self.assertEqual(optinfo.assetclass, 'LARGESTOCK')
コード例 #54
0
    def test_optinfo(self):
        optinfo = seclist[2]

        # Test missing required elements
        c = deepcopy(optinfo)
        secid = c[0][0]
        secid.remove(secid[0])  # uniqueid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # @@FIXME - we don't handle two <SECID> aggregates within <OPTINFO>
        c = deepcopy(optinfo)
        secid = c[0][0]
        secid.remove(secid[1])  # uniqueidtype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(optinfo)
        secinfo = c[0]
        secinfo.remove(secinfo[1])  # secname
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(optinfo)
        c.remove(c[1])  # opttype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(optinfo)
        c.remove(c[2])  # strikeprice
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(optinfo)
        c.remove(c[3])  # dtexpire
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(optinfo)
        c.remove(c[4])  # shperctrct
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(optinfo)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        optinfo = Aggregate.from_etree(optinfo)
        self.assertEqual(optinfo.uniqueid, '000342222')
        self.assertEqual(optinfo.uniqueidtype, 'CUSIP')
        self.assertEqual(optinfo.secname, 'Lucky Airlines Jan 97 Put')
        self.assertEqual(optinfo.ticker, 'LUAXX')
        self.assertEqual(optinfo.fiid, '0013')
        self.assertEqual(optinfo.opttype, 'PUT')
        self.assertEqual(optinfo.strikeprice, Decimal('35.00'))
        self.assertEqual(optinfo.dtexpire, datetime(2005, 1, 21))
        self.assertEqual(optinfo.shperctrct, 100)
        self.assertEqual(optinfo.assetclass, 'LARGESTOCK')
コード例 #55
0
    def test_bal(self):
        bal = invstmtrs[5][3][0]

        # Test missing required elements
        c = deepcopy(bal)
        c.remove(c[0])  # name
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(bal)
        c.remove(c[1])  # desc
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(bal)
        c.remove(c[2])  # baltype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(bal)
        c.remove(c[3])  # value
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(bal)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        bal = Aggregate.from_etree(bal)
        self.assertEqual(bal.name, 'Margin Interest Rate')
        self.assertEqual(bal.desc, 'Current interest rate on margin balances')
        self.assertEqual(bal.baltype, 'PERCENT')
        self.assertEqual(bal.value, Decimal('7.85'))
        self.assertEqual(bal.dtasof, datetime(2005, 8, 27, 1, 0, 0))
コード例 #56
0
ファイル: test_models.py プロジェクト: EliRibble/ofxtools
    def test_invtran(self):
        buystock = invtranlist[2]

        # Test missing required elements
        c = deepcopy(buystock)
        invtran = c[0][0]
        invtran.remove(invtran[0]) # fitid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        invtran = c[0][0]
        invtran.remove(invtran[1]) # dttrade
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        secid = c[0][1]
        secid.remove(secid[0]) # uniqueid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        secid = c[0][1]
        secid.remove(secid[1]) # uniqueidtype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        invbuy = c[0]
        invbuy.remove(invbuy[2]) # units
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        invbuy = c[0]
        invbuy.remove(invbuy[3]) # unitprice
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        invbuy = c[0]
        invbuy.remove(invbuy[5]) # total
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        invbuy = c[0]
        invbuy.remove(invbuy[6]) # subacctsec
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        invbuy = c[0]
        invbuy.remove(invbuy[6]) # subacctfund
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(buystock)
        c.remove(c[1]) # buytype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(buystock)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        buystock = Aggregate.from_etree(buystock)
        self.assertEqual(buystock.fitid, '23321')
        self.assertEqual(buystock.dttrade, datetime(2005, 8, 25))
        self.assertEqual(buystock.dtsettle, datetime(2005, 8, 28))
        self.assertEqual(buystock.uniqueid, '123456789')
        self.assertEqual(buystock.uniqueidtype, 'CUSIP')
        self.assertEqual(buystock.units, Decimal('100'))
        self.assertEqual(buystock.unitprice, Decimal('50.00'))
        self.assertEqual(buystock.commission, Decimal('25.00'))
        self.assertEqual(buystock.total, Decimal('-5025.00'))
        self.assertEqual(buystock.subacctsec, 'CASH')
        self.assertEqual(buystock.subacctfund, 'CASH')
コード例 #57
0
ファイル: test_models.py プロジェクト: EliRibble/ofxtools
    def test_bal(self):
        bal = invstmtrs[5][3][0]

        # Test missing required elements
        c = deepcopy(bal)
        c.remove(c[0]) # name
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(bal)
        c.remove(c[1]) # desc
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(bal)
        c.remove(c[2]) # baltype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(bal)
        c.remove(c[3]) # value
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(bal)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        bal = Aggregate.from_etree(bal)
        self.assertEqual(bal.name, 'Margin Interest Rate')
        self.assertEqual(bal.desc, 'Current interest rate on margin balances')
        self.assertEqual(bal.baltype, 'PERCENT')
        self.assertEqual(bal.value, Decimal('7.85'))
        self.assertEqual(bal.dtasof, datetime(2005, 8, 27, 1, 0, 0))
コード例 #58
0
ファイル: test_models.py プロジェクト: EliRibble/ofxtools
    def test_posopt(self):
        posopt = invposlist[1]

        # Test missing required elements
        c = deepcopy(posopt)
        secinfo = c[0][0]
        secinfo.remove(secinfo[0]) # uniqueid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        secinfo = c[0][0]
        secinfo.remove(secinfo[1]) # uniqueidtype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        invpos = c[0]
        invpos.remove(invpos[1]) # heldinacct
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        invpos = c[0]
        invpos.remove(invpos[2]) # postype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        invpos = c[0]
        invpos.remove(invpos[3]) # units
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        invpos = c[0]
        invpos.remove(invpos[4]) # unitprice
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        invpos = c[0]
        invpos.remove(invpos[4]) # mktval
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        invpos = c[0]
        invpos.remove(invpos[4]) # dtpriceasof
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(posopt)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        posopt = Aggregate.from_etree(posopt)
        self.assertEqual(posopt.uniqueid, '000342222')
        self.assertEqual(posopt.uniqueidtype, 'CUSIP')
        self.assertEqual(posopt.heldinacct, 'CASH')
        self.assertEqual(posopt.postype, 'LONG')
        self.assertEqual(posopt.units, Decimal('1'))
        self.assertEqual(posopt.unitprice, Decimal('5'))
        self.assertEqual(posopt.mktval, Decimal('500'))
        self.assertEqual(posopt.dtpriceasof, datetime(2005, 8, 27, 1, 0, 0))
        self.assertEqual(posopt.memo, 'Option is in the money')
コード例 #59
0
ファイル: test_models.py プロジェクト: EliRibble/ofxtools
    def test_posstock(self):
        posstock = invposlist[0]

        # Test missing required elements
        c = deepcopy(posstock)
        secinfo = c[0][0]
        secinfo.remove(secinfo[0]) # uniqueid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        secinfo = c[0][0]
        secinfo.remove(secinfo[1]) # uniqueidtype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        invpos = c[0]
        invpos.remove(invpos[1]) # heldinacct
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        invpos = c[0]
        invpos.remove(invpos[2]) # postype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        invpos = c[0]
        invpos.remove(invpos[3]) # units
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        invpos = c[0]
        invpos.remove(invpos[4]) # unitprice
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        invpos = c[0]
        invpos.remove(invpos[4]) # mktval
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posstock)
        invpos = c[0]
        invpos.remove(invpos[4]) # dtpriceasof
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(posstock)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        posstock = Aggregate.from_etree(posstock)
        self.assertEqual(posstock.uniqueid, '123456789')
        self.assertEqual(posstock.uniqueidtype, 'CUSIP')
        self.assertEqual(posstock.heldinacct, 'CASH')
        self.assertEqual(posstock.postype, 'LONG')
        self.assertEqual(posstock.units, Decimal('200'))
        self.assertEqual(posstock.unitprice, Decimal('49.50'))
        self.assertEqual(posstock.mktval, Decimal('9900.00'))
        self.assertEqual(posstock.dtpriceasof, datetime(2005, 8, 27, 1, 0, 0))
        self.assertEqual(posstock.memo, 'Next dividend payable Sept 1')
コード例 #60
0
    def test_posopt(self):
        posopt = invposlist[1]

        # Test missing required elements
        c = deepcopy(posopt)
        secinfo = c[0][0]
        secinfo.remove(secinfo[0])  # uniqueid
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        secinfo = c[0][0]
        secinfo.remove(secinfo[1])  # uniqueidtype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        invpos = c[0]
        invpos.remove(invpos[1])  # heldinacct
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        invpos = c[0]
        invpos.remove(invpos[2])  # postype
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        invpos = c[0]
        invpos.remove(invpos[3])  # units
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        invpos = c[0]
        invpos.remove(invpos[4])  # unitprice
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        invpos = c[0]
        invpos.remove(invpos[4])  # mktval
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        c = deepcopy(posopt)
        invpos = c[0]
        invpos.remove(invpos[4])  # dtpriceasof
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Test invalid extra elements
        c = deepcopy(posopt)
        ET.SubElement(c, 'FAKEELEMENT').text = 'garbage'
        with self.assertRaises(ValueError):
            Aggregate.from_etree(c)

        # Make sure Aggregate.from_etree() calls Element.convert() and sets
        # Aggregate instance attributes with the result
        posopt = Aggregate.from_etree(posopt)
        self.assertEqual(posopt.uniqueid, '000342222')
        self.assertEqual(posopt.uniqueidtype, 'CUSIP')
        self.assertEqual(posopt.heldinacct, 'CASH')
        self.assertEqual(posopt.postype, 'LONG')
        self.assertEqual(posopt.units, Decimal('1'))
        self.assertEqual(posopt.unitprice, Decimal('5'))
        self.assertEqual(posopt.mktval, Decimal('500'))
        self.assertEqual(posopt.dtpriceasof, datetime(2005, 8, 27, 1, 0, 0))
        self.assertEqual(posopt.memo, 'Option is in the money')