def test_get_risk_models(mocker): mock_response = { 'results': [ RiskModel.from_dict({ "coverage": "Global", "id": "WW_TEST_MODEL", "name": "World Wide Medium Term Test Model", "term": "Medium", "vendor": "Goldman Sachs", "universeIdentifier": "gsid", "type": "Factor", "version": 4 }), RiskModel.from_dict({ "coverage": "Global", "id": "WW_TEST_MODEL_2", "name": "World Wide Medium Term Test Model 2", "term": "Medium", "vendor": "Goldman Sachs", "universeIdentifier": "gsid", "version": 2, "type": "Thematic" }) ], 'totalResults': 2 } expected_response = [ RiskModel(coverage='Global', id='WW_TEST_MODEL', name='World Wide Medium Term Test Model', term='Medium', vendor='Goldman Sachs', universe_identifier='gsid', version=4, type='Factor'), RiskModel(coverage='Global', id='WW_TEST_MODEL_2', name='World Wide Medium Term Test Model 2', term='Medium', vendor='Goldman Sachs', universe_identifier='gsid', version=2, type='Thematic') ] # 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 = GsRiskModelApi.get_risk_models() GsSession.current._get.assert_called_with('/risk/models?', cls=RiskModel) assert response == expected_response
def test_get_risk_model(mocker): model_id = 'WW_TEST_MODEL' model = RiskModel.from_dict({ "coverage": "Global", "id": "WW_TEST_MODEL", "name": "World Wide Medium Term Test Model", "term": "Medium", "vendor": "Goldman Sachs", "universeIdentifier": "gsid", "version": 4 }) expected_response = RiskModel(coverage='Global', id='WW_TEST_MODEL', name='World Wide Medium Term Test Model', term='Medium', vendor='Goldman Sachs', version=4, universe_identifier='gsid') # 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=model) # run test response = GsRiskModelApi.get_risk_model(model_id) GsSession.current._get.assert_called_with( '/risk/models/{id}'.format(id=model_id), cls=RiskModel) assert response == expected_response
def test_update_risk_model(mocker): model = RiskModel.from_dict({ "coverage": "Global", "id": "WW_TEST_MODEL", "name": "World Wide Medium Term Test Model", "term": "Medium", "vendor": "Goldman Sachs", "universeIdentifier": "gsid", "version": 4 }) # mock GsSession mocker.patch.object( GsSession.__class__, 'default_value', return_value=GsSession.get( Environment.QA, 'client_id', 'secret')) mocker.patch.object(GsSession.current, '_put', return_value=model) # run test response = GsRiskModelApi.update_risk_model(model) GsSession.current._put.assert_called_with('/risk/models/{id}'.format(id='WW_TEST_MODEL'), model, cls=RiskModel) assert response == model