Skip to content

Commit 315225d

Browse files
author
Joel Collins
committed
Added back tests for deprecated tasks view
1 parent fd73788 commit 315225d

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

tests/test_default_views.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,60 @@ def task_func():
7070
def test_action_kill_missing(thing_client):
7171
with thing_client as c:
7272
assert c.delete("/actions/missing_id").status_code == 404
73+
74+
75+
### DEPRECATED: LEGACY TASK VIEW
76+
77+
78+
def test_tasks_list(thing_client):
79+
def task_func():
80+
pass
81+
82+
task_obj = current_thing.actions.spawn(task_func)
83+
84+
with thing_client as c:
85+
response = c.get("/tasks").json
86+
ids = [task.get("id") for task in response]
87+
assert str(task_obj.id) in ids
88+
89+
90+
def test_task_representation(thing_client):
91+
def task_func():
92+
pass
93+
94+
task_obj = current_thing.actions.spawn(task_func)
95+
task_id = str(task_obj.id)
96+
97+
with thing_client as c:
98+
response = c.get(f"/tasks/{task_id}").json
99+
assert response
100+
101+
102+
def test_task_representation_missing(thing_client):
103+
with thing_client as c:
104+
assert c.get("/tasks/missing_id").status_code == 404
105+
106+
107+
def test_task_kill(thing_client):
108+
def task_func():
109+
while True:
110+
gevent.sleep(0)
111+
112+
task_obj = current_thing.actions.spawn(task_func)
113+
task_id = str(task_obj.id)
114+
115+
# Wait for task to start
116+
task_obj.started_event.wait()
117+
assert task_id in current_thing.actions.to_dict()
118+
119+
# Send a DELETE request to terminate the task
120+
with thing_client as c:
121+
response = c.delete(f"/tasks/{task_id}")
122+
assert response.status_code == 200
123+
# Test task was terminated
124+
assert task_obj._status == "terminated"
125+
126+
127+
def test_task_kill_missing(thing_client):
128+
with thing_client as c:
129+
assert c.delete("/tasks/missing_id").status_code == 404

0 commit comments

Comments
 (0)