filters to_dict
This commit is contained in:
parent
0520a9f9f6
commit
87b4fcb18b
|
@ -18,6 +18,25 @@ class ProcessInstanceReportFilter:
|
||||||
end_to: Optional[int] = None
|
end_to: Optional[int] = None
|
||||||
process_status: Optional[list[str]] = 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:
|
class ProcessInstanceReportService:
|
||||||
"""ProcessInstanceReportService."""
|
"""ProcessInstanceReportService."""
|
||||||
|
|
|
@ -13,10 +13,90 @@ from spiffworkflow_backend.services.process_instance_report_service import (
|
||||||
ProcessInstanceReportFilter,
|
ProcessInstanceReportFilter,
|
||||||
)
|
)
|
||||||
from spiffworkflow_backend.services.process_instance_report_service import (
|
from spiffworkflow_backend.services.process_instance_report_service import (
|
||||||
|
ProcessInstanceReportFilter,
|
||||||
ProcessInstanceReportService,
|
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):
|
class TestProcessInstanceReportService(BaseTest):
|
||||||
"""TestProcessInstanceReportService."""
|
"""TestProcessInstanceReportService."""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue