def test_get_many_portfolios(mocker): id_1 = 'MP1' id_2 = 'MP2' mock_response = {'results': ( Portfolio.from_dict({'id': id_1, 'currency': 'USD', 'name': 'Example Port 1'}), Portfolio.from_dict({'id': id_2, 'currency': 'USD', 'name': 'Example Port 2'}) ), 'totalResults': 2} expected_response = ( Portfolio(id=id_1, currency='USD', name='Example Port 1'), Portfolio(id=id_2, currency='USD', name='Example Port 2') ) # mock GsSession mocker.patch.object( GsSession.__class__, 'default_value', return_value=GsSession.get( Environment.QA, 'client_id', 'secret')) mocker.patch.object(GsSession.current, '_get', return_value=mock_response) # run test response = GsPortfolioApi.get_portfolios() GsSession.current._get.assert_called_with('/portfolios?&limit=100', cls=Portfolio) assert response == expected_response
def get(cls, portfolio_id: str = None, name: str = None, **kwargs): if portfolio_id is None and name is None: raise MqValueError( 'Please specify a portfolio ID and/or portfolio name.') portfolios = GsPortfolioApi.get_portfolios( portfolio_ids=[portfolio_id] if portfolio_id else None, portfolio_names=[name] if name else None) if len(portfolios) == 0: raise ValueError( 'No portfolios in Marquee match the requested name and/or ID.') if len(portfolios) > 1: portfolios = { 'Name': [p.name for p in portfolios], 'ID': [p.id for p in portfolios], 'Created Time': [p.created_time for p in portfolios] } cls._print_dict(portfolios) raise ValueError( 'More than one portfolio matches the requested name and/or ID. To resolve,' ' please find the correct portfolio ID below and set it as your portfolio_id.' ) port = portfolios[0] return Portfolio(name=port.name, portfolio_id=port.id, currency=port.currency, entitlements=Entitlements.from_target( port.entitlements))