Skip to content

Commit daa5abf

Browse files
committed
re-apply test changes
1 parent 5d65097 commit daa5abf

File tree

4 files changed

+441
-1
lines changed

4 files changed

+441
-1
lines changed

_test_contract/platform_api/test_jobs.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,60 @@ def test_cancel_job(httpx_mock, platform_client: UnstructuredClient, platform_ap
165165
request = requests[0]
166166
assert request.method == "POST"
167167
assert request.url == url
168+
169+
170+
def test_create_job(httpx_mock, platform_client: UnstructuredClient, platform_api_url: str):
171+
import json
172+
173+
url = f"{platform_api_url}/api/v1/jobs/"
174+
175+
httpx_mock.add_response(
176+
method="POST",
177+
status_code=200,
178+
headers={"Content-Type": "application/json"},
179+
json={
180+
"created_at": "2025-06-22T11:37:21.648Z",
181+
"id": "fcdc4994-eea5-425c-91fa-e03f2bd8030d",
182+
"status": "SCHEDULED",
183+
"runtime": None,
184+
"workflow_id": "16b80fee-64dc-472d-8f26-1d7729b6423d",
185+
"workflow_name": "job-fcdc4994",
186+
"input_file_ids": ["upload-test-file-123"],
187+
"output_node_files": [
188+
{
189+
"node_id": "93fc2ce8-e7c8-424f-a6aa-41460fc5d35d",
190+
"file_id": "upload-test-file-123",
191+
"node_type": "partition",
192+
"node_subtype": "unstructured_api",
193+
}
194+
],
195+
"job_type": "template",
196+
},
197+
url=url,
198+
)
199+
200+
# request_data should be a JSON string containing the job creation data
201+
request_data = json.dumps({
202+
"template_id": "hi_res_partition",
203+
})
204+
205+
create_job_response = platform_client.jobs.create_job(
206+
request=operations.CreateJobRequest(
207+
body_create_job=shared.BodyCreateJob(
208+
request_data=request_data,
209+
)
210+
)
211+
)
212+
assert create_job_response.status_code == 200
213+
214+
requests = httpx_mock.get_requests()
215+
assert len(requests) == 1
216+
request = requests[0]
217+
assert request.method == "POST"
218+
assert request.url == url
219+
220+
job = create_job_response.job_information
221+
assert job.id == "fcdc4994-eea5-425c-91fa-e03f2bd8030d"
222+
assert job.status == "SCHEDULED"
223+
assert job.job_type == "template"
224+
assert job.created_at == datetime.fromisoformat("2025-06-22T11:37:21.648+00:00")
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
from datetime import datetime
2+
3+
import pytest
4+
5+
from unstructured_client import UnstructuredClient
6+
from unstructured_client.models import operations
7+
from unstructured_client.models.errors import SDKError
8+
9+
10+
def test_list_templates(httpx_mock, platform_client: UnstructuredClient, platform_api_url: str):
11+
url = f"{platform_api_url}/api/v1/templates/"
12+
13+
httpx_mock.add_response(
14+
method="GET",
15+
headers={"Content-Type": "application/json"},
16+
json=[
17+
{
18+
"id": "hi_res_partition",
19+
"name": "High Resolution Partition",
20+
"description": "Partition documents with high resolution strategy",
21+
"version": "1.0.0",
22+
"nodes": [
23+
{
24+
"id": "93fc2ce8-e7c8-424f-a6aa-41460fc5d35d",
25+
"name": "partition step",
26+
"type": "partition",
27+
"subtype": "unstructured_api",
28+
}
29+
],
30+
"edges": [],
31+
},
32+
{
33+
"id": "hi_res_and_enrichment",
34+
"name": "High Resolution and Enrichment",
35+
"description": "Partition with enrichment",
36+
"version": "1.0.0",
37+
"nodes": [],
38+
"edges": [],
39+
},
40+
],
41+
url=url,
42+
)
43+
44+
templates_response = platform_client.templates.list_templates(
45+
request=operations.ListTemplatesRequest()
46+
)
47+
assert templates_response.status_code == 200
48+
49+
requests = httpx_mock.get_requests()
50+
assert len(requests) == 1
51+
request = requests[0]
52+
assert request.method == "GET"
53+
assert request.url == url
54+
55+
assert "templates" in templates_response.response_list_templates
56+
templates = templates_response.response_list_templates
57+
assert len(templates) == 2
58+
assert templates[0]["id"] == "hi_res_partition"
59+
assert templates[0]["name"] == "High Resolution Partition"
60+
assert templates[1]["id"] == "hi_res_and_enrichment"
61+
62+
63+
def test_get_template(httpx_mock, platform_client: UnstructuredClient, platform_api_url: str):
64+
url = f"{platform_api_url}/api/v1/templates/hi_res_partition"
65+
66+
httpx_mock.add_response(
67+
method="GET",
68+
headers={"Content-Type": "application/json"},
69+
json={
70+
"id": "hi_res_partition",
71+
"name": "High Resolution Partition",
72+
"description": "Partition documents with high resolution strategy",
73+
"version": "1.0.0",
74+
"nodes": [
75+
{
76+
"id": "93fc2ce8-e7c8-424f-a6aa-41460fc5d35d",
77+
"name": "partition step",
78+
"type": "partition",
79+
"subtype": "unstructured_api",
80+
"settings": {
81+
"strategy": "fast",
82+
"include_page_breaks": False,
83+
},
84+
}
85+
],
86+
"edges": [
87+
{
88+
"source_id": "00000000-0000-0000-0000-000000000001-downloader",
89+
"destination_id": "93fc2ce8-e7c8-424f-a6aa-41460fc5d35d",
90+
}
91+
],
92+
},
93+
url=url,
94+
)
95+
96+
template_response = platform_client.templates.get_template(
97+
request=operations.GetTemplateRequest(template_id="hi_res_partition")
98+
)
99+
assert template_response.status_code == 200
100+
101+
requests = httpx_mock.get_requests()
102+
assert len(requests) == 1
103+
request = requests[0]
104+
assert request.method == "GET"
105+
assert request.url == url
106+
107+
assert "template" in template_response.response_get_template
108+
template = template_response.response_get_template
109+
assert template["id"] == "hi_res_partition"
110+
assert template["name"] == "High Resolution Partition"
111+
assert len(template["nodes"]) == 1
112+
assert template["nodes"][0]["id"] == "93fc2ce8-e7c8-424f-a6aa-41460fc5d35d"
113+
114+
115+
def test_get_template_not_found(
116+
httpx_mock, platform_client: UnstructuredClient, platform_api_url: str
117+
):
118+
url = f"{platform_api_url}/api/v1/templates/nonexistent_template"
119+
120+
httpx_mock.add_response(
121+
method="GET",
122+
status_code=404,
123+
headers={"Content-Type": "application/json"},
124+
json={"detail": "Template nonexistent_template not found"},
125+
url=url,
126+
)
127+
128+
with pytest.raises(SDKError) as e:
129+
platform_client.templates.get_template(
130+
request=operations.GetTemplateRequest(template_id="nonexistent_template")
131+
)
132+
133+
assert e.value.status_code == 404
134+
assert "API error occurred" in e.value.message
135+
136+
requests = httpx_mock.get_requests()
137+
assert len(requests) == 1
138+
request = requests[0]
139+
assert request.method == "GET"
140+
assert request.url == url
141+

0 commit comments

Comments
 (0)