Skip to content

Commit

Permalink
Add test for fetch_many
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilty committed Oct 30, 2018
1 parent e65d3f4 commit 8233c05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion redis_tasks/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ def fetch_many(cls, task_ids):
return tasks

def refresh(self, data=None):
key = self.key
if not data:
data = connection.hgetall(self.key)
obj = {k.decode(): v for k, v in data.items()}
Expand Down
14 changes: 14 additions & 0 deletions tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,17 @@ def test_init_save_fetch_delete(connection, assert_atomic, stub):
assert not connection.exists(t.key)
with pytest.raises(TaskDoesNotExist):
Task.fetch(t.id)


def test_fetch_many(stub):
tasks_data = [{"args": []}, {"args": ["foo"]}, {"args": ["bar"]},
{"args": ["foo", "bar"]}, {"args": []}]
tasks = [Task(stub, **d) for d in tasks_data]
for t in tasks:
t._save()

fetched = Task.fetch_many([t.id for t in tasks[1:4]])
assert len(fetched) == 3
for i, task in enumerate(fetched):
assert task.id == tasks[i+1].id
assert task.args == tasks_data[i+1]["args"]

0 comments on commit 8233c05

Please sign in to comment.