diff --git a/bin/save_all_bpmn.py b/bin/save_all_bpmn.py index 89dbdbbc..eead781b 100644 --- a/bin/save_all_bpmn.py +++ b/bin/save_all_bpmn.py @@ -7,7 +7,7 @@ def main() -> None: """Main.""" app = get_hacked_up_app_for_script() with app.app_context(): - failing_process_models = DataSetupService.save_all() + failing_process_models = DataSetupService.save_all_process_models() for bpmn_errors in failing_process_models: print(bpmn_errors) if len(failing_process_models) > 0: diff --git a/src/spiffworkflow_backend/services/acceptance_test_fixtures.py b/src/spiffworkflow_backend/services/acceptance_test_fixtures.py index 4b8c73c1..144c5ef2 100644 --- a/src/spiffworkflow_backend/services/acceptance_test_fixtures.py +++ b/src/spiffworkflow_backend/services/acceptance_test_fixtures.py @@ -2,6 +2,7 @@ import json import time +from flask import current_app from flask_bpmn.models.db import db from tests.spiffworkflow_backend.helpers.base_test import BaseTest @@ -9,8 +10,9 @@ from spiffworkflow_backend.models.process_instance import ProcessInstanceModel from spiffworkflow_backend.models.process_instance import ProcessInstanceStatus -def load_fixtures() -> list[ProcessInstanceModel]: +def load_acceptance_test_fixtures() -> list[ProcessInstanceModel]: """Load_fixtures.""" + current_app.logger.debug("load_acceptance_test_fixtures() start") test_process_group_id = "acceptance-tests-group-one" test_process_model_id = "acceptance-tests-model-1" user = BaseTest.find_or_create_user() @@ -40,4 +42,5 @@ def load_fixtures() -> list[ProcessInstanceModel]: process_instances.append(process_instance) db.session.commit() + current_app.logger.debug("load_acceptance_test_fixtures() end") return process_instances diff --git a/src/spiffworkflow_backend/services/data_setup_service.py b/src/spiffworkflow_backend/services/data_setup_service.py index 4d92d6b4..0c28af2e 100644 --- a/src/spiffworkflow_backend/services/data_setup_service.py +++ b/src/spiffworkflow_backend/services/data_setup_service.py @@ -1,4 +1,6 @@ """Data_setup_service.""" +from flask import current_app + from spiffworkflow_backend.services.process_model_service import ProcessModelService from spiffworkflow_backend.services.spec_file_service import SpecFileService @@ -6,9 +8,15 @@ from spiffworkflow_backend.services.spec_file_service import SpecFileService class DataSetupService: """DataSetupService.""" - @staticmethod - def save_all() -> list: + @classmethod + def run_setup(cls) -> list: + """Run_setup.""" + return cls.save_all_process_models() + + @classmethod + def save_all_process_models(cls) -> list: """Save_all.""" + current_app.logger.debug("DataSetupService.save_all_process_models() start") failing_process_models = [] process_models = ProcessModelService().get_process_models() for process_model in process_models: @@ -26,7 +34,7 @@ class DataSetupService: ] if process_model.primary_file_name in bad_files: continue - print(f"primary_file_name: {process_model.primary_file_name}") + # print(f"primary_file_name: {process_model.primary_file_name}") try: SpecFileService.update_file( process_model, @@ -79,4 +87,5 @@ class DataSetupService: "primary_file_name not set", ) ) + current_app.logger.debug("DataSetupService.save_all_process_models() end") return failing_process_models diff --git a/tests/spiffworkflow_backend/unit/test_acceptance_test_fixtures.py b/tests/spiffworkflow_backend/unit/test_acceptance_test_fixtures.py index 93fb4206..1d515712 100644 --- a/tests/spiffworkflow_backend/unit/test_acceptance_test_fixtures.py +++ b/tests/spiffworkflow_backend/unit/test_acceptance_test_fixtures.py @@ -1,12 +1,14 @@ """Test_acceptance_test_fixtures.""" from flask.app import Flask -from spiffworkflow_backend.services.acceptance_test_fixtures import load_fixtures +from spiffworkflow_backend.services.acceptance_test_fixtures import ( + load_acceptance_test_fixtures, +) def test_start_dates_are_one_hour_apart(app: Flask) -> None: """Test_start_dates_are_one_hour_apart.""" - process_instances = load_fixtures() + process_instances = load_acceptance_test_fixtures() assert len(process_instances) > 2 assert process_instances[0].start_in_seconds is not None diff --git a/wsgi.py b/wsgi.py index 060a0fd7..839f0c14 100644 --- a/wsgi.py +++ b/wsgi.py @@ -2,7 +2,10 @@ import os from spiffworkflow_backend import create_app -from spiffworkflow_backend.services.acceptance_test_fixtures import load_fixtures +from spiffworkflow_backend.services.acceptance_test_fixtures import ( + load_acceptance_test_fixtures, +) +from spiffworkflow_backend.services.data_setup_service import DataSetupService app = create_app() @@ -10,4 +13,8 @@ app = create_app() # it also loaded when we were running migrations, which resulted in a chicken/egg thing. if os.environ.get("SPIFFWORKFLOW_BACKEND_LOAD_FIXTURE_DATA") == "true": with app.app_context(): - load_fixtures() + load_acceptance_test_fixtures() + +if os.environ.get("SPIFFWORKFLOW_BACKEND_RUN_DATA_SETUP") != "false": + with app.app_context(): + DataSetupService.run_setup()