Example #1
0
def test_get_risk_model_coverage(mocker):
    results = {
        "results": [
            RiskModelFactor.from_dict({
                "model": "AXUS4S",
                "businessDate": "2020-11-02"
            }),
            RiskModelFactor.from_dict({
                "model": "AXAU4M",
                "businessDate": "2020-11-03"
            })
        ]
    }

    # mock GsSession
    mocker.patch.object(GsSession.__class__,
                        'default_value',
                        return_value=GsSession.get(Environment.QA, 'client_id',
                                                   'secret'))
    mocker.patch.object(GsSession.current, '_post', return_value=results)

    # run test
    response = GsFactorRiskModelApi.get_risk_model_coverage()
    GsSession.current._post.assert_called_with('/risk/models/coverage', {})
    assert response == results['results']
Example #2
0
def test_get_risk_model_factors(mocker):
    factors = {
        'results': [
            RiskModelFactor.from_dict({
                "type": "Factor",
                "identifier": "Factor1"
            }),
            RiskModelFactor.from_dict({
                "type": "Category",
                "identifier": "Factor2"
            })
        ],
        'totalResults':
        2
    }

    expected_response = [
        RiskModelFactor(identifier='Factor1', type='Factor'),
        RiskModelFactor(identifier='Factor2', type='Category')
    ]

    # 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=factors)

    # run test
    response = GsFactorRiskModelApi.get_risk_model_factors(model_id='id')
    GsSession.current._get.assert_called_with('/risk/models/id/factors',
                                              cls=RiskModelFactor)
    assert response == expected_response
Example #3
0
 def __init__(self, risk_model_id: str, factor_name: str):
     self.risk_model_id = risk_model_id
     factors = RiskModel(risk_model_id).get_factor_data()
     factors = [
         factor for factor in factors if factor['name'] == factor_name
     ]
     self.factor = RiskModelFactor(
         identifier=factors[0]['identifier'],
         type_=factors[0]['type'],
         name=factors[0]['name']) if factors else None
Example #4
0
def test_create_risk_model_factor(mocker):
    factor = RiskModelFactor.from_dict({
        "identifier": "Factor1",
        "type": "Factor"
    })

    expected_response = RiskModelFactor(identifier='Factor1', type='Factor')

    # mock GsSession
    mocker.patch.object(GsSession.__class__,
                        'default_value',
                        return_value=GsSession.get(Environment.QA, 'client_id',
                                                   'secret'))
    mocker.patch.object(GsSession.current, '_post', return_value=factor)

    # run test
    response = GsFactorRiskModelApi.create_risk_model_factor(model_id='id',
                                                             factor=factor)
    GsSession.current._post.assert_called_with('/risk/models/id/factors',
                                               factor,
                                               cls=RiskModelFactor)
    assert response == expected_response
Example #5
0
def test_update_risk_model_factor(mocker):
    factor = RiskModelFactor.from_dict({
        "identifier": "factor",
        "type": "Factor"
    })

    # 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=factor)

    # run test
    response = GsFactorRiskModelApi.update_risk_model_factor(model_id='id', factor_id='factor', factor=factor)
    GsSession.current._put.assert_called_with('/risk/models/{id}/factors/{identifier}'
                                              .format(id='id', identifier='factor'), factor, cls=RiskModelFactor)
    assert response == factor