This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
test_adhoc.py
85 lines (65 loc) · 2.02 KB
/
test_adhoc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Standard Library
from json import loads
from uuid import uuid4
# 3rd Party
from preggy import expect
import tests.func.base # NOQA isort:skip pylint:disable=unused-import
def test_adhoc1(client):
"""
Given API and Worker are UP
When I submit a new job that ends successfully
Then I can see its results in API
"""
task_id = uuid4()
status, body, _ = client.post(
f"/tasks/{task_id}/", data={"image": "ubuntu", "command": "echo 'it works'"}
)
expect(status).to_equal(200)
result = loads(body)
expect(result["executionId"]).not_to_be_null()
execution_url = result["executionUrl"]
expect(execution_url).to_have_finished_with(
status="done", log="it works", exitCode=0, cli=client
)
def test_adhoc2(client):
"""
Given API and Worker are UP
When I submit a new job that fails
Then I can see its results in API
"""
task_id = uuid4()
status, body, _ = client.post(
f"/tasks/{task_id}/",
data={
"image": "ubuntu",
"command": """bash -c 'echo "it failed" && exit 123'""",
},
)
expect(status).to_equal(200)
result = loads(body)
expect(result["executionId"]).not_to_be_null()
execution_url = result["executionUrl"]
expect(execution_url).to_have_finished_with(
status="failed", log="it failed", error="", exitCode=123, cli=client
)
def test_adhoc3(client):
"""
Given API and Worker are UP
When I submit a new job that fails
Then I can see its error log in API
"""
task_id = uuid4()
status, body, _ = client.post(
f"/tasks/{task_id}/", data={"image": "ubuntu", "command": """bash -c 'qwe'"""}
)
expect(status).to_equal(200)
result = loads(body)
expect(result["executionId"]).not_to_be_null()
execution_url = result["executionUrl"]
expect(execution_url).to_have_finished_with(
status="failed",
log="",
error="bash: qwe: command not found",
exitCode=127,
cli=client,
)