|
10 | 10 | BadRequestException, |
11 | 11 | BaseRequestException, |
12 | 12 | ConflictException, |
| 13 | + EmailVerificationRequiredException, |
13 | 14 | ServerException, |
14 | 15 | ) |
15 | 16 | from workos.utils.http_client import SyncHTTPClient |
@@ -263,6 +264,57 @@ def test_conflict_exception(self): |
263 | 264 | assert str(ex) == "(message=No message, request_id=request-123)" |
264 | 265 | assert ex.__class__ == ConflictException |
265 | 266 |
|
| 267 | + def test_email_verification_required_exception(self): |
| 268 | + request_id = "request-123" |
| 269 | + email_verification_id = "email_verification_01J6K4PMSWQXVFGF5ZQJXC6VC8" |
| 270 | + |
| 271 | + self.http_client._client.request = MagicMock( |
| 272 | + return_value=httpx.Response( |
| 273 | + status_code=403, |
| 274 | + json={ |
| 275 | + "message": "Please verify your email to authenticate via password.", |
| 276 | + "code": "email_verification_required", |
| 277 | + "email_verification_id": email_verification_id, |
| 278 | + }, |
| 279 | + headers={"X-Request-ID": request_id}, |
| 280 | + ), |
| 281 | + ) |
| 282 | + |
| 283 | + try: |
| 284 | + self.http_client.request("bad_place") |
| 285 | + except EmailVerificationRequiredException as ex: |
| 286 | + assert ( |
| 287 | + ex.message == "Please verify your email to authenticate via password." |
| 288 | + ) |
| 289 | + assert ex.code == "email_verification_required" |
| 290 | + assert ex.email_verification_id == email_verification_id |
| 291 | + assert ex.request_id == request_id |
| 292 | + assert ex.__class__ == EmailVerificationRequiredException |
| 293 | + assert isinstance(ex, AuthorizationException) |
| 294 | + |
| 295 | + def test_regular_authorization_exception_still_raised(self): |
| 296 | + request_id = "request-123" |
| 297 | + |
| 298 | + self.http_client._client.request = MagicMock( |
| 299 | + return_value=httpx.Response( |
| 300 | + status_code=403, |
| 301 | + json={ |
| 302 | + "message": "You do not have permission to access this resource.", |
| 303 | + "code": "forbidden", |
| 304 | + }, |
| 305 | + headers={"X-Request-ID": request_id}, |
| 306 | + ), |
| 307 | + ) |
| 308 | + |
| 309 | + try: |
| 310 | + self.http_client.request("bad_place") |
| 311 | + except AuthorizationException as ex: |
| 312 | + assert ex.message == "You do not have permission to access this resource." |
| 313 | + assert ex.code == "forbidden" |
| 314 | + assert ex.request_id == request_id |
| 315 | + assert ex.__class__ == AuthorizationException |
| 316 | + assert not isinstance(ex, EmailVerificationRequiredException) |
| 317 | + |
266 | 318 | def test_request_includes_base_headers(self, capture_and_mock_http_client_request): |
267 | 319 | request_kwargs = capture_and_mock_http_client_request(self.http_client, {}, 200) |
268 | 320 |
|
|
0 commit comments