55from unittest .mock import AsyncMock
66
77from 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+ )
914from 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 ):
0 commit comments