added test for removing bad json objects and fixed some comments w/ burnettk
This commit is contained in:
parent
68912ac7a6
commit
a2e55d8c8e
5
.flake8
5
.flake8
|
@ -4,6 +4,9 @@ ignore = E203,E501,RST201,RST203,RST301,W503
|
|||
max-line-length = 120
|
||||
max-complexity = 10
|
||||
docstring-convention = google
|
||||
per-file-ignores = tests/*:S101
|
||||
rst-roles = class,const,func,meth,mod,ref
|
||||
rst-directives = deprecated
|
||||
|
||||
per-file-ignores =
|
||||
# prefer naming tests descriptively rather than forcing comments
|
||||
tests/*:S101,D103
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""Common API functionality."""
|
||||
"""API Error functionality."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
@ -19,7 +19,7 @@ api_exception_blueprint = Blueprint("api_exception_blueprint", __name__)
|
|||
|
||||
|
||||
class ApiError(Exception):
|
||||
"""ApiError Class!"""
|
||||
"""ApiError Class to help handle exceptions."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -37,7 +37,7 @@ class ApiError(Exception):
|
|||
offset: int = 0,
|
||||
task_trace: dict | None = None,
|
||||
) -> None:
|
||||
"""The Init Method!"""
|
||||
"""The Init Method."""
|
||||
if task_data is None:
|
||||
task_data = {}
|
||||
if task_trace is None:
|
||||
|
@ -76,7 +76,7 @@ class ApiError(Exception):
|
|||
Exception.__init__(self, self.message)
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""This is Magic?"""
|
||||
"""Instructions to print instance as a string."""
|
||||
msg = "ApiError: % s. " % self.message
|
||||
if self.task_name:
|
||||
msg += f"Error in task '{self.task_name}' ({self.task_id}). "
|
||||
|
@ -125,7 +125,7 @@ class ApiError(Exception):
|
|||
|
||||
@staticmethod
|
||||
def remove_unserializeable_from_dict(my_dict: dict) -> dict:
|
||||
"""Method name is good."""
|
||||
"""Removes unserializeable from dict."""
|
||||
keys_to_delete = []
|
||||
for key, value in my_dict.items():
|
||||
if not ApiError.is_jsonable(value):
|
||||
|
|
|
@ -5,12 +5,22 @@ from flask_bpmn.api.api_error import ApiError
|
|||
|
||||
|
||||
def test_is_jsonable_can_succeed() -> None:
|
||||
"""It exits with a status code of zero."""
|
||||
result = ApiError.is_jsonable("This is a string and should pass json.dumps")
|
||||
assert result is True
|
||||
|
||||
|
||||
def test_is_jsonable_can_fail() -> None:
|
||||
"""It exits with a status code of zero."""
|
||||
result = ApiError.is_jsonable(io.StringIO("BAD JSON OBJECT"))
|
||||
assert result is False
|
||||
|
||||
|
||||
def test_remove_unserializeable_from_dict_succeeds() -> None:
|
||||
initial_dict_object = {
|
||||
"valid_key": "valid_value",
|
||||
"invalid_key_value": io.StringIO("BAD JSON OBJECT"),
|
||||
}
|
||||
final_dict_object = {
|
||||
"valid_key": "valid_value",
|
||||
}
|
||||
result = ApiError.remove_unserializeable_from_dict(initial_dict_object)
|
||||
assert result == final_dict_object
|
||||
|
|
Loading…
Reference in New Issue