From 87b4fcb18b368bed21aa1499e7836b0f5f9afcfc Mon Sep 17 00:00:00 2001 From: Jon Herron Date: Tue, 15 Nov 2022 15:45:55 -0500 Subject: [PATCH] filters to_dict --- .../process_instance_report_service.py | 19 +++++ .../test_process_instance_report_service.py | 80 +++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py index f997ef7e5..95ba93d70 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_report_service.py @@ -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.""" diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_report_service.py b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_report_service.py index 48fd52ba3..0e3227a1b 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_report_service.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_report_service.py @@ -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."""