Example #1
0
 def test_delete(self):
     rf = ReactiveFramework(StubModel())
     rf.delete()
     self.assertEqual(True, rf.model.delete_called)
Example #2
0
 def test_delete(self):
     rf = ReactiveFramework(StubModel())
     rf.delete()
     self.assertEqual(True, rf.model.delete_called)
    def test_integration(self):
        s = Session()
        s.query(Trade).delete()
        s.query(Portfolio).delete()
        trade_id = self.book_a_trade()
        trades = s.query(Trade).all()
        self.assertEquals( 1, len(trades) )
        self.assertEquals( trade_id, trades[0].trade_id)
        self.assertEquals( 100, trades[0].quantity )
        self.assertEquals( 600, trades[0].price )
        self.assertEquals( "Buy", trades[0].action.value )
        self.assertEquals( "GOOGL.O", trades[0].instrument.name )
        self.assertEquals( "USD", trades[0].currency.name )
        self.assertEquals( date(2015,5,5), trades[0].trade_date )
        self.assertEquals( date(2015,5,7), trades[0].settle_date )
        self.assertEquals( "Fund1", trades[0].portfolio.fund.name )   

        s = Session()
        ports = s.query(Portfolio).all()
        self.assertEquals( 1, len(ports) )
        self.assertEquals( 'Fund1', ports[0].fund.name )
        self.assertEquals( 'Trader1', ports[0].trader.name )
        self.assertEquals( 'Analyst1', ports[0].analyst.name )
        self.assertEquals( 'Broker1', ports[0].broker.name )
        self.assertEquals( 'Clearer1', ports[0].clearer.name )
        self.assertEquals( 'sec1', ports[0].sector )
        self.assertEquals( 'strat1', ports[0].strategy )

        rf = ReactiveFramework(VanillaModel())
        rf.load(trade_id)
        self.assertEquals( 100, rf.get_value('quantity' ))
        self.assertEquals( 600, rf.get_value('price' ))
        self.assertEquals( "Buy", rf.get_value('action' ))
        self.assertEquals( "GOOGL.O", rf.get_value('instrument' ))
        self.assertEquals( "USD", rf.get_value('currency'))
        self.assertEquals( date(2015,5,5), rf.get_value('trade_date' ))
        self.assertEquals( date(2015,5,7), rf.get_value('settle_date' ))
        self.assertEquals( "Fund1", rf.get_value('fund' ))
        self.assertEquals( "Trader1", rf.get_value('trader' ))
        self.assertEquals( "Analyst1", rf.get_value('analyst' ))
        self.assertEquals( "Broker1", rf.get_value('broker' ))
        self.assertEquals( "Clearer1", rf.get_value('clearer' ))
        self.assertEquals( "sec1", rf.get_value('sector' ))
        self.assertEquals( "strat1", rf.get_value('strategy' ))
        
        
        rf.set_value( 'quantity', -140)
        rf.set_value( 'price', 600)
        rf.set_value( 'action', "Sell")
        rf.set_value( 'instrument', "GOOGL.O")
        rf.set_value( 'trade_date', date(2015,5,5))
        rf.set_value( 'fund', "Fund2")
        self.assertEquals({}, rf.validate())
        rf.save()
 
        s = Session()
        trades = s.query(Trade).all()
        self.assertEquals( 1, len(trades) )
        self.assertEquals( -140, trades[0].quantity )
        self.assertEquals( 600, trades[0].price )
        self.assertEquals( "Sell", trades[0].action.value )
        self.assertEquals( "GOOGL.O", trades[0].instrument.name )
        self.assertEquals( "USD", trades[0].currency.name )
        self.assertEquals( date(2015,5,5), trades[0].trade_date )
        self.assertEquals( date(2015,5,7), trades[0].settle_date )
        self.assertEquals( "Fund2", trades[0].portfolio.fund.name )
 
        rf.delete()
        trades = s.query(Trade).all()
        self.assertEquals( 0, len(trades) )
    def test_integration(self):
        s = Session()
        s.query(Trade).delete()
        s.query(Portfolio).delete()
        trade_id = self.book_a_trade()
        trades = s.query(Trade).all()
        self.assertEquals(1, len(trades))
        self.assertEquals(trade_id, trades[0].trade_id)
        self.assertEquals(100, trades[0].quantity)
        self.assertEquals(600, trades[0].price)
        self.assertEquals("Buy", trades[0].action.value)
        self.assertEquals("GOOGL.O", trades[0].instrument.name)
        self.assertEquals("USD", trades[0].currency.name)
        self.assertEquals(date(2015, 5, 5), trades[0].trade_date)
        self.assertEquals(date(2015, 5, 7), trades[0].settle_date)
        self.assertEquals("Fund1", trades[0].portfolio.fund.name)

        s = Session()
        ports = s.query(Portfolio).all()
        self.assertEquals(1, len(ports))
        self.assertEquals('Fund1', ports[0].fund.name)
        self.assertEquals('Trader1', ports[0].trader.name)
        self.assertEquals('Analyst1', ports[0].analyst.name)
        self.assertEquals('Broker1', ports[0].broker.name)
        self.assertEquals('Clearer1', ports[0].clearer.name)
        self.assertEquals('sec1', ports[0].sector)
        self.assertEquals('strat1', ports[0].strategy)

        rf = ReactiveFramework(VanillaModel())
        rf.load(trade_id)
        self.assertEquals(100, rf.get_value('quantity'))
        self.assertEquals(600, rf.get_value('price'))
        self.assertEquals("Buy", rf.get_value('action'))
        self.assertEquals("GOOGL.O", rf.get_value('instrument'))
        self.assertEquals("USD", rf.get_value('currency'))
        self.assertEquals(date(2015, 5, 5), rf.get_value('trade_date'))
        self.assertEquals(date(2015, 5, 7), rf.get_value('settle_date'))
        self.assertEquals("Fund1", rf.get_value('fund'))
        self.assertEquals("Trader1", rf.get_value('trader'))
        self.assertEquals("Analyst1", rf.get_value('analyst'))
        self.assertEquals("Broker1", rf.get_value('broker'))
        self.assertEquals("Clearer1", rf.get_value('clearer'))
        self.assertEquals("sec1", rf.get_value('sector'))
        self.assertEquals("strat1", rf.get_value('strategy'))

        rf.set_value('quantity', -140)
        rf.set_value('price', 600)
        rf.set_value('action', "Sell")
        rf.set_value('instrument', "GOOGL.O")
        rf.set_value('trade_date', date(2015, 5, 5))
        rf.set_value('fund', "Fund2")
        self.assertEquals({}, rf.validate())
        rf.save()

        s = Session()
        trades = s.query(Trade).all()
        self.assertEquals(1, len(trades))
        self.assertEquals(-140, trades[0].quantity)
        self.assertEquals(600, trades[0].price)
        self.assertEquals("Sell", trades[0].action.value)
        self.assertEquals("GOOGL.O", trades[0].instrument.name)
        self.assertEquals("USD", trades[0].currency.name)
        self.assertEquals(date(2015, 5, 5), trades[0].trade_date)
        self.assertEquals(date(2015, 5, 7), trades[0].settle_date)
        self.assertEquals("Fund2", trades[0].portfolio.fund.name)

        rf.delete()
        trades = s.query(Trade).all()
        self.assertEquals(0, len(trades))