Skip to content

Commit da5ec09

Browse files
committed
test NEXUS-817: added retry tests
1 parent 709fe3f commit da5ec09

File tree

8 files changed

+236
-104
lines changed

8 files changed

+236
-104
lines changed

_test_contract/conftest.py

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import os
12
from datetime import timedelta
3+
from pathlib import Path
24

35
import pytest
46

@@ -7,15 +9,81 @@
79
FAKE_API_KEY = "91pmLBeETAbXCpNylRsLq11FdiZPTk"
810

911
@pytest.fixture(scope="module")
10-
def client(platform_api_url) -> UnstructuredClient:
12+
def platform_client(platform_api_url) -> UnstructuredClient:
1113
_client = UnstructuredClient(
1214
api_key_auth=FAKE_API_KEY,
1315
server_url=platform_api_url,
1416
)
1517
yield _client
1618

19+
@pytest.fixture(scope="module")
20+
def serverless_client(serverless_api_url) -> UnstructuredClient:
21+
_client = UnstructuredClient(
22+
api_key_auth=FAKE_API_KEY,
23+
server_url=serverless_api_url
24+
)
25+
yield _client
26+
1727
@pytest.fixture(autouse=True)
1828
def mock_sleep(mocker, freezer):
1929
sleep_mock = mocker.patch("time.sleep")
2030
sleep_mock.side_effect = lambda seconds: freezer.tick(timedelta(seconds=seconds))
21-
yield sleep_mock
31+
yield sleep_mock
32+
33+
@pytest.fixture(scope="module")
34+
def platform_api_url():
35+
return "https://platform.unstructuredapp.io"
36+
37+
@pytest.fixture(scope="module")
38+
def serverless_api_url():
39+
return "https://api.unstructuredapp.io"
40+
41+
@pytest.fixture(scope="module")
42+
def dummy_partitioned_text():
43+
return """[
44+
{
45+
"type": "NarrativeText",
46+
"element_id": "b7dca0363a83468b9e7326c0c1caf93e",
47+
"text": "March 17, 2022",
48+
"metadata": {
49+
"detection_class_prob": 0.35799261927604675,
50+
"coordinates": {
51+
"points": [
52+
[
53+
1447.871337890625,
54+
301.74810791015625
55+
],
56+
[
57+
1447.871337890625,
58+
326.5603332519531
59+
],
60+
[
61+
1616.6922607421875,
62+
326.5603332519531
63+
],
64+
[
65+
1616.6922607421875,
66+
301.74810791015625
67+
]
68+
],
69+
"system": "PixelSpace",
70+
"layout_width": 1700,
71+
"layout_height": 2200
72+
},
73+
"last_modified": "2024-02-07T14:23:29",
74+
"filetype": "application/pdf",
75+
"languages": [
76+
"eng"
77+
],
78+
"page_number": 1,
79+
"file_directory": "data",
80+
"filename": "MyDocument.pdf"
81+
}
82+
}
83+
]"""
84+
85+
@pytest.fixture(scope="module")
86+
def doc_path() -> Path:
87+
samples_path = Path(__file__).resolve().parents[1] / "_sample_docs"
88+
assert samples_path.exists()
89+
return samples_path

_test_contract/platform_api/conftest.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

_test_contract/platform_api/test_destinations.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def test_list_destinations(
11-
httpx_mock, client: UnstructuredClient, platform_api_url: str
11+
httpx_mock, platform_client: UnstructuredClient, platform_api_url: str
1212
):
1313
url = f"{platform_api_url}/api/v1/destinations/"
1414

@@ -34,7 +34,7 @@ def test_list_destinations(
3434
url=url,
3535
)
3636

