Skip to content

Commit

Permalink
api: fix updated
Browse files Browse the repository at this point in the history
* Uses `scan` in `generator` function to generate a complete result.

Co-Authored-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep committed Sep 8, 2022
1 parent db6fc2e commit 1372f09
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
3 changes: 0 additions & 3 deletions rero_mef/agents/mef/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ def get_updated(cls, data):
search = search.filter('range', _updated={'gte': from_date})
if pids := data.get('pids'):
search = search.filter('terms', pid=pids)

search = search \
.sort({'pid': {'order': 'asc'}})
return generate(search)


Expand Down
3 changes: 1 addition & 2 deletions rero_mef/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,9 +1245,8 @@ def get_mefs_endpoints():

def generate(search):
"""Lagging genarator."""
records = search.__iter__()
yield '['
for idx, record in enumerate(records):
for idx, record in enumerate(search.scan()):
if idx != 0:
yield ', '
yield json.dumps(record.to_dict())
Expand Down
8 changes: 4 additions & 4 deletions tests/api/test_agents_mef_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def test_agents_mef_get_updated(client, agent_mef_record, agent_idref_record,
{}
)
assert res.status_code == 200
pids = [rec.get('pid') for rec in data]
pids = sorted([rec.get('pid') for rec in data])
assert pids == ['1', '2', '3']

res, data = postdata(
Expand All @@ -162,7 +162,7 @@ def test_agents_mef_get_updated(client, agent_mef_record, agent_idref_record,
{"pids": ['2']}
)
assert res.status_code == 200
pids = [rec.get('pid') for rec in data]
pids = sorted([rec.get('pid') for rec in data])
assert pids == ['2']

res, data = postdata(
Expand All @@ -171,7 +171,7 @@ def test_agents_mef_get_updated(client, agent_mef_record, agent_idref_record,
{"from_date": "2022-02-02"}
)
assert res.status_code == 200
pids = [rec.get('pid') for rec in data]
pids = sorted([rec.get('pid') for rec in data])
assert pids == ['1', '2', '3']

date = datetime.now(timezone.utc) + timedelta(days=1)
Expand All @@ -181,5 +181,5 @@ def test_agents_mef_get_updated(client, agent_mef_record, agent_idref_record,
{"from_date": date.isoformat()}
)
assert res.status_code == 200
pids = [rec.get('pid') for rec in data]
pids = sorted([rec.get('pid') for rec in data])
assert pids == []
8 changes: 4 additions & 4 deletions tests/api/test_concepts_mef_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_concepts_mef_get_updated(client,
{}
)
assert res.status_code == 200
pids = [rec.get('pid') for rec in data]
pids = sorted([rec.get('pid') for rec in data])
assert pids == ['1', '2', '3']

res, data = postdata(
Expand All @@ -97,7 +97,7 @@ def test_concepts_mef_get_updated(client,
{"pids": ['2']}
)
assert res.status_code == 200
pids = [rec.get('pid') for rec in data]
pids = sorted([rec.get('pid') for rec in data])
assert pids == ['2']

res, data = postdata(
Expand All @@ -106,7 +106,7 @@ def test_concepts_mef_get_updated(client,
{"from_date": "2022-02-02"}
)
assert res.status_code == 200
pids = [rec.get('pid') for rec in data]
pids = sorted([rec.get('pid') for rec in data])
assert pids == ['1', '2', '3']

date = datetime.now(timezone.utc) + timedelta(days=1)
Expand All @@ -116,5 +116,5 @@ def test_concepts_mef_get_updated(client,
{"from_date": date.isoformat()}
)
assert res.status_code == 200
pids = [rec.get('pid') for rec in data]
pids = sorted([rec.get('pid') for rec in data])
assert pids == []

0 comments on commit 1372f09

Please sign in to comment.