Skip to content

Commit

Permalink
update python client for new candidate endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishflavored committed Feb 11, 2019
1 parent 486bba6 commit 7f160e7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions analyzere/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,23 @@ def candidates(self, index=None):
resp = request('get', path)
return convert_to_analyzere_object(resp, Candidate, optimization_view_id=self.id)

def candidate_parameters(self, index=None):
if index is None:
path = '{}/candidate_parameters'.format(self._get_path(self.id))
else:
try:
index = int(index)
except ValueError:
raise Exception('index argument provided to OptimizationView.candidate_parameters() must be an integer')
path = '{}/candidate_parameters/{}'.format(self._get_path(self.id), index)
resp = request('get', path)
return convert_to_analyzere_object(resp, Candidate, optimization_view_id=self.id)

def candidate_metrics(self):
path = '{}/candidate_metrics'.format(self._get_path(self.id))
resp = request('get', path)
return convert_to_analyzere_object(resp)


class OptimizationDomain(EmbeddedResource):
pass
Expand Down
21 changes: 21 additions & 0 deletions tests/test_base_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,27 @@ def test_candidates(self, reqmock):
assert type(r[0]) == Candidate
assert r[0].foo == 'bar'

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'

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

def test_initial_portfolio_metrics(self, reqmock):
reqmock.get('https://api/optimization_views/abc123/initial_portfolio_metrics',
status_code=200,
Expand Down

0 comments on commit 7f160e7

Please sign in to comment.