-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtest_jobs.py
More file actions
166 lines (135 loc) · 5.17 KB
/
test_jobs.py
File metadata and controls
166 lines (135 loc) · 5.17 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
from datetime import datetime
import pytest
from unstructured_client import UnstructuredClient
from unstructured_client.models import shared, operations
from unstructured_client.models.errors import SDKError
def test_list_jobs(httpx_mock, client: UnstructuredClient, platform_api_url: str):
url = f"{platform_api_url}/api/v1/jobs/"
httpx_mock.add_response(
method="GET",
headers={"Content-Type": "application/json"},
json=[
{
"created_at": "2025-06-22T11:37:21.648Z",
"id": "fcdc4994-eea5-425c-91fa-e03f2bd8030d",
"status": "IN_PROGRESS",
"runtime": None,
"workflow_id": "16b80fee-64dc-472d-8f26-1d7729b6423d",
"workflow_name": "test_workflow",
}
],
url=url,
)
jobs_response = client.jobs.list_jobs(request=operations.ListJobsRequest())
assert jobs_response.status_code == 200
requests = httpx_mock.get_requests()
assert len(requests) == 1
request = requests[0]
assert request.method == "GET"
assert request.url == url
assert len(jobs_response.response_list_jobs) == 1
job = jobs_response.response_list_jobs[0]
assert job.id == "fcdc4994-eea5-425c-91fa-e03f2bd8030d"
assert job.workflow_id == "16b80fee-64dc-472d-8f26-1d7729b6423d"
assert job.workflow_name == "test_workflow"
assert job.status == "IN_PROGRESS"
assert job.created_at == datetime.fromisoformat("2025-06-22T11:37:21.648+00:00")
def test_get_job(httpx_mock, client: UnstructuredClient, platform_api_url: str):
url = f"{platform_api_url}/api/v1/jobs/fcdc4994-eea5-425c-91fa-e03f2bd8030d"
httpx_mock.add_response(
method="GET",
headers={"Content-Type": "application/json"},
json={
"created_at": "2025-06-22T11:37:21.648Z",
"id": "fcdc4994-eea5-425c-91fa-e03f2bd8030d",
"status": "SCHEDULED",
"runtime": None,
"workflow_id": "16b80fee-64dc-472d-8f26-1d7729b6423d",
"workflow_name": "test_workflow",
},
url=url,
)
job_response = client.jobs.get_job(
request=operations.GetJobRequest(job_id="fcdc4994-eea5-425c-91fa-e03f2bd8030d")
)
assert job_response.status_code == 200
requests = httpx_mock.get_requests()
assert len(requests) == 1
request = requests[0]
assert request.method == "GET"
assert request.url == url
job = job_response.job_information
assert job.id == "fcdc4994-eea5-425c-91fa-e03f2bd8030d"
assert job.workflow_id == "16b80fee-64dc-472d-8f26-1d7729b6423d"
assert job.workflow_name == "test_workflow"
assert job.status == "SCHEDULED"
assert job.created_at == datetime.fromisoformat("2025-06-22T11:37:21.648+00:00")
def test_get_job_not_found(
httpx_mock, client: UnstructuredClient, platform_api_url: str
):
url = f"{platform_api_url}/api/v1/jobs/fcdc4994-eea5-425c-91fa-e03f2bd8030d"
httpx_mock.add_response(
method="GET",
status_code=404,
headers={"Content-Type": "application/json"},
json={"detail": "Job not found"},
url=url,
)
with pytest.raises(SDKError) as e:
client.jobs.get_job(
request=operations.GetJobRequest(
job_id="fcdc4994-eea5-425c-91fa-e03f2bd8030d"
)
)
assert e.value.status_code == 404
assert e.value.message == "API error occurred"
requests = httpx_mock.get_requests()
assert len(requests) == 1
request = requests[0]
assert request.method == "GET"
assert request.url == url
def test_get_job_error(httpx_mock, client: UnstructuredClient, platform_api_url: str):
url = f"{platform_api_url}/api/v1/jobs/fcdc4994-eea5-425c-91fa-e03f2bd8030d"
httpx_mock.add_response(
method="GET",
status_code=500,
headers={"Content-Type": "application/json"},
json={"detail": "Internal server error"},
url=url,
)
with pytest.raises(SDKError) as e:
client.jobs.get_job(
request=operations.GetJobRequest(
job_id="fcdc4994-eea5-425c-91fa-e03f2bd8030d"
)
)
assert e.value.status_code == 500
assert e.value.message == "API error occurred"
requests = httpx_mock.get_requests()
assert len(requests) == 1
request = requests[0]
assert request.method == "GET"
assert request.url == url
def test_cancel_job(httpx_mock, client: UnstructuredClient, platform_api_url: str):
url = f"{platform_api_url}/api/v1/jobs/fcdc4994-eea5-425c-91fa-e03f2bd8030d/cancel"
httpx_mock.add_response(
method="POST",
status_code=200,
url=url,
json={
"id": "fcdc4994-eea5-425c-91fa-e03f2bd8030d",
"status": "cancelled",
"message": "Job successfully cancelled.",
},
)
cancel_response = client.jobs.cancel_job(
request=operations.CancelJobRequest(
job_id="fcdc4994-eea5-425c-91fa-e03f2bd8030d"
)
)
assert cancel_response.status_code == 200
requests = httpx_mock.get_requests()
assert len(requests) == 1
request = requests[0]
assert request.method == "POST"
assert request.url == url