def get_positions_data(self, start: dt.date = DateLimit.LOW_LIMIT.value, end: dt.date = dt.date.today(), fields: [str] = None, position_type: PositionType = PositionType.CLOSE) -> List[Dict]: if self.positioned_entity_type == EntityType.ASSET: return GsAssetApi.get_asset_positions_data(self.id, start, end, fields, position_type) if self.positioned_entity_type == EntityType.PORTFOLIO: return GsPortfolioApi.get_positions_data(self.id, start, end, fields, position_type) raise NotImplementedError
def test_portfolio_positions_data(mocker): mock_response = {'results': [ { 'underlyingAssetId': 'MA4B66MW5E27UAFU2CD', 'divisor': 8305900333.262549, 'quantity': 0.016836826158, 'positionType': 'close', 'bbid': 'EXPE UW', 'assetId': 'MA4B66MW5E27U8P32SB', 'positionDate': '2019-11-07', 'assetClassificationsGicsSector': 'Consumer Discretionary', 'closePrice': 98.29, 'ric': 'EXPE.OQ' }, ]} expected_response = [ { 'underlyingAssetId': 'MA4B66MW5E27UAFU2CD', 'divisor': 8305900333.262549, 'quantity': 0.016836826158, 'positionType': 'close', 'bbid': 'EXPE UW', 'assetId': 'MA4B66MW5E27U8P32SB', 'positionDate': '2019-11-07', 'assetClassificationsGicsSector': 'Consumer Discretionary', 'closePrice': 98.29, 'ric': 'EXPE.OQ' }, ] # 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_positions_data('portfolio_id', dt.date(2020, 1, 1), dt.date(2021, 1, 1)) GsSession.current._get.assert_called_with( '/portfolios/portfolio_id/positions/data?startDate=2020-01-01&endDate=2021-01-01') assert response == expected_response