prepare results wrapping for error handling architecture
This commit is contained in:
@@ -76,7 +76,7 @@ def test_status_handler_api_error():
|
||||
assert new_err.api_server_error == api_err
|
||||
|
||||
|
||||
def test_status_handler_raising():
|
||||
def test_status_handler_unwrap():
|
||||
status_hdlr = errors.StatusHandler()
|
||||
|
||||
# success: should not raise
|
||||
@@ -121,3 +121,47 @@ def test_status_handler_raising():
|
||||
assert description in descr
|
||||
assert msg in descr
|
||||
raise err
|
||||
|
||||
|
||||
def test_status_handler_exception_parsing():
|
||||
status_hdlr = errors.StatusHandler()
|
||||
test_message = "Test Exception"
|
||||
test_code = 110
|
||||
exception = ValueError(test_message)
|
||||
status = status_hdlr.exception_to_error(exception, test_code)
|
||||
assert status.code == test_code
|
||||
assert status.description == exception.__class__.__name__
|
||||
assert status.message == test_message
|
||||
|
||||
|
||||
def test_not_set():
|
||||
not_set = errors.NotSet()
|
||||
# using slots, dynamic attribute generation should not be possible
|
||||
with pytest.raises(AttributeError):
|
||||
not_set.test = "try to set value" # type: ignore
|
||||
|
||||
|
||||
def test_result_wrapper_class():
|
||||
test_result = 10
|
||||
error_code = 146
|
||||
twrapper: errors.ResultWrapper[int] = errors.ResultWrapper(
|
||||
result=test_result,
|
||||
exception=None,
|
||||
code_on_error=error_code,
|
||||
)
|
||||
assert twrapper.status == errors.STATUS_HANDLER.SUCCESS
|
||||
assert twrapper.result == test_result
|
||||
assert twrapper.status.code != error_code
|
||||
# test for no result
|
||||
test_result = errors.NotSet()
|
||||
test_message = "Test of error message"
|
||||
exception = ValueError(test_message)
|
||||
twrapper: errors.ResultWrapper[int] = errors.ResultWrapper(
|
||||
result=test_result,
|
||||
exception=exception,
|
||||
code_on_error=error_code,
|
||||
)
|
||||
assert twrapper.status != errors.STATUS_HANDLER.SUCCESS
|
||||
assert twrapper.status.code == error_code
|
||||
with pytest.raises(errors.WAccessResultDespiteError):
|
||||
twrapper.result
|
||||
|
||||
Reference in New Issue
Block a user