Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Please see [MIGRATING.md](./MIGRATING.md) for information on breaking changes.

### Fixed

- Endpoints which return totalRecords as the first key

### Changed

### Removed
Expand Down
12 changes: 10 additions & 2 deletions src/ldlite/_folio.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FolioClient:
def __init__(self, params: FolioParams):
self._client_factory = default_client_factory(params)

def iterate_records(
def iterate_records( # noqa: C901 (to be really fixed in a non-bugfix release)
self,
path: str,
timeout: float,
Expand Down Expand Up @@ -92,7 +92,15 @@ def iterate_records(
record = ""
return

key = next(iter(j.keys()))
# folio records usually have two keys
# the actual list and the totalRecords key
# totalRecords isn't always in the same spot
# so we check for keys until we find a good one
# totalRecords as of right now is the only key that could get in the way
# but there may end up with more
keys = iter(j.keys())
while (key := next(keys)) and key in ["totalRecords"]:
...
nonid_key = (
# Grab the first key if there isn't an id column
# because we need it to offset page properly
Expand Down
7 changes: 5 additions & 2 deletions tests/test_cases/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ def patch_request_get(
httpx_post_mock.return_value.cookies.__getitem__.return_value = "token"

side_effects = []
for values in self.values.values():
for i, values in enumerate(self.values.values()):
key = next(iter(values[0].keys()))
total_mock = MagicMock()
total_mock.text = f'{{"{key}": [{{"id": ""}}], "totalRecords": 100000}}'
if i % 2 == 0:
total_mock.text = f'{{"{key}": [{{"id": ""}}], "totalRecords": 100000}}'
else:
total_mock.text = f'{{"totalRecords": 100000, "{key}": [{{"id": ""}}]}}'

value_mocks = []
for v in values:
Expand Down