two passing tests around the WorkflowSpecService

This commit is contained in:
Dan 2022-02-07 13:34:13 -05:00
parent b5ff8774e1
commit d64853fa5b
4 changed files with 19 additions and 11 deletions

View File

@ -72,7 +72,7 @@ class WorkflowSpecService(FileSystemService):
return workflows
def get_libraries(self) -> List[WorkflowSpecInfo]:
spec_list = list(self.libraries.values())
spec_list = self.libraries.workflows
spec_list.sort(key=lambda w: w.display_order)
return spec_list
@ -107,7 +107,7 @@ class WorkflowSpecService(FileSystemService):
self.scan_file_system()
def delete_category(self, category_id: str):
if category_id in self.specs:
if category_id in self.categories:
path = self.category_path(category_id)
shutil.rmtree(path)
self.scan_file_system()
@ -124,14 +124,17 @@ class WorkflowSpecService(FileSystemService):
self.specs = {}
self.master_spec = None
self.libraries = {}
self.standalone = {}
if not os.path.exists(FileSystemService.root_path()):
return # Nothing to scan yet. There are no files.
directory_items = os.scandir(FileSystemService.root_path())
for item in directory_items:
if item.is_dir():
if item.name == self.LIBRARY_SPECS:
self.scan_category(item, is_library=True)
if item.name == self.STAND_ALONE_SPECS:
elif item.name == self.STAND_ALONE_SPECS:
self.scan_category(item, is_standalone=True)
elif item.name == self.MASTER_SPECIFICATION:
self.scan_spec(item, is_master=True)
@ -155,9 +158,10 @@ class WorkflowSpecService(FileSystemService):
self.standalone = cat
else:
self.categories[cat.id] = cat
workflow_dirs = os.scandir(FileSystemService.root_path())
workflow_dirs = os.scandir(dir_item.path)
for item in workflow_dirs:
self.scan_spec(item, category=cat)
if item.is_dir():
self.scan_spec(item, category=cat)
return cat
@staticmethod
@ -187,9 +191,10 @@ class WorkflowSpecService(FileSystemService):
if is_master:
self.master_spec = spec
elif category:
self.specs[spec.id] = spec
spec.category = category
category.workflows.append(spec)
self.specs[spec.id] = spec
def set_primary_bpmn(self, workflow_spec: WorkflowSpecInfo, file_name: str, binary_data=None):
# If this is a BPMN, extract the process id, and determine if it is contains swim lanes.

View File

@ -1,5 +1,5 @@
{
"id": 1,
"id": "category_number_one",
"display_name": "Category Number One",
"admin": false,
"display_order": 0

View File

@ -1,5 +1,5 @@
{
"id": 2,
"id": "category_number_two",
"admin": false,
"display_order": 1,
"display_name": "Category Number Two"

View File

@ -36,23 +36,26 @@ class TestWorkflowSync(BaseTest):
self.load_test_spec('email', category_id=c1.id, library=True)
def test_from_file_system_blank_slate(self):
self.service.scan_file_system()
self.assertEquals(0, len(self.service.get_categories()))
self.assertEquals(0, len(self.service.get_specs()))
self.copy_files_to_file_system()
self.service.scan_file_system()
self.assertEquals(2, len(self.service.get_categories()))
self.assertEquals(5, len(self.service.get_specs()))
self.assertEquals(1, len(self.service.get_category('Category Number One').workflows))
self.assertEquals(2, len(self.service.get_category('Category Number Two').workflows))
self.assertEquals(1, len(self.service.get_category('category_number_one').workflows))
self.assertEquals(2, len(self.service.get_category('category_number_two').workflows))
self.assertIsNotNone(self.service.master_spec)
self.assertEquals(1, len(self.service.get_libraries()))
self.assertEquals(1, len(self.service.master_spec.libraries))
def test_delete_category_and_workflows(self):
self.copy_files_to_file_system()
self.service.scan_file_system()
cat_path = SpecFileService().category_path('Category Number One')
shutil.rmtree(cat_path) # Remove the path, as if from a git pull and the path was removed.
self.assertEquals(3, len(self.service.get_categories()))
self.service.scan_file_system()
self.assertEquals(1, len(self.service.get_categories()))
self.assertEquals(4, len(self.service.get_specs()))