Skip to content

Commit a7051c7

Browse files
ellnixsanders41
andcommitted
Refactor batch classes and tests
Co-authored-by: sanders41 <[email protected]>
1 parent fa1594b commit a7051c7

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

meilisearch/models/task.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ def validate_finished_at(cls, v: str) -> Optional[datetime]: # pylint: disable=
149149
return iso_to_date_time(v)
150150

151151

152-
class BatchResults:
153-
def __init__(self, resp: Dict[str, Any]) -> None:
154-
self.results: List[Batch] = [Batch(**batch) for batch in resp["results"]]
155-
self.total: int = resp["total"]
156-
self.limit: int = resp["limit"]
157-
self.from_: int = resp["from"]
158-
self.next_: int = resp["next"]
152+
class BatchResults(CamelBase):
153+
results: List[Batch]
154+
total: int
155+
limit: int
156+
from_: int
157+
# None means last page
158+
next_: Optional[int]

meilisearch/task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ def get_batches(self, parameters: Optional[MutableMapping[str, Any]] = None) ->
4848
if parameters is None:
4949
parameters = {}
5050
for param in parameters:
51-
if isinstance(parameters[param], list):
51+
if isinstance(parameters[param], (list, tuple)):
5252
parameters[param] = ",".join(parameters[param])
5353
batches = self.http.get(f"{self.config.paths.batch}?{parse.urlencode(parameters)}")
54-
return BatchResults(batches)
54+
return BatchResults(**batches)
5555

5656
def get_batch(self, uid: int) -> Batch:
5757
"""Get one tasks batch.

tests/client/test_client_task_meilisearch.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,6 @@ def test_get_batches_with_parameters(client):
186186
def test_get_batch(client):
187187
"""Tests getting the details of a batch."""
188188
batches = client.get_batches({"limit": 1})
189-
batch = client.get_batch(batches.results[0].uid)
190-
batch_dict = batch.__dict__
191-
assert "uid" in batch_dict
192-
assert "details" in batch_dict
193-
assert "stats" in batch_dict
194-
assert "duration" in batch_dict
195-
assert "started_at" in batch_dict
196-
assert "finished_at" in batch_dict
197-
assert "progress" in batch_dict
189+
uid = batches.results[0].uid
190+
batch = client.get_batch(uid)
191+
assert batch.uid == uid

0 commit comments

Comments
 (0)