This commit is contained in:
jasquat 2022-12-12 15:36:03 -05:00
parent 52d61fabad
commit f6462d83af
5 changed files with 34 additions and 13 deletions

View File

@ -9,7 +9,7 @@ from sqlalchemy import UniqueConstraint
class SpecReferenceNotFoundError(Exception): class SpecReferenceNotFoundError(Exception):
pass """SpecReferenceNotFoundError."""
@dataclass() @dataclass()

View File

@ -65,7 +65,8 @@ from spiffworkflow_backend.models.process_model import ProcessModelInfo
from spiffworkflow_backend.models.process_model import ProcessModelInfoSchema from spiffworkflow_backend.models.process_model import ProcessModelInfoSchema
from spiffworkflow_backend.models.secret_model import SecretModel from spiffworkflow_backend.models.secret_model import SecretModel
from spiffworkflow_backend.models.secret_model import SecretModelSchema from spiffworkflow_backend.models.secret_model import SecretModelSchema
from spiffworkflow_backend.models.spec_reference import SpecReferenceCache, SpecReferenceNotFoundError from spiffworkflow_backend.models.spec_reference import SpecReferenceCache
from spiffworkflow_backend.models.spec_reference import SpecReferenceNotFoundError
from spiffworkflow_backend.models.spec_reference import SpecReferenceSchema from spiffworkflow_backend.models.spec_reference import SpecReferenceSchema
from spiffworkflow_backend.models.spiff_logging import SpiffLoggingModel from spiffworkflow_backend.models.spiff_logging import SpiffLoggingModel
from spiffworkflow_backend.models.spiff_step_details import SpiffStepDetailsModel from spiffworkflow_backend.models.spiff_step_details import SpiffStepDetailsModel
@ -1073,7 +1074,9 @@ def process_instance_report_column_list() -> flask.wrappers.Response:
def process_instance_show( def process_instance_show(
modified_process_model_identifier: str, process_instance_id: int, process_identifier: Optional[str] = None modified_process_model_identifier: str,
process_instance_id: int,
process_identifier: Optional[str] = None,
) -> flask.wrappers.Response: ) -> flask.wrappers.Response:
"""Create_process_instance.""" """Create_process_instance."""
process_model_identifier = modified_process_model_identifier.replace(":", "/") process_model_identifier = modified_process_model_identifier.replace(":", "/")
@ -1083,11 +1086,17 @@ def process_instance_show(
process_model_with_diagram = None process_model_with_diagram = None
name_of_file_with_diagram = None name_of_file_with_diagram = None
if process_identifier: if process_identifier:
spec_reference = SpecReferenceCache.query.filter_by(identifier=process_identifier).first() spec_reference = SpecReferenceCache.query.filter_by(
identifier=process_identifier
).first()
if spec_reference is None: if spec_reference is None:
raise SpecReferenceNotFoundError(f"Could not find given process identifier in the cache: {process_identifier}") raise SpecReferenceNotFoundError(
f"Could not find given process identifier in the cache: {process_identifier}"
)
process_model_with_diagram = ProcessModelService.get_process_model(spec_reference.process_model_id) process_model_with_diagram = ProcessModelService.get_process_model(
spec_reference.process_model_id
)
name_of_file_with_diagram = spec_reference.file_name name_of_file_with_diagram = spec_reference.file_name
else: else:
process_model_with_diagram = get_process_model(process_model_identifier) process_model_with_diagram = get_process_model(process_model_identifier)
@ -1104,7 +1113,9 @@ def process_instance_show(
).decode("utf-8") ).decode("utf-8")
else: else:
bpmn_xml_file_contents = GitService.get_instance_file_contents_for_revision( bpmn_xml_file_contents = GitService.get_instance_file_contents_for_revision(
process_model_with_diagram, process_instance.bpmn_version_control_identifier, file_name=name_of_file_with_diagram process_model_with_diagram,
process_instance.bpmn_version_control_identifier,
file_name=name_of_file_with_diagram,
) )
process_instance.bpmn_xml_file_contents = bpmn_xml_file_contents process_instance.bpmn_xml_file_contents = bpmn_xml_file_contents

