コード例 #1
0
 def test_sensitivity_analysis_empty(self, reqmock):
     # result can be an empty list
     reqmock.get('https://api/optimization_views/abc_id',
                 status_code=200, text='{"id":"abc_id"}')
     ov = OptimizationView.retrieve('abc_id')
     reqmock.get('https://api/optimization_views/abc_id/sensitivity_analysis',
                 status_code=200, text='{"sensitivities": []}')
     r = ov.sensitivity_analysis()
     assert hasattr(r, 'sensitivities')
     assert len(r.sensitivities) == 0
コード例 #2
0
 def test_sensitivity_analysis_with_candidates(self, reqmock, candidates, expected_len, get_string):
     # list of candidates should be translated to the correct api request
     reqmock.get('https://api/optimization_views/abc_id',
                 status_code=200, text='{"id":"abc_id"}')
     ov = OptimizationView.retrieve('abc_id')
     reqmock.get(get_string,
                 status_code=200, text=TestOptimizationResource.sensitivity_text)
     r = ov.sensitivity_analysis(candidates=candidates)
     assert hasattr(r, 'sensitivities')
     assert len(r.sensitivities) == expected_len
     for i in range(len(r.sensitivities)):
         for attribute in TestOptimizationResource.required_attributes:
             assert hasattr(r.sensitivities[i], attribute)
コード例 #3
0
 def test_candidate_parameters(self, reqmock):
     candidate_parameters_response = ('{'
                                      ' "items": [{"foo": "bar"}],'
                                      ' "meta": {"total_count": 1,"limit": 100,"offset": 0}'
                                      '}')
     reqmock.get('https://api/optimization_views/abc123/candidate_parameters',
                 status_code=200,
                 text=candidate_parameters_response)
     r = OptimizationView(id='abc123').candidate_parameters()
     assert isinstance(r, list)
     assert len(r) == 1
     assert type(r[0]) == Candidate
     assert r[0].foo == 'bar'
コード例 #4
0
 def test_initial_portfolio_metrics(self, reqmock):
     reqmock.get('https://api/optimization_views/abc123/initial_portfolio_metrics',
                 status_code=200,
                 text='{"num": 1.0}')
     f = OptimizationView(id='abc123').initial_metrics()
     assert f.num == 1.0
コード例 #5
0
 def test_candidate_metrics(self, reqmock):
     reqmock.get('https://api/optimization_views/abc123/candidate_metrics',
                 status_code=200,
                 text='{"num": 1.0}')
     f = OptimizationView(id='abc123').candidate_metrics()
     assert f.num == 1.0
コード例 #6
0
 def test_result(self, reqmock):
     reqmock.get('https://api/optimization_views/abc123/result',
                 status_code=200,
                 text='{"num": 1.0}')
     f = OptimizationView(id='abc123').result()
     assert f.num == 1.0
コード例 #7
0
 def test_retrieve(self, reqmock):
     reqmock.get('https://api/optimization_views/abc123',
                 status_code=200,
                 text='{"num": 1.0}')
     f = OptimizationView.retrieve('abc123')
     assert f.num == 1.0