Skip to content

Commit

Permalink
Feature/SK-611 | List models API-function - Filter by session id (#499)
Browse files Browse the repository at this point in the history
* added list_models to client.py

* api test added for list_models
  • Loading branch information
niklastheman committed Jan 4, 2024
1 parent 12f4d80 commit e23421a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions fedn/fedn/network/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ def get_model_trail(self):
response = requests.get(self._get_url('get_model_trail'), verify=self.verify)
return response.json()

def list_models(self, session_id=None):
""" Get all models from the statestore.
:return: All models.
:rtype: dict
"""
response = requests.get(self._get_url('list_models'), params={'session_id': session_id}, verify=self.verify)
return response.json()

def list_clients(self):
""" Get all clients from the statestore.
Expand Down
13 changes: 13 additions & 0 deletions fedn/fedn/network/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,19 @@ def test_list_sessions(self):
# Assert api.list_sessions was called
fedn.network.api.server.api.get_all_sessions.assert_called_once()

def test_list_models(self):
""" Test list_models endpoint. """
# Mock api.list_models
return_value = {"test": "test"}
fedn.network.api.server.api.get_models = MagicMock(return_value=return_value)
# Make request
response = self.app.get('/list_models')
# Assert response
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json, return_value)
# Assert api.list_models was called
fedn.network.api.server.api.get_models.assert_called_once()

def test_get_package(self):
""" Test get_package endpoint. """
# Mock api.get_package
Expand Down

0 comments on commit e23421a

Please sign in to comment.