Skip to content

Commit

Permalink
Fix get_fields_values for NeuroMorpho (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-berchet authored May 23, 2023
1 parent 93c7d8a commit 4441e34
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
17 changes: 12 additions & 5 deletions morphapi/api/neuromorphorg.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ def get_fields_values(self, field):
"""
Returns the list of allowed values for a given query field
"""
return list(
request_no_ssl(self._base_url + f"/fields/{field}").json()[
"fields"
]
)
current_page = 0
max_page = 1
values = []
while current_page < max_page:
req = request_no_ssl(
self._base_url
+ f"/fields/{field}?&size=1000&page={current_page}"
).json()
values.extend(req["fields"])
max_page = req.get("page", {}).get("totalPages", max_page)
current_page += 1
return values

def get_neurons_metadata(self, size=100, page=0, **criteria):
"""
Expand Down
3 changes: 3 additions & 0 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def test_neuromorpho_download(tmpdir):
assert neurons[0].data_file.name == "BAD ID.swc"
assert neurons[0].points is None

# Test get_fields_values
assert len(api.get_fields_values("strain")) > 1000


def test_mouselight_download(tmpdir):
mlapi = MouseLightAPI(base_dir=tmpdir)
Expand Down

0 comments on commit 4441e34

Please sign in to comment.