|
6 | 6 | from pydantic import ValidationError |
7 | 7 | from pydantic import field_validator |
8 | 8 |
|
| 9 | +from scim2_models import Context |
9 | 10 | from scim2_models import Error |
10 | 11 | from scim2_models import InvalidFilterException |
11 | 12 | from scim2_models import InvalidPathException |
@@ -429,3 +430,44 @@ def test_from_error_type_error(): |
429 | 430 | """from_error() raises TypeError for non-Error input.""" |
430 | 431 | with pytest.raises(TypeError, match="Expected Error"): |
431 | 432 | SCIMException.from_error("not an error") |
| 433 | + |
| 434 | + |
| 435 | +def test_scim_ctx_default_none(): |
| 436 | + """SCIMException has scim_ctx=None by default.""" |
| 437 | + exc = SCIMException() |
| 438 | + assert exc.scim_ctx is None |
| 439 | + |
| 440 | + |
| 441 | +def test_scim_ctx_set_directly(): |
| 442 | + """SCIMException can have scim_ctx set directly.""" |
| 443 | + exc = SCIMException(detail="Test error", scim_ctx=Context.RESOURCE_CREATION_REQUEST) |
| 444 | + assert exc.scim_ctx == Context.RESOURCE_CREATION_REQUEST |
| 445 | + assert exc.detail == "Test error" |
| 446 | + |
| 447 | + |
| 448 | +def test_scim_ctx_on_subclass(): |
| 449 | + """Exception subclasses can have scim_ctx set.""" |
| 450 | + exc = InvalidValueException( |
| 451 | + detail="Invalid input", |
| 452 | + attribute="userName", |
| 453 | + scim_ctx=Context.RESOURCE_CREATION_REQUEST, |
| 454 | + ) |
| 455 | + assert exc.scim_ctx == Context.RESOURCE_CREATION_REQUEST |
| 456 | + assert exc.attribute == "userName" |
| 457 | + |
| 458 | + |
| 459 | +def test_from_error_with_scim_ctx(): |
| 460 | + """from_error() passes scim_ctx to the created exception.""" |
| 461 | + error = Error(status=400, scim_type="invalidValue", detail="Missing required") |
| 462 | + exc = SCIMException.from_error(error, scim_ctx=Context.RESOURCE_CREATION_RESPONSE) |
| 463 | + assert isinstance(exc, InvalidValueException) |
| 464 | + assert exc.scim_ctx == Context.RESOURCE_CREATION_RESPONSE |
| 465 | + assert exc.detail == "Missing required" |
| 466 | + |
| 467 | + |
| 468 | +def test_from_error_without_scim_ctx(): |
| 469 | + """from_error() creates exception with scim_ctx=None when not provided.""" |
| 470 | + error = Error(status=400, scim_type="invalidFilter", detail="Bad filter") |
| 471 | + exc = SCIMException.from_error(error) |
| 472 | + assert isinstance(exc, InvalidFilterException) |
| 473 | + assert exc.scim_ctx is None |
0 commit comments