From ed07907ee28fc47e7bf49205f6470bb803a14b8b Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 7 Feb 2022 11:00:19 -0500 Subject: [PATCH] at least allow the tests to spin up, even if they all fail. --- crc/models/workflow.py | 4 +- crc/services/workflow_spec_service.py | 35 ++---- tests/base_test.py | 2 +- .../Workflow One/empty_workflow.bpmn | 1 + tests/workflow/test_workflow_sync.py | 111 ------------------ 5 files changed, 16 insertions(+), 137 deletions(-) delete mode 100644 tests/workflow/test_workflow_sync.py diff --git a/crc/models/workflow.py b/crc/models/workflow.py index bf7867f7..dd8fd8b7 100644 --- a/crc/models/workflow.py +++ b/crc/models/workflow.py @@ -12,7 +12,7 @@ class WorkflowSpecCategory(object): self.display_name = display_name self.display_order = display_order self.admin = admin - + self.workflows = [] class WorkflowSpecCategorySchema(ma.Schema): class Meta: @@ -25,7 +25,7 @@ class WorkflowSpecInfo(object): display_order, is_master_spec, standalone, library, primary_file_name, primary_process_id, is_review, libraries): - self.id = id # Sting unqiue id + self.id = id # Sting unique id self.display_name = display_name self.description = description self.category_name = category_name diff --git a/crc/services/workflow_spec_service.py b/crc/services/workflow_spec_service.py index da69579c..30cd7746 100644 --- a/crc/services/workflow_spec_service.py +++ b/crc/services/workflow_spec_service.py @@ -73,13 +73,20 @@ class WorkflowSpecService(FileSystemService): # fixme pass - # get_categories() - # get_category(category_name) - # add_category(body: WorkflowCategory) - # update_category(category, body) - # delete_category(category) + def get_categories(self) -> List[WorkflowSpecCategory]: + pass + def get_category(self, category_id) -> WorkflowSpecCategory: + pass + def add_category(self, category: WorkflowSpecCategory): + pass + + def update_category(self, category: WorkflowSpecCategory): + pass + + def delete_category(self, category: WorkflowSpecCategory): + pass def reorder_workflow_spec_category(self, spec:WorkflowSpecInfo, direction): # Fixme: Resort Workflow categories @@ -211,21 +218,3 @@ class WorkflowSpecService(FileSystemService): return process_elements[0].attrib['id'] - # TODO Methods i would add... - # delete_spec(spec_id) - # get_spec(spec_id) - # update_spec(spec_id, body) - # add_spec(body) - - # Other methods i would add, maybe not here.. - # add_library(body) - # get_libraries() - # get_library(spec_id, library_id) - # delete_library(library_id) - - # get_workflow_categories() - # get_workflow_category(category, body) - # add_workflow_category(body) - # update_workflow_category(category, body) - # delete_workflow_category(category) - diff --git a/tests/base_test.py b/tests/base_test.py index 81b69c85..25104103 100644 --- a/tests/base_test.py +++ b/tests/base_test.py @@ -38,7 +38,6 @@ class BaseTest(unittest.TestCase): """ Great class to inherit from, as it sets up and tears down classes efficiently when we have a database in place. """ - workflow_spec_service = WorkflowSpecService() if not app.config['TESTING']: raise (Exception("INVALID TEST CONFIGURATION. This is almost always in import order issue." @@ -97,6 +96,7 @@ class BaseTest(unittest.TestCase): db.drop_all() def setUp(self): + self.workflow_spec_service = WorkflowSpecService() pass def tearDown(self): diff --git a/tests/data/IMPORT_TEST/Category Number One/Workflow One/empty_workflow.bpmn b/tests/data/IMPORT_TEST/Category Number One/Workflow One/empty_workflow.bpmn index e69de29b..8b137891 100644 --- a/tests/data/IMPORT_TEST/Category Number One/Workflow One/empty_workflow.bpmn +++ b/tests/data/IMPORT_TEST/Category Number One/Workflow One/empty_workflow.bpmn @@ -0,0 +1 @@ + diff --git a/tests/workflow/test_workflow_sync.py b/tests/workflow/test_workflow_sync.py deleted file mode 100644 index 861fba7a..00000000 --- a/tests/workflow/test_workflow_sync.py +++ /dev/null @@ -1,111 +0,0 @@ -import json -import os -import shutil - -from tests.base_test import BaseTest - -from crc.services.workflow_sync import WorkflowSyncService -from crc.models.workflow import WorkflowSpecInfo, WorkflowSpecCategory -from crc.services.file_system_service import FileSystemService -from crc.services.spec_file_service import SpecFileService -from crc import db, app - - -class TestWorkflowSync(BaseTest): - - spec_path = FileSystemService.root_path() - import_spec_path = os.path.join(app.root_path, '..', 'tests', 'data', 'IMPORT_TEST') - - def set_up_file_system(self): - """Some tests rely on a well populated file system and an empty database to start""" - shutil.copytree(self.import_spec_path, self.spec_path) - - def set_up_database(self): - """Some tests rely on a well populated database and an empty file system to start""" - - # Construct Two Categories, with one workflow in first category, two in the second. - # assure that the data in categories.json is correct - # and that there is the correct data structure. - c1 = self.assure_category_name_exists("Category Number One") - c2 = self.assure_category_name_exists("Category Number Two") - self.load_test_spec('random_fact', category_id=c1.id) - self.load_test_spec('hello_world', category_id=c2.id) - self.load_test_spec('decision_table', category_id=c2.id) - self.load_test_spec('empty_workflow', category_id=c1.id, master_spec=True) - self.load_test_spec('email', category_id=c1.id, library=True) - - def test_from_file_system_blank_slate(self): - self.assertEquals(0, len(db.session.query(WorkflowSpecModel).all())) - self.assertEquals(0, len(db.session.query(WorkflowSpecCategoryModel).all())) - self.set_up_file_system() - WorkflowSyncService().from_file_system() - self.assertEquals(2, len(db.session.query(WorkflowSpecCategoryModel).all())) - self.assertEquals(5, len(db.session.query(WorkflowSpecModel).all())) - self.assertEquals(1, len(db.session.query(WorkflowSpecModel).filter(WorkflowSpecModel.category_id == 1).all())) - self.assertEquals(2, len(db.session.query(WorkflowSpecModel).filter(WorkflowSpecModel.category_id == 2).all())) - self.assertEquals(1, len(db.session.query(WorkflowSpecModel).filter(WorkflowSpecModel.is_master_spec).all())) - self.assertEquals(1, len(db.session.query(WorkflowSpecModel).filter(WorkflowSpecModel.library).all())) - # The top level workflow, has a library - tlw = db.session.query(WorkflowSpecModel).filter(WorkflowSpecModel.is_master_spec).first() - self.assertEquals(1, len(tlw.libraries)) - - def test_repeated_imports(self): - self.set_up_file_system() - WorkflowSyncService().from_file_system() - WorkflowSyncService().from_file_system() - WorkflowSyncService().from_file_system() - self.assertEquals(2, len(db.session.query(WorkflowSpecCategoryModel).all())) - self.assertEquals(5, len(db.session.query(WorkflowSpecModel).all())) - - def test_delete_category_and_workflows(self): - self.set_up_file_system() - WorkflowSyncService().from_file_system() - cat_path = SpecFileService().category_path('Category Number One') - shutil.rmtree(cat_path) - WorkflowSyncService().from_file_system() - self.assertEquals(1, len(db.session.query(WorkflowSpecCategoryModel).all())) - self.assertEquals(4, len(db.session.query(WorkflowSpecModel).all())) - self.assertEquals(0, len(db.session.query(WorkflowSpecModel).filter(WorkflowSpecModel.category_id == 1).all())) - - WorkflowSyncService().to_file_system() - json_path = os.path.join(FileSystemService.root_path(), "categories.json") - with open(json_path) as json_file: - data = json.load(json_file) - self.assertEquals(1, len(data['categories']), "When the json file is written back to disk, there is only one category now.") - - def test_to_file_system(self): - """Assure we get the basic paths on the file system that we would expect.""" - self.assertFalse(os.path.exists(self.spec_path)) - self.set_up_database() - self.assertEqual(4, len(os.listdir(self.spec_path)), "Adding workflows should create dir structure") - WorkflowSyncService().to_file_system() - self.assertEqual(5, len(os.listdir(self.spec_path)), "Sync service should create categories.json file") - - def test_to_file_system_correct_categories(self): - """Assure we have two categories in the json file, and that these directories exist, and contain - workflow.json files for each workflow.""" - self.set_up_database() - WorkflowSyncService().to_file_system() - json_path = os.path.join(self.spec_path, 'categories.json') - - with open(json_path) as json_file: - data = json.load(json_file) - self.assertTrue('categories' in data) - self.assertEqual(2, len(data['categories'])) - counter = 0 - for c in data['categories']: - cat_path = os.path.join(self.spec_path, c['display_name']) - self.assertTrue(os.path.exists(cat_path), "The category directories exist.") - self.assertEqual(data['categories'][counter]['display_order'], counter, "Order is correct") - counter += 1 - workflow_dirs = os.listdir(cat_path) - for wd in workflow_dirs: - wf_json_path = os.path.join(cat_path, wd, 'workflow.json') - self.assertTrue(os.path.exists(wf_json_path), "A workflow.json file should exist.") - # Fixme: Assure the master workflow spec, and Libraries are also exported to file system. - - - # Todo: - # * What if category json files, and directories don't match? - # * Test renaming a category - # * Test moving a workflow to a different category