View File

@ -46,7 +46,10 @@ class GitService:
@classmethod @classmethod
def get_instance_file_contents_for_revision( def get_instance_file_contents_for_revision(
cls, process_model: ProcessModelInfo, revision: str, file_name: Optional[str] = None cls,
process_model: ProcessModelInfo,
revision: str,
file_name: Optional[str] = None,
) -> str: ) -> str:
"""Get_instance_file_contents_for_revision.""" """Get_instance_file_contents_for_revision."""
bpmn_spec_absolute_dir = current_app.config["BPMN_SPEC_ABSOLUTE_DIR"] bpmn_spec_absolute_dir = current_app.config["BPMN_SPEC_ABSOLUTE_DIR"]

View File

@ -1174,6 +1174,7 @@ class TestProcessApi(BaseTest):
with_db_and_bpmn_file_cleanup: None, with_db_and_bpmn_file_cleanup: None,
with_super_admin_user: UserModel, with_super_admin_user: UserModel,
) -> None: ) -> None:
"""Test_process_instance_show_with_specified_process_identifier."""
process_model_id = "call_activity_nested" process_model_id = "call_activity_nested"
process_model_identifier = self.create_group_and_model_with_bpmn( process_model_identifier = self.create_group_and_model_with_bpmn(
client=client, client=client,
@ -1182,7 +1183,9 @@ class TestProcessApi(BaseTest):
process_model_id=process_model_id, process_model_id=process_model_id,
bpmn_file_location="call_activity_nested", bpmn_file_location="call_activity_nested",
) )
spec_reference = SpecReferenceCache.query.filter_by(identifier="Level2b").first() spec_reference = SpecReferenceCache.query.filter_by(
identifier="Level2b"
).first()
assert spec_reference assert spec_reference
modified_process_model_identifier = ( modified_process_model_identifier = (
self.modify_process_identifier_for_path_param(process_model_identifier) self.modify_process_identifier_for_path_param(process_model_identifier)
@ -1211,8 +1214,8 @@ class TestProcessApi(BaseTest):
with open(process_instance_file_path) as f_open: with open(process_instance_file_path) as f_open:
xml_file_contents = f_open.read() xml_file_contents = f_open.read()
assert show_response.json["bpmn_xml_file_contents"] != xml_file_contents assert show_response.json["bpmn_xml_file_contents"] != xml_file_contents
spec_reference_file_path = ( spec_reference_file_path = os.path.join(
os.path.join(file_system_root, spec_reference.relative_path) file_system_root, spec_reference.relative_path
) )
with open(spec_reference_file_path) as f_open: with open(spec_reference_file_path) as f_open:
xml_file_contents = f_open.read() xml_file_contents = f_open.read()

View File

@ -7,6 +7,7 @@ from spiffworkflow_backend.services.git_service import GitService
class TestGitService(BaseTest): class TestGitService(BaseTest):
"""TestGitService."""
def test_strips_output_of_stdout_from_command( def test_strips_output_of_stdout_from_command(
self, self,
@ -14,5 +15,8 @@ class TestGitService(BaseTest):
client: FlaskClient, client: FlaskClient,
with_db_and_bpmn_file_cleanup: None, with_db_and_bpmn_file_cleanup: None,
) -> None: ) -> None:
output = GitService.run_shell_command_to_get_stdout(["echo", ' This output should not end in space or newline \n']) """Test_strips_output_of_stdout_from_command."""
assert output == 'This output should not end in space or newline' output = GitService.run_shell_command_to_get_stdout(
["echo", " This output should not end in space or newline \n"]
)
assert output == "This output should not end in space or newline"