|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 |
|
| 5 | +from meilisearch.models.task import TaskInfo |
5 | 6 | from tests import common |
6 | 7 |
|
7 | 8 |
|
@@ -91,3 +92,42 @@ def test_get_task_inexistent(client): |
91 | 92 | """Tests getting a task that does not exists.""" |
92 | 93 | with pytest.raises(Exception): |
93 | 94 | client.get_task("abc") |
| 95 | + |
| 96 | + |
| 97 | +@pytest.fixture |
| 98 | +def create_tasks(empty_index, small_movies): |
| 99 | + """Ensures there are some tasks present for testing.""" |
| 100 | + index = empty_index() |
| 101 | + index.update_ranking_rules(["type", "exactness"]) |
| 102 | + index.reset_ranking_rules() |
| 103 | + index.add_documents(small_movies) |
| 104 | + index.add_documents(small_movies) |
| 105 | + |
| 106 | + |
| 107 | +@pytest.mark.usefixtures("create_tasks") |
| 108 | +def test_cancel_tasks(client): |
| 109 | + """Tests cancel a task with uid 1.""" |
| 110 | + task = client.cancel_tasks({"uids": ["1", "2"]}) |
| 111 | + client.wait_for_task(task.task_uid) |
| 112 | + tasks = client.get_tasks({"types": "taskCancelation"}) |
| 113 | + |
| 114 | + assert isinstance(task, TaskInfo) |
| 115 | + assert task.task_uid is not None |
| 116 | + assert task.index_uid is None |
| 117 | + assert task.type == "taskCancelation" |
| 118 | + assert "uids" in tasks["results"][0]["details"]["originalFilter"] |
| 119 | + assert "uids=1%2C2" in tasks["results"][0]["details"]["originalFilter"] |
| 120 | + |
| 121 | + |
| 122 | +@pytest.mark.usefixtures("create_tasks") |
| 123 | +def test_cancel_every_task(client): |
| 124 | + """Tests cancel every task.""" |
| 125 | + task = client.cancel_tasks({"statuses": ["enqueued", "processing"]}) |
| 126 | + client.wait_for_task(task.task_uid) |
| 127 | + tasks = client.get_tasks({"types": "taskCancelation"}) |
| 128 | + |
| 129 | + assert isinstance(task, TaskInfo) |
| 130 | + assert task.task_uid is not None |
| 131 | + assert task.index_uid is None |
| 132 | + assert task.type == "taskCancelation" |
| 133 | + assert "statuses=enqueued%2Cprocessing" in tasks["results"][0]["details"]["originalFilter"] |
0 commit comments