37-
destinations_response = client.destinations.list_destinations(
37+
destinations_response = platform_client.destinations.list_destinations(
3838
request=operations.ListDestinationsRequest()
3939
)
4040
assert destinations_response.status_code == 200
@@ -57,7 +57,7 @@ def test_list_destinations(
5757

5858

5959
def test_list_destinations_empty(
60-
httpx_mock, client: UnstructuredClient, platform_api_url: str
60+
httpx_mock, platform_client: UnstructuredClient, platform_api_url: str
6161
):
6262
url = f"{platform_api_url}/api/v1/destinations/"
6363

@@ -68,7 +68,7 @@ def test_list_destinations_empty(
6868
url=url,
6969
)
7070

71-
destinations_response = client.destinations.list_destinations(
71+
destinations_response = platform_client.destinations.list_destinations(
7272
request=operations.ListDestinationsRequest()
7373
)
7474
assert destinations_response.status_code == 200
@@ -89,7 +89,7 @@ def test_list_destinations_empty(
8989
@pytest.mark.httpx_mock(can_send_already_matched_responses=True) # in case of retries
9090
def test_list_destinations_5xx_code(
9191
httpx_mock,
92-
client: UnstructuredClient,
92+
platform_client: UnstructuredClient,
9393
platform_api_url: str,
9494
error_status_code: int,
9595
):
@@ -103,7 +103,7 @@ def test_list_destinations_5xx_code(
103103
)
104104

105105
with pytest.raises(SDKError) as excinfo:
106-
client.destinations.list_destinations(
106+
platform_client.destinations.list_destinations(
107107
request=operations.ListDestinationsRequest()
108108
)
109109
requests = httpx_mock.get_requests()
@@ -112,7 +112,7 @@ def test_list_destinations_5xx_code(
112112
assert excinfo.value.status_code == error_status_code
113113

114114

115-
def test_get_destination(httpx_mock, client: UnstructuredClient, platform_api_url: str):
115+
def test_get_destination(httpx_mock, platform_client: UnstructuredClient, platform_api_url: str):
116116
dest_id = "0c363dec-3c70-45ee-8041-481044a6e1cc"
117117
url = f"{platform_api_url}/api/v1/destinations/{dest_id}"
118118

@@ -136,7 +136,7 @@ def test_get_destination(httpx_mock, client: UnstructuredClient, platform_api_ur
136136
url=url,
137137
)
138138

139-
destination_response = client.destinations.get_destination(
139+
destination_response = platform_client.destinations.get_destination(
140140
request=operations.GetDestinationRequest(destination_id=dest_id)
141141
)
142142
assert destination_response.status_code == 200
@@ -158,7 +158,7 @@ def test_get_destination(httpx_mock, client: UnstructuredClient, platform_api_ur
158158

159159

160160
def test_get_destination_not_found(
161-
httpx_mock, client: UnstructuredClient, platform_api_url: str
161+
httpx_mock, platform_client: UnstructuredClient, platform_api_url: str
162162
):
163163
dest_id = "0c363dec-3c70-45ee-8041-481044a6e1cc"
164164
url = f"{platform_api_url}/api/v1/destinations/{dest_id}"
@@ -171,7 +171,7 @@ def test_get_destination_not_found(
171171
)
172172

173173
with pytest.raises(SDKError) as excinfo:
174-
client.destinations.get_destination(
174+
platform_client.destinations.get_destination(
175175
request=operations.GetDestinationRequest(destination_id=dest_id)
176176
)
177177

@@ -182,7 +182,7 @@ def test_get_destination_not_found(
182182

183183

184184
def test_create_destination(
185-
httpx_mock, client: UnstructuredClient, platform_api_url: str
185+
httpx_mock, platform_client: UnstructuredClient, platform_api_url: str
186186
):
187187
url = f"{platform_api_url}/api/v1/destinations/"
188188

@@ -204,7 +204,7 @@ def test_create_destination(
204204
url=url,
205205
)
206206

207-
destination_response = client.destinations.create_destination(
207+
destination_response = platform_client.destinations.create_destination(
208208
request=operations.CreateDestinationRequest(
209209
create_destination_connector=shared.CreateDestinationConnector(
210210
name="test_destination_name",
@@ -236,7 +236,7 @@ def test_create_destination(
236236

237237

238238
def test_update_destination(
239-
httpx_mock, client: UnstructuredClient, platform_api_url: str
239+
httpx_mock, platform_client: UnstructuredClient, platform_api_url: str
240240
):
241241
dest_id = "b25d4161-77a0-4e08-b65e-86f398ce15ad"
242242
url = f"{platform_api_url}/api/v1/destinations/{dest_id}"
@@ -259,7 +259,7 @@ def test_update_destination(
259259
url=url,
260260
)
261261

262-
destination_update_response = client.destinations.update_destination(
262+
destination_update_response = platform_client.destinations.update_destination(
263263
request=operations.UpdateDestinationRequest(
264264
destination_id=dest_id,
265265
update_destination_connector=shared.UpdateDestinationConnector(
@@ -291,7 +291,7 @@ def test_update_destination(
291291

292292

293293
def test_delete_destination(
294-
httpx_mock, client: UnstructuredClient, platform_api_url: str
294+
httpx_mock, platform_client: UnstructuredClient, platform_api_url: str
295295
):
296296
dest_id = "b25d4161-77a0-4e08-b65e-86f398ce15ad"
297297
url = f"{platform_api_url}/api/v1/destinations/{dest_id}"
@@ -304,7 +304,7 @@ def test_delete_destination(
304304
url=url,
305305
)
306306

307-
response = client.destinations.delete_destination(
307+
response = platform_client.destinations.delete_destination(
308308
request=operations.DeleteDestinationRequest(destination_id=dest_id)
309309
)
310310
assert response.status_code == 200

_test_contract/platform_api/test_jobs.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from unstructured_client.models.errors import SDKError
88

99

10-
def test_list_jobs(httpx_mock, client: UnstructuredClient, platform_api_url: str):
10+
def test_list_jobs(httpx_mock, platform_client: UnstructuredClient, platform_api_url: str):
1111
url = f"{platform_api_url}/api/v1/jobs/"
1212

1313
httpx_mock.add_response(
@@ -26,7 +26,7 @@ def test_list_jobs(httpx_mock, client: UnstructuredClient, platform_api_url: str
2626
url=url,
2727
)
2828

29-
jobs_response = client.jobs.list_jobs(request=operations.ListJobsRequest())
29+
jobs_response = platform_client.jobs.list_jobs(request=operations.ListJobsRequest())
3030
assert jobs_response.status_code == 200
3131

3232
requests = httpx_mock.get_requests()
@@ -44,7 +44,7 @@ def test_list_jobs(httpx_mock, client: UnstructuredClient, platform_api_url: str
4444
assert job.created_at == datetime.fromisoformat("2025-06-22T11:37:21.648+00:00")
4545

4646

47-
def test_get_job(httpx_mock, client: UnstructuredClient, platform_api_url: str):
47+
def test_get_job(httpx_mock, platform_client: UnstructuredClient, platform_api_url: str):
4848
url = f"{platform_api_url}/api/v1/jobs/fcdc4994-eea5-425c-91fa-e03f2bd8030d"
4949

5050
httpx_mock.add_response(
@@ -61,7 +61,7 @@ def test_get_job(httpx_mock, client: UnstructuredClient, platform_api_url: str):
6161
url=url,
6262
)
6363

64-
job_response = client.jobs.get_job(
64+
job_response = platform_client.jobs.get_job(
6565
request=operations.GetJobRequest(job_id="fcdc4994-eea5-425c-91fa-e03f2bd8030d")
6666
)
6767
assert job_response.status_code == 200
@@ -81,7 +81,7 @@ def test_get_job(httpx_mock, client: UnstructuredClient, platform_api_url: str):
8181

8282

8383
def test_get_job_not_found(
84-
httpx_mock, client: UnstructuredClient, platform_api_url: str
84+
httpx_mock, platform_client: UnstructuredClient, platform_api_url: str
8585
):
8686
url = f"{platform_api_url}/api/v1/jobs/fcdc4994-eea5-425c-91fa-e03f2bd8030d"
8787

@@ -94,7 +94,7 @@ def test_get_job_not_found(
9494
)
9595

9696
with pytest.raises(SDKError) as e:
97-
client.jobs.get_job(
97+
platform_client.jobs.get_job(
9898
request=operations.GetJobRequest(
9999
job_id="fcdc4994-eea5-425c-91fa-e03f2bd8030d"
100100
)
@@ -110,7 +110,7 @@ def test_get_job_not_found(
110110
assert request.url == url
111111

112112

113-
def test_get_job_error(httpx_mock, client: UnstructuredClient, platform_api_url: str):
113+
def test_get_job_error(httpx_mock, platform_client: UnstructuredClient, platform_api_url: str):
114114
url = f"{platform_api_url}/api/v1/jobs/fcdc4994-eea5-425c-91fa-e03f2bd8030d"
115115

116116
httpx_mock.add_response(
@@ -122,7 +122,7 @@ def test_get_job_error(httpx_mock, client: UnstructuredClient, platform_api_url:
122122
)
123123

124124
with pytest.raises(SDKError) as e:
125-
client.jobs.get_job(
125+
platform_client.jobs.get_job(
126126
request=operations.GetJobRequest(
127127
job_id="fcdc4994-eea5-425c-91fa-e03f2bd8030d"
128128
)
@@ -138,7 +138,7 @@ def test_get_job_error(httpx_mock, client: UnstructuredClient, platform_api_url:
138138
assert request.url == url
139139

140140

141-
def test_cancel_job(httpx_mock, client: UnstructuredClient, platform_api_url: str):
141+
def test_cancel_job(httpx_mock, platform_client: UnstructuredClient, platform_api_url: str):
142142
url = f"{platform_api_url}/api/v1/jobs/fcdc4994-eea5-425c-91fa-e03f2bd8030d/cancel"
143143

144144
httpx_mock.add_response(
@@ -152,7 +152,7 @@ def test_cancel_job(httpx_mock, client: UnstructuredClient, platform_api_url: st
152152
},
153153
)
154154

155-
cancel_response = client.jobs.cancel_job(
155+
cancel_response = platform_client.jobs.cancel_job(
156156
request=operations.CancelJobRequest(
157157
job_id="fcdc4994-eea5-425c-91fa-e03f2bd8030d"
158158
)

0 commit comments

Comments
 (0)