def test_creation_duplicates(self): p = Portfolio(name='Avanza', currency='SEK').save() a_date = datetime.date(2001, 1, 3) pos = Position(symbol='AAPL', currency='SEK', currency_rate=1.0, enter_date=a_date, enter_price=5000.0, enter_commission=99.0, shares=1000.0, portfolio=p) pos.save() self.assertRaises(Exception, pos.save)
def test_delete_all(self): p = Portfolio(name='Avanza', currency='SEK').save() a_date = datetime.date(2001, 1, 3) pos = Position(symbol='AAPL', currency='SEK', currency_rate=1.0, enter_date=a_date, enter_price=5000.0, enter_commission=99.0, shares=1000.0, portfolio=p) pos.save() Position.delete_all() fetched_model = Position.load( symbol='AAPL', enter_date=a_date, portfolio=p) self.assertFalse(fetched_model)