Skip to content

Commit 59c4936

Browse files
committed
Update exception tests.
1 parent 722c39c commit 59c4936

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

tests/test_async_http_client.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
from unittest.mock import AsyncMock
66

77
from tests.test_sync_http_client import STATUS_CODE_TO_EXCEPTION_MAPPING
8-
from workos.exceptions import BadRequestException, BaseRequestException, ServerException
8+
from workos.exceptions import (
9+
BadRequestException,
10+
BaseRequestException,
11+
ConflictException,
12+
ServerException,
13+
)
914
from workos.utils.http_client import AsyncHTTPClient
1015

1116

@@ -186,8 +191,6 @@ async def test_request_exceptions_include_expected_request_data(
186191
except expected_exception as ex: # type: ignore
187192
assert ex.message == response_message
188193
assert ex.request_id == request_id
189-
except Exception as ex:
190-
# This'll fail for sure here but... just using the nice error that'd come up
191194
assert ex.__class__ == expected_exception
192195

193196
async def test_bad_request_exceptions_include_expected_request_data(self):
@@ -210,7 +213,6 @@ async def test_bad_request_exceptions_include_expected_request_data(self):
210213
str(ex)
211214
== "(message=No message, request_id=request-123, error=example_error, error_description=Example error description)"
212215
)
213-
except Exception as ex:
214216
assert ex.__class__ == BadRequestException
215217

216218
async def test_bad_request_exceptions_exclude_expected_request_data(self):
@@ -228,7 +230,6 @@ async def test_bad_request_exceptions_exclude_expected_request_data(self):
228230
await self.http_client.request("bad_place")
229231
except BadRequestException as ex:
230232
assert str(ex) == "(message=No message, request_id=request-123, foo=bar)"
231-
except Exception as ex:
232233
assert ex.__class__ == BadRequestException
233234

234235
async def test_request_bad_body_raises_expected_exception_with_request_data(self):
@@ -247,10 +248,24 @@ async def test_request_bad_body_raises_expected_exception_with_request_data(self
247248
except ServerException as ex:
248249
assert ex.message == None
249250
assert ex.request_id == request_id
250-
except Exception as ex:
251-
# This'll fail for sure here but... just using the nice error that'd come up
252251
assert ex.__class__ == ServerException
253252

253+
async def test_conflict_exception(self):
254+
request_id = "request-123"
255+
256+
self.http_client._client.request = AsyncMock(
257+
return_value=httpx.Response(
258+
status_code=409,
259+
headers={"X-Request-ID": request_id},
260+
),
261+
)
262+
263+
try:
264+
await self.http_client.request("bad_place")
265+
except ConflictException as ex:
266+
assert str(ex) == "(message=No message, request_id=request-123)"
267+
assert ex.__class__ == ConflictException
268+
254269
async def test_request_includes_base_headers(
255270
self, capture_and_mock_http_client_request
256271
):

tests/test_sync_http_client.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ def test_request_exceptions_include_expected_request_data(
201201
except expected_exception as ex: # type: ignore
202202
assert ex.message == response_message
203203
assert ex.request_id == request_id
204-
except Exception as ex:
205-
# This'll fail for sure here but... just using the nice error that'd come up
206204
assert ex.__class__ == expected_exception
207205

208206
def test_bad_request_exceptions_include_request_data(self):
@@ -229,7 +227,6 @@ def test_bad_request_exceptions_include_request_data(self):
229227
str(ex)
230228
== "(message=No message, request_id=request-123, error=example_error, error_description=Example error description, foo=bar)"
231229
)
232-
except Exception as ex:
233230
assert ex.__class__ == BadRequestException
234231

235232
def test_request_bad_body_raises_expected_exception_with_request_data(self):
@@ -248,8 +245,6 @@ def test_request_bad_body_raises_expected_exception_with_request_data(self):
248245
except ServerException as ex:
249246
assert ex.message == None
250247
assert ex.request_id == request_id
251-
except Exception as ex:
252-
# This'll fail for sure here but... just using the nice error that'd come up
253248
assert ex.__class__ == ServerException
254249

255250
def test_conflict_exception(self):
@@ -266,7 +261,6 @@ def test_conflict_exception(self):
266261
self.http_client.request("bad_place")
267262
except ConflictException as ex:
268263
assert str(ex) == "(message=No message, request_id=request-123)"
269-
except Exception as ex:
270264
assert ex.__class__ == ConflictException
271265

272266
def test_request_includes_base_headers(self, capture_and_mock_http_client_request):

0 commit comments

Comments
 (0)