filters to_dict

This commit is contained in:
Jon Herron 2022-11-15 15:45:55 -05:00
parent ec68bcb24e
commit 167021e230
2 changed files with 99 additions and 0 deletions

View File

@ -18,6 +18,25 @@ class ProcessInstanceReportFilter:
end_to: Optional[int] = None
process_status: Optional[list[str]] = None
def to_dict(self) -> dict[str, str]:
"""to_dict."""
d = {}
if self.process_model_identifier is not None:
d["process_model_identifier"] = self.process_model_identifier
if self.start_from is not None:
d["start_from"] = str(self.start_from)
if self.start_to is not None:
d["start_to"] = str(self.start_to)
if self.end_from is not None:
d["end_from"] = str(self.end_from)
if self.end_to is not None:
d["end_to"] = str(self.end_to)
if self.process_status is not None:
d["process_status"] = ",".join(self.process_status)
return d
class ProcessInstanceReportService:
"""ProcessInstanceReportService."""

View File

@ -13,10 +13,90 @@ from spiffworkflow_backend.services.process_instance_report_service import (
ProcessInstanceReportFilter,
)
from spiffworkflow_backend.services.process_instance_report_service import (
ProcessInstanceReportFilter,
ProcessInstanceReportService,
)
class TestProcessInstanceReportFilter(BaseTest):
"""TestProcessInstanceReportFilter."""
def test_empty_filter_to_dict(
self,
app: Flask,
client: FlaskClient,
with_db_and_bpmn_file_cleanup: None,
with_super_admin_user: UserModel,
) -> None:
"""Docstring."""
d = ProcessInstanceReportFilter().to_dict()
assert d == {}
def test_string_value_filter_to_dict(
self,
app: Flask,
client: FlaskClient,
with_db_and_bpmn_file_cleanup: None,
with_super_admin_user: UserModel,
) -> None:
"""Docstring."""
d = ProcessInstanceReportFilter(
process_model_identifier="bob"
).to_dict()
assert d == {"process_model_identifier": "bob"}
def test_int_value_filter_to_dict(
self,
app: Flask,
client: FlaskClient,
with_db_and_bpmn_file_cleanup: None,
with_super_admin_user: UserModel,
) -> None:
"""Docstring."""
d = ProcessInstanceReportFilter(
start_from=1,
start_to=2,
end_from=3,
end_to=4,
).to_dict()
assert d == {
"start_from": "1",
"start_to": "2",
"end_from": "3",
"end_to": "4",
}
def test_list_single_value_filter_to_dict(
self,
app: Flask,
client: FlaskClient,
with_db_and_bpmn_file_cleanup: None,
with_super_admin_user: UserModel,
) -> None:
"""Docstring."""
d = ProcessInstanceReportFilter(
process_status=["bob"]
).to_dict()
assert d == {"process_status": "bob"}
def test_list_multiple_value_filter_to_dict(
self,
app: Flask,
client: FlaskClient,
with_db_and_bpmn_file_cleanup: None,
with_super_admin_user: UserModel,
) -> None:
"""Docstring."""
d = ProcessInstanceReportFilter(
process_status=["joe", "bob", "sue"]
).to_dict()
assert d == {"process_status": "joe,bob,sue"}
class TestProcessInstanceReportService(BaseTest):
"""TestProcessInstanceReportService."""