Skip to content

Commit 9e9fa0a

Browse files
committed
Merge branch 'main' into python-v2-migration
2 parents 340df96 + 5f99db3 commit 9e9fa0a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
This is a Python client for the [Unstructured API](https://docs.unstructured.io/api-reference/api-services/overview).
2727

28-
Please refer to the [Unstructured docs](https://docs.unstructured.io/api-reference/api-services/sdk) for a full guide to using the client.
28+
Please refer to the [Unstructured docs](https://docs.unstructured.io/api-reference/api-services/sdk-python) for a full guide to using the client.
2929

3030
<!-- Start SDK Installation [installation] -->
3131
## SDK Installation

_test_unstructured_client/unit/test_custom_hooks.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,40 @@ def mock_post(request):
8888
assert bool(pattern.search(caplog.text))
8989

9090

91+
@pytest.mark.parametrize(
92+
("status_code", "expect_retry"),
93+
[
94+
[500, False],
95+
[502, True],
96+
[503, True],
97+
[504, True],
98+
]
99+
)
100+
def test_unit_number_of_retries_in_5xx(status_code: int, expect_retry: bool):
101+
filename = "README.md"
102+
backoff_strategy = BackoffStrategy(
103+
initial_interval=1, max_interval=10, exponent=1.5, max_elapsed_time=300
104+
)
105+
retries = RetryConfig(
106+
strategy="backoff", backoff=backoff_strategy, retry_connection_errors=True
107+
)
108+
109+
with requests_mock.Mocker() as mock:
110+
mock.post("https://api.unstructuredapp.io/general/v0/general", status_code=status_code)
111+
session = UnstructuredClient(api_key_auth=FAKE_KEY)
112+
113+
with open(filename, "rb") as f:
114+
files = shared.Files(content=f.read(), file_name=filename)
115+
116+
req = shared.PartitionParameters(files=files)
117+
with pytest.raises(Exception, match=f"unknown content-type received: None: Status {status_code}"):
118+
session.general.partition(req, retries=retries)
119+
if expect_retry:
120+
assert len(mock.request_history) > 1
121+
else:
122+
assert len(mock.request_history) == 1
123+
124+
91125
def test_unit_backoff_strategy_logs_retries_connection_error(caplog):
92126
caplog.set_level(logging.INFO)
93127
filename = "README.md"

0 commit comments

Comments
 (0)