Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
feat: add NotFoundError
Browse files Browse the repository at this point in the history
  • Loading branch information
HamidMolareza committed Mar 31, 2023
1 parent 122e667 commit 2321dc3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
29 changes: 29 additions & 0 deletions def_result/ResultDetails/Errors/NotFoundError.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Any, Dict, List, Optional

from def_result.ResultDetails.ErrorDetail import ErrorDetail


class NotFoundError(ErrorDetail):
"""
Stores the error details of a not found error.
Inherits from ErrorDetail class.
"""
def __init__(self, title: Optional[str] = "NotFound Error",
message: Optional[str] = None,
code: Optional[int] = 404,
errors: Optional[Dict[str, str]] = None,
exception: Optional[Exception] = None,
more_data: Optional[List[Any]] = None):
"""
Initializes a new instance of the NotFoundError class.
:param title: The title of the error.
:param message: The message associated with the error.
:param code: The HTTP status code associated with the error.
:param errors: The dictionary of errors associated with the error.
:param exception: The exception associated with the error.
:param more_data: Any additional data associated with the error.
"""
super().__init__(title=title, message=message, code=code, errors=errors, exception=exception,
more_data=more_data)
25 changes: 25 additions & 0 deletions tests/ResultDetails/Errors/test_NotFoundError.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import unittest

from def_result.ResultDetails.Errors.NotFoundError import NotFoundError
from tests.helpers import assert_error_detail


class TestNotFoundError(unittest.TestCase):
def test_init_without_args(self):
detail = NotFoundError()

assert_error_detail(test_class=self, error_detail=detail, title="NotFound Error",
code=404)

def test_init_with_args(self):
exception = Exception("fake")
detail = NotFoundError(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()

0 comments on commit 2321dc3

Please sign in to comment.