def test_get_latest_portfolio_positions(mocker): id_1 = 'MP1' date = dt.date(2019, 2, 18) mock_response = {'results': ( PositionSet.from_dict({ 'id': 'mock1', 'positionDate': '2019-02-18', 'lastUpdateTime': '2019-02-19T12:10:32.401Z', 'positions': [ {'assetId': 'MQA123', 'quantity': 0.3}, {'assetId': 'MQA456', 'quantity': 0.7} ] }), )} expected_response = ( PositionSet('mock1', date, dup.parse('2019-02-19T12:10:32.401Z'), ( Position(assetId='MQA123', quantity=0.3), Position(assetId='MQA456', quantity=0.7) )) ) # mock GsSession mocker.patch.object(GsSession.__class__, 'current', return_value=GsSession.get(Environment.QA, 'client_id', 'secret')) mocker.patch.object(GsSession.current, '_get', return_value=mock_response) # run test response = GsPortfolioApi.get_latest_positions(id_1) GsSession.current._get.assert_called_with('/portfolios/{id}/positions/last?type=close'.format(id=id_1), cls=PositionSet) assert response == expected_response
def test_get_portfolio_positions(mocker): id_1 = 'MP1' start_date = dt.date(2019, 2, 18) end_date = dt.date(2019, 2, 19) mock_response = {'positionSets': ( { 'id': 'mock1', 'positionDate': '2019-02-18', 'lastUpdateTime': '2019-02-19T12:10:32.401Z', 'positions': [ {'assetId': 'MQA123', 'quantity': 0.3}, {'assetId': 'MQA456', 'quantity': 0.7} ] }, { 'id': 'mock2', 'positionDate': '2019-02-19', 'lastUpdateTime': '2019-02-20T05:04:32.981Z', 'positions': [ {'assetId': 'MQA123', 'quantity': 0.4}, {'assetId': 'MQA456', 'quantity': 0.6} ] } )} expected_response = ( PositionSet('mock1', start_date, dup.parse('2019-02-19T12:10:32.401Z'), ( Position(assetId='MQA123', quantity=0.3), Position(assetId='MQA456', quantity=0.7) )), PositionSet('mock2', end_date, dup.parse('2019-02-20T05:04:32.981Z'), ( Position(assetId='MQA123', quantity=0.4), Position(assetId='MQA456', quantity=0.6) )) ) # mock GsSession mocker.patch.object( GsSession.__class__, 'current', 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(id_1, start_date, end_date) GsSession.current._get.assert_called_with( '/portfolios/{id}/positions?type=close&startDate={sd}&endDate={ed}'.format(id=id_1, sd=start_date, ed=end_date)) assert response == expected_response