ensure the primary process file and id are set when adding a new bpmn file w/ burnettk
This commit is contained in:
parent
036055dc59
commit
d8c5e99ac3
|
@ -34,8 +34,8 @@ class ProcessModelInfo:
|
|||
is_master_spec: bool | None = False
|
||||
standalone: bool | None = False
|
||||
library: bool | None = False
|
||||
primary_file_name: str | None = ""
|
||||
primary_process_id: str | None = ""
|
||||
primary_file_name: str | None = None
|
||||
primary_process_id: str | None = None
|
||||
libraries: list[str] = field(default_factory=list)
|
||||
display_order: int | None = 0
|
||||
is_review: bool = False
|
||||
|
|
|
@ -310,8 +310,6 @@ class ProcessModelService(FileSystemService):
|
|||
is_master_spec=is_master,
|
||||
display_name=name,
|
||||
description="",
|
||||
primary_process_id="",
|
||||
primary_file_name="",
|
||||
display_order=0,
|
||||
is_review=False,
|
||||
libraries=[],
|
||||
|
|
|
@ -24,6 +24,7 @@ from spiffworkflow_backend.models.message_triggerable_process_model import (
|
|||
)
|
||||
from spiffworkflow_backend.models.process_model import ProcessModelInfo
|
||||
from spiffworkflow_backend.services.file_system_service import FileSystemService
|
||||
from spiffworkflow_backend.services.process_model_service import ProcessModelService
|
||||
|
||||
|
||||
class SpecFileService(FileSystemService):
|
||||
|
@ -193,12 +194,17 @@ class SpecFileService(FileSystemService):
|
|||
|
||||
try:
|
||||
if set_primary_file:
|
||||
process_model_info.primary_process_id = (
|
||||
SpecFileService.get_bpmn_process_identifier(bpmn_etree_element)
|
||||
)
|
||||
process_model_info.primary_file_name = file_name
|
||||
process_model_info.is_review = SpecFileService.has_swimlane(
|
||||
bpmn_etree_element
|
||||
attributes_to_update = {
|
||||
"primary_process_id": (
|
||||
SpecFileService.get_bpmn_process_identifier(
|
||||
bpmn_etree_element
|
||||
)
|
||||
),
|
||||
"primary_file_name": file_name,
|
||||
"is_review": SpecFileService.has_swimlane(bpmn_etree_element),
|
||||
}
|
||||
ProcessModelService().update_spec(
|
||||
process_model_info, attributes_to_update
|
||||
)
|
||||
|
||||
SpecFileService.check_for_message_models(
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
"""Base_test."""
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
from typing import Optional
|
||||
|
||||
from flask import current_app
|
||||
from flask.app import Flask
|
||||
from flask.testing import FlaskClient
|
||||
from flask_bpmn.api.api_error import ApiError
|
||||
|
@ -77,14 +79,14 @@ class BaseTest:
|
|||
assert response.status_code == 201
|
||||
return response
|
||||
|
||||
def create_process_model(
|
||||
def create_process_model_with_api(
|
||||
self,
|
||||
client: FlaskClient,
|
||||
process_group_id: Optional[str] = None,
|
||||
process_model_id: Optional[str] = None,
|
||||
process_model_display_name: Optional[str] = None,
|
||||
process_model_description: Optional[str] = None,
|
||||
fault_or_suspend_on_exception: Optional[str] = None,
|
||||
process_model_id: str = "make_cookies",
|
||||
process_model_display_name: str = "Cooooookies",
|
||||
process_model_description: str = "Om nom nom delicious cookies",
|
||||
fault_or_suspend_on_exception: str = NotificationType.suspend.value,
|
||||
exception_notification_addresses: Optional[list] = None,
|
||||
primary_process_id: Optional[str] = None,
|
||||
primary_file_name: Optional[str] = None,
|
||||
|
@ -104,20 +106,8 @@ class BaseTest:
|
|||
else:
|
||||
process_group = ProcessModelService().get_process_group(process_group_id)
|
||||
|
||||
if process_model_id is None:
|
||||
process_model_id = "make_cookies"
|
||||
if process_model_display_name is None:
|
||||
process_model_display_name = "Cooooookies"
|
||||
if process_model_description is None:
|
||||
process_model_description = "Om nom nom delicious cookies"
|
||||
if fault_or_suspend_on_exception is None:
|
||||
fault_or_suspend_on_exception = NotificationType.suspend.value
|
||||
if exception_notification_addresses is None:
|
||||
exception_notification_addresses = []
|
||||
if primary_process_id is None:
|
||||
primary_process_id = ""
|
||||
if primary_file_name is None:
|
||||
primary_file_name = ""
|
||||
model = ProcessModelInfo(
|
||||
id=process_model_id,
|
||||
display_name=process_model_display_name,
|
||||
|
@ -146,25 +136,21 @@ class BaseTest:
|
|||
def create_spec_file(
|
||||
self,
|
||||
client: FlaskClient,
|
||||
process_group_id: str = "",
|
||||
process_model_id: str = "",
|
||||
file_name: str = "",
|
||||
file_data: bytes = b"",
|
||||
process_group_id: str = "random_fact",
|
||||
process_model_id: str = "random_fact",
|
||||
process_model: Optional[ProcessModelInfo] = None,
|
||||
file_name: str = "random_fact.svg",
|
||||
file_data: bytes = b"abcdef",
|
||||
) -> Any:
|
||||
"""Test_create_spec_file."""
|
||||
if process_group_id == "":
|
||||
process_group_id = "random_fact"
|
||||
if process_model_id == "":
|
||||
process_model_id = "random_fact"
|
||||
if file_name == "":
|
||||
file_name = "random_fact.svg"
|
||||
if file_data == b"":
|
||||
file_data = b"abcdef"
|
||||
spec = load_test_spec(process_model_id, process_group_id=process_group_id)
|
||||
if process_model is None:
|
||||
process_model = load_test_spec(
|
||||
process_model_id, process_group_id=process_group_id
|
||||
)
|
||||
data = {"file": (io.BytesIO(file_data), file_name)}
|
||||
user = self.find_or_create_user()
|
||||
response = client.post(
|
||||
f"/v1.0/process-models/{spec.process_group_id}/{spec.id}/files",
|
||||
f"/v1.0/process-models/{process_model.process_group_id}/{process_model.id}/files",
|
||||
data=data,
|
||||
follow_redirects=True,
|
||||
content_type="multipart/form-data",
|
||||
|
@ -177,7 +163,7 @@ class BaseTest:
|
|||
# assert "image/svg+xml" == file["content_type"]
|
||||
|
||||
response = client.get(
|
||||
f"/v1.0/process-models/{spec.process_group_id}/{spec.id}/files/{file_name}",
|
||||
f"/v1.0/process-models/{process_model.process_group_id}/{process_model.id}/files/{file_name}",
|
||||
headers=logged_in_headers(user),
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
@ -233,3 +219,20 @@ class BaseTest:
|
|||
db.session.add(process_instance)
|
||||
db.session.commit()
|
||||
return process_instance
|
||||
|
||||
def get_test_data_file_contents(
|
||||
self, file_name: str, process_model_test_data_dir: str
|
||||
) -> bytes:
|
||||
"""Get_test_data_file_contents."""
|
||||
current_app.root_path,
|
||||
file_full_path = os.path.join(
|
||||
current_app.root_path,
|
||||
"..",
|
||||
"..",
|
||||
"tests",
|
||||
"data",
|
||||
process_model_test_data_dir,
|
||||
file_name,
|
||||
)
|
||||
with open(file_full_path, "rb") as file:
|
||||
return file.read()
|
||||
|
|
|
@ -41,8 +41,6 @@ class ExampleDataLoader:
|
|||
is_master_spec=master_spec,
|
||||
standalone=standalone,
|
||||
library=library,
|
||||
primary_file_name="",
|
||||
primary_process_id="",
|
||||
is_review=False,
|
||||
libraries=[],
|
||||
)
|
||||
|
|
|
@ -39,13 +39,11 @@ class TestProcessApi(BaseTest):
|
|||
self, app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
|
||||
) -> None:
|
||||
"""Test_add_new_process_model."""
|
||||
# group_id = None,
|
||||
model_id = "make_cookies"
|
||||
model_display_name = "Cooooookies"
|
||||
model_description = "Om nom nom delicious cookies"
|
||||
self.create_process_model(
|
||||
model_id = "sample"
|
||||
model_display_name = "Sample"
|
||||
model_description = "The sample"
|
||||
self.create_process_model_with_api(
|
||||
client,
|
||||
process_group_id=None,
|
||||
process_model_id=model_id,
|
||||
process_model_display_name=model_display_name,
|
||||
process_model_description=model_description,
|
||||
|
@ -55,13 +53,25 @@ class TestProcessApi(BaseTest):
|
|||
assert 0 == process_model.display_order
|
||||
assert 1 == len(ProcessModelService().get_process_groups())
|
||||
|
||||
self.create_spec_file(client)
|
||||
bpmn_file_name = "sample.bpmn"
|
||||
bpmn_file_data_bytes = self.get_test_data_file_contents(
|
||||
bpmn_file_name, "sample"
|
||||
)
|
||||
self.create_spec_file(
|
||||
client,
|
||||
file_name=bpmn_file_name,
|
||||
file_data=bpmn_file_data_bytes,
|
||||
process_model=process_model,
|
||||
)
|
||||
process_model = ProcessModelService().get_process_model(model_id)
|
||||
assert process_model.primary_file_name == bpmn_file_name
|
||||
assert process_model.primary_process_id == "sample"
|
||||
|
||||
def test_process_model_delete(
|
||||
self, app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
|
||||
) -> None:
|
||||
"""Test_process_model_delete."""
|
||||
self.create_process_model(client)
|
||||
self.create_process_model_with_api(client)
|
||||
|
||||
# assert we have a model
|
||||
process_model = ProcessModelService().get_process_model("make_cookies")
|
||||
|
@ -118,7 +128,7 @@ class TestProcessApi(BaseTest):
|
|||
self, app: Flask, client: FlaskClient, with_db_and_bpmn_file_cleanup: None
|
||||
) -> None:
|
||||
"""Test_process_model_update."""
|
||||
self.create_process_model(client)
|
||||
self.create_process_model_with_api(client)
|
||||
process_model = ProcessModelService().get_process_model("make_cookies")
|
||||
assert process_model.id == "make_cookies"
|
||||
assert process_model.display_name == "Cooooookies"
|
||||
|
@ -153,7 +163,7 @@ class TestProcessApi(BaseTest):
|
|||
model_id = f"test_model_{i}"
|
||||
model_display_name = f"Test Model {i}"
|
||||
model_description = f"Test Model {i} Description"
|
||||
self.create_process_model(
|
||||
self.create_process_model_with_api(
|
||||
client, group_id, model_id, model_display_name, model_description
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue