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_scheduled.py
72 lines (54 loc) · 1.78 KB
/
test_scheduled.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
# Standard Library
import calendar
from datetime import datetime
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_scheduled1(client):
"""
Given API and Worker are UP
When I submit a scheduled job with specific timestamp
Then I can see its results in API
"""
task_id = uuid4()
date = datetime.utcnow()
unixtime = calendar.timegm(date.utctimetuple())
status, body, _ = client.post(
f"/tasks/{task_id}/",
data={"image": "ubuntu", "command": "echo 'it works'", "startAt": unixtime},
)
expect(status).to_equal(200)
result = loads(body)
expect(result["jobId"]).not_to_be_null()
job_url = result["jobUrl"]
meta = {}
expect(job_url).to_have_execution(cli=client, execution=meta)
expect(meta).to_include("url")
expect(meta).to_include("executionId")
expect(meta["url"]).to_have_finished_with(
status="done", log="it works", exitCode=0, cli=client
)
def test_scheduled2(client):
"""
Given API and Worker are UP
When I submit a scheduled job in a few seconds
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'", "startIn": "1s"},
)
expect(status).to_equal(200)
result = loads(body)
expect(result["jobId"]).not_to_be_null()
job_url = result["jobUrl"]
meta = {}
expect(job_url).to_have_execution(cli=client, execution=meta)
expect(meta).to_include("url")
expect(meta).to_include("executionId")
expect(meta["url"]).to_have_finished_with(
status="done", log="it works", exitCode=0, cli=client
)