Download tests/unit/test_errors.py from paisaly/backend: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/spaces/paisaly/backend/resolve/main/tests/unit/test_errors.py
- Command line
-
hf download hf://spaces/paisaly/backend/tests/unit/test_errors.py
-
curl -L -o test_errors.py https://huggingface.co/spaces/paisaly/backend/resolve/main/tests/unit/test_errors.py
2.1 kB
| """Unit tests for AppError hierarchy.""" | |
| import pytest | |
| from app.errors import ( | |
| AuthenticationError, | |
| ConflictError, | |
| ForbiddenError, | |
| NotFoundError, | |
| RateLimitError, | |
| ValidationError, | |
| ) | |
| class TestAppErrorSubclasses: | |
| def test_validation_error(self): | |
| e = ValidationError("bad input") | |
| assert e.status_code == 400 | |
| assert e.error_code == "validation_error" | |
| assert e.message == "bad input" | |
| def test_authentication_error(self): | |
| e = AuthenticationError("not authenticated") | |
| assert e.status_code == 401 | |
| assert e.error_code == "authentication_error" | |
| def test_forbidden_error(self): | |
| e = ForbiddenError("not allowed") | |
| assert e.status_code == 403 | |
| assert e.error_code == "forbidden" | |
| def test_not_found_error(self): | |
| e = NotFoundError("resource missing") | |
| assert e.status_code == 404 | |
| assert e.error_code == "not_found" | |
| def test_conflict_error(self): | |
| e = ConflictError("already exists") | |
| assert e.status_code == 409 | |
| assert e.error_code == "conflict" | |
| def test_rate_limit_error(self): | |
| e = RateLimitError("slow down") | |
| assert e.status_code == 429 | |
| assert e.error_code == "rate_limit_exceeded" | |
| class TestAppErrorToDict: | |
| def test_basic(self): | |
| e = NotFoundError("url not found") | |
| assert e.to_dict() == {"error": "url not found", "code": "not_found"} | |
| def test_optional_key_present(self, kwargs, key, value): | |
| e = ValidationError("invalid", **kwargs) | |
| assert e.to_dict()[key] == value | |
| def test_no_optional_keys_when_absent(self): | |
| d = NotFoundError("missing").to_dict() | |
| assert "field" not in d | |
| assert "details" not in d | |