This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5516040
commit fbf0ed7
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from typing import Any, Dict, List, Optional | ||
|
||
from def_result.ResultDetails.ErrorDetail import ErrorDetail | ||
|
||
|
||
class ValidationError(ErrorDetail): | ||
""" Represents a validation error.""" | ||
def __init__(self, title: Optional[str] = "One or more validation errors occurred", | ||
message: Optional[str] = None, | ||
code: Optional[int] = 400, | ||
errors: Optional[Dict[str, str]] = None, | ||
exception: Optional[Exception] = None, | ||
more_data: Optional[List[Any]] = None): | ||
super().__init__(title=title, message=message, code=code, errors=errors, exception=exception, | ||
more_data=more_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import unittest | ||
|
||
from def_result.ResultDetails.Errors.ValidationError import ValidationError | ||
from tests.helpers import assert_error_detail, assert_result_detail | ||
|
||
|
||
class TestValidationError(unittest.TestCase): | ||
def test_init_without_args(self): | ||
detail = ValidationError() | ||
|
||
assert_error_detail(test_class=self, error_detail=detail, title="One or more validation errors occurred", | ||
code=400) | ||
|
||
def test_init_with_args(self): | ||
exception = Exception("fake") | ||
detail = ValidationError(title="title", message="message", code=100, more_data=["message"], | ||
errors={"key": "message"}, exception=exception) | ||
|
||
assert_error_detail(test_class=self, error_detail=detail, title="title", | ||
code=100, message="message", more_data=["message"], | ||
errors={"key": "message"}, exception=exception) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |