# Path: intuition/test_utils.py
# class TestPortfolio(PortfolioFactory):
#     ''' Returns minimal portfolio for tests '''
#     initialized = False
# 
#     def initialize(self, properties):
#         self.initialized = True
# 
#     def optimize(self, date, to_buy, to_sell, parameters):
#         if 'raise_fake_error' in parameters:
#             raise ValueError('whatever error')
#         return {'date': date, 'buy': to_buy}, 0, 1


import unittest
import intuition.api.portfolio as portfolio
import dna.test_utils
from nose.tools import raises, ok_, eq_
from intuition.test_utils import TestPortfolio
        eq_(self.pf.date, '2014/12/27')
        eq_(self.pf.perfs, 'fake_perfs')

    def test_overload_optimize(self):
        alloc, e_ret, e_risk = self.pf.optimize(
            date='2014/12/25',
            to_buy={'su.pa': 34.5},
            to_sell={'tec.pa': 45.4},
            parameters={}
        )
        eq_(e_ret, 0)
        eq_(e_risk, 1)
        eq_(alloc['date'], '2014/12/25')
        eq_(alloc['buy'], {'su.pa': 34.5})

    def test_trade_signals_handler(self):
        signals = {
            'buy': {'su.pa': 34.5},
            'sell': {'tec.pa': 45.4}
        }
        alloc = self.pf.trade_signals_handler(signals)
        self.assertIsNone(alloc['date'])
        eq_(alloc['buy'], signals['buy'])

    @raises(portfolio.PortfolioOptimizationFailed)
    def test_error_while_opitmizing(self):
        signals = {
            'buy': {'su.pa': 34.5},
            'sell': {'tec.pa': 45.4}
        }

# Path: intuition/test_utils.py
# class TestPortfolio(PortfolioFactory):
#     ''' Returns minimal portfolio for tests '''
#     initialized = False
# 
#     def initialize(self, properties):
#         self.initialized = True
# 
#     def optimize(self, date, to_buy, to_sell, parameters):
#         if 'raise_fake_error' in parameters:
#             raise ValueError('whatever error')
#         return {'date': date, 'buy': to_buy}, 0, 1


# Path: tests/api/test_portfolio.py
import unittest
import intuition.api.portfolio as portfolio
import dna.test_utils
from nose.tools import raises, ok_, eq_
from intuition.test_utils import TestPortfolio

        eq_(self.pf.date, '2014/12/27')
        eq_(self.pf.perfs, 'fake_perfs')

    def test_overload_optimize(self):
        alloc, e_ret, e_risk = self.pf.optimize(
            date='2014/12/25',
            to_buy={'su.pa': 34.5},
            to_sell={'tec.pa': 45.4},
            parameters={}
        )
        eq_(e_ret, 0)
        eq_(e_risk, 1)
        eq_(alloc['date'], '2014/12/25')
        eq_(alloc['buy'], {'su.pa': 34.5})

    def test_trade_signals_handler(self):
        signals = {
            'buy': {'su.pa': 34.5},
            'sell': {'tec.pa': 45.4}
        }
        alloc = self.pf.trade_signals_handler(signals)
        self.assertIsNone(alloc['date'])
        eq_(alloc['buy'], signals['buy'])

    @raises(portfolio.PortfolioOptimizationFailed)
    def test_error_while_opitmizing(self):
        signals = {
            'buy': {'su.pa': 34.5},
            'sell': {'tec.pa': 45.4}
        }

        pf = TestPortfolio({'raise_fake_error': True})