feat: implement blog project with CI pipeline
This commit is contained in:
87
tests/unit/test_exceptions.py
Normal file
87
tests/unit/test_exceptions.py
Normal file
@@ -0,0 +1,87 @@
|
||||
from app.core.exceptions import (
|
||||
AppException,
|
||||
ForbiddenError,
|
||||
NotFoundError,
|
||||
UnauthorizedError,
|
||||
ValidationError,
|
||||
)
|
||||
|
||||
|
||||
class TestAppException:
|
||||
def test_default_status_code(self) -> None:
|
||||
exc = AppException(message="Test error")
|
||||
assert exc.message == "Test error"
|
||||
assert exc.status_code == 500
|
||||
|
||||
def test_custom_status_code(self) -> None:
|
||||
exc = AppException(message="Custom error", status_code=400)
|
||||
assert exc.message == "Custom error"
|
||||
assert exc.status_code == 400
|
||||
|
||||
def test_string_representation(self) -> None:
|
||||
exc = AppException(message="Error message")
|
||||
assert str(exc) == "Error message"
|
||||
|
||||
|
||||
class TestNotFoundError:
|
||||
def test_default_message(self) -> None:
|
||||
exc = NotFoundError()
|
||||
assert exc.message == "Resource not found"
|
||||
assert exc.status_code == 404
|
||||
|
||||
def test_custom_message(self) -> None:
|
||||
exc = NotFoundError(message="Item not found")
|
||||
assert exc.message == "Item not found"
|
||||
assert exc.status_code == 404
|
||||
|
||||
def test_is_subclass_of_app_exception(self) -> None:
|
||||
exc = NotFoundError()
|
||||
assert isinstance(exc, AppException)
|
||||
|
||||
|
||||
class TestValidationError:
|
||||
def test_default_message(self) -> None:
|
||||
exc = ValidationError()
|
||||
assert exc.message == "Validation failed"
|
||||
assert exc.status_code == 400
|
||||
|
||||
def test_custom_message(self) -> None:
|
||||
exc = ValidationError(message="Invalid email format")
|
||||
assert exc.message == "Invalid email format"
|
||||
assert exc.status_code == 400
|
||||
|
||||
def test_is_subclass_of_app_exception(self) -> None:
|
||||
exc = ValidationError()
|
||||
assert isinstance(exc, AppException)
|
||||
|
||||
|
||||
class TestUnauthorizedError:
|
||||
def test_default_message(self) -> None:
|
||||
exc = UnauthorizedError()
|
||||
assert exc.message == "Unauthorized"
|
||||
assert exc.status_code == 401
|
||||
|
||||
def test_custom_message(self) -> None:
|
||||
exc = UnauthorizedError(message="Invalid credentials")
|
||||
assert exc.message == "Invalid credentials"
|
||||
assert exc.status_code == 401
|
||||
|
||||
def test_is_subclass_of_app_exception(self) -> None:
|
||||
exc = UnauthorizedError()
|
||||
assert isinstance(exc, AppException)
|
||||
|
||||
|
||||
class TestForbiddenError:
|
||||
def test_default_message(self) -> None:
|
||||
exc = ForbiddenError()
|
||||
assert exc.message == "Forbidden"
|
||||
assert exc.status_code == 403
|
||||
|
||||
def test_custom_message(self) -> None:
|
||||
exc = ForbiddenError(message="Access denied")
|
||||
assert exc.message == "Access denied"
|
||||
assert exc.status_code == 403
|
||||
|
||||
def test_is_subclass_of_app_exception(self) -> None:
|
||||
exc = ForbiddenError()
|
||||
assert isinstance(exc, AppException)
|
||||
Reference in New Issue
Block a user