Skip to content

Commit e81f7ac

Browse files
committed
Fix unit tests
1 parent a1d1e2f commit e81f7ac

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

_test_unstructured_client/unit/test_custom_hooks.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,32 @@ def test_unit_number_of_retries_in_5xx(status_code: int, expect_retry: bool):
106106
strategy="backoff", backoff=backoff_strategy, retry_connection_errors=True
107107
)
108108

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)
109+
number_of_requests = [0]
110+
def mock_post(request):
111+
if request.url == "https://api.unstructuredapp.io/general/v0/general" and request.method == "POST":
112+
number_of_requests[0] += 1
113+
return Response(status_code, request=request)
114+
115+
116+
transport = httpx.MockTransport(mock_post)
117+
client = httpx.Client(transport=transport)
118+
session = UnstructuredClient(api_key_auth=FAKE_KEY, client=client)
119+
120+
121+
with open(filename, "rb") as f:
122+
files = shared.Files(content=f.read(), file_name=filename)
123+
124+
req = operations.PartitionRequest(
125+
shared.PartitionParameters(files=files)
126+
)
112127

113-
with open(filename, "rb") as f:
114-
files = shared.Files(content=f.read(), file_name=filename)
128+
with pytest.raises(Exception, match=f"Status {status_code}"):
129+
session.general.partition(req, retries=retries)
115130

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)
119131
if expect_retry:
120-
assert len(mock.request_history) > 1
132+
assert number_of_requests[0] > 1
121133
else:
122-
assert len(mock.request_history) == 1
134+
assert number_of_requests[0] == 1
123135

124136

125137
def test_unit_backoff_strategy_logs_retries_connection_error(caplog):

0 commit comments

Comments
 (0)