From 91fa44b2abb92b588258d8d8ed0c9beab850baf7 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Fri, 21 Jan 2022 14:37:11 -0500 Subject: [PATCH 1/4] ** WIP ** Committing so I can work on another ticket. --- crc/services/error_service.py | 5 +- .../data/missing_library/missing_library.bpmn | 75 +++++++++++++++++++ tests/data/missing_library/multiply.bpmn | 42 +++++++++++ .../workflow/test_workflow_missing_library.py | 16 ++++ 4 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 tests/data/missing_library/missing_library.bpmn create mode 100644 tests/data/missing_library/multiply.bpmn create mode 100644 tests/workflow/test_workflow_missing_library.py diff --git a/crc/services/error_service.py b/crc/services/error_service.py index 3810ea5a..94308cf2 100644 --- a/crc/services/error_service.py +++ b/crc/services/error_service.py @@ -22,7 +22,10 @@ known_errors = {'Non-default exclusive outgoing sequence flow without condition 'for the property.'}, 'Error opening excel file .*, with file_model_id:': {'hint': 'It looks like you are trying to use an older xls file. ' - 'Try uploading a newer xlsx file.'}} + 'Try uploading a newer xlsx file.'}, + 'Failed to parse the Workflow Specification. Error is \'The process \'(.+)\' was not found. Did you mean one of the following: .*': + {'hint': 'The workflow spec could not be parsed. If you are loading a library, check whether the name is correct.'} + } class ValidationErrorService(object): diff --git a/tests/data/missing_library/missing_library.bpmn b/tests/data/missing_library/missing_library.bpmn new file mode 100644 index 00000000..63bd3326 --- /dev/null +++ b/tests/data/missing_library/missing_library.bpmn @@ -0,0 +1,75 @@ + + + + + Flow_1w8il3k + + + + + Flow_0zy8gri + Flow_0mtrjqf + + + ## Multiple +{{ multiple }} + + Flow_0mtrjqf + Flow_0zy8247 + + + + Flow_0zy8247 + + + + + + + + + + + + + + Flow_1w8il3k + Flow_0zy8gri + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/missing_library/multiply.bpmn b/tests/data/missing_library/multiply.bpmn new file mode 100644 index 00000000..0bb8e1f2 --- /dev/null +++ b/tests/data/missing_library/multiply.bpmn @@ -0,0 +1,42 @@ + + + + + Flow_1ncal2l + + + + Flow_1q7r744 + + + + Flow_1ncal2l + Flow_1q7r744 + multiple = num_1 * num_2 + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/workflow/test_workflow_missing_library.py b/tests/workflow/test_workflow_missing_library.py new file mode 100644 index 00000000..c4dab5fb --- /dev/null +++ b/tests/workflow/test_workflow_missing_library.py @@ -0,0 +1,16 @@ +from tests.base_test import BaseTest +from example_data import ExampleDataLoader + + +class TestDuplicateWorkflowSpecFile(BaseTest): + + def test_duplicate_workflow_spec_file(self): + spec1 = ExampleDataLoader().create_spec('missing_library', 'Missing Library', category_id=0, library=False, + from_tests=True) + workflow = self.create_workflow('missing_library') + with self.assertRaises(AssertionError) as ae: + workflow_api = self.get_workflow_api(workflow) + # task = workflow_api.next_task + # self.complete_form(workflow, task, {'num_1': 4, 'num_2': 5}) + + print('test_duplicate_workflow_spec_file') \ No newline at end of file From 73e250a54cf88bf28006cf73f78123c5b8b7baee Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Mon, 24 Jan 2022 10:35:11 -0500 Subject: [PATCH 2/4] Test for missing library hint in the error message --- tests/data/missing_library/multiply.bpmn | 42 ------------------- .../workflow/test_workflow_missing_library.py | 24 ++++++----- 2 files changed, 13 insertions(+), 53 deletions(-) delete mode 100644 tests/data/missing_library/multiply.bpmn diff --git a/tests/data/missing_library/multiply.bpmn b/tests/data/missing_library/multiply.bpmn deleted file mode 100644 index 0bb8e1f2..00000000 --- a/tests/data/missing_library/multiply.bpmn +++ /dev/null @@ -1,42 +0,0 @@ - - - - - Flow_1ncal2l - - - - Flow_1q7r744 - - - - Flow_1ncal2l - Flow_1q7r744 - multiple = num_1 * num_2 - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/workflow/test_workflow_missing_library.py b/tests/workflow/test_workflow_missing_library.py index c4dab5fb..1bccc6da 100644 --- a/tests/workflow/test_workflow_missing_library.py +++ b/tests/workflow/test_workflow_missing_library.py @@ -1,16 +1,18 @@ from tests.base_test import BaseTest -from example_data import ExampleDataLoader + +import json -class TestDuplicateWorkflowSpecFile(BaseTest): +class TestMissingLibrary(BaseTest): - def test_duplicate_workflow_spec_file(self): - spec1 = ExampleDataLoader().create_spec('missing_library', 'Missing Library', category_id=0, library=False, - from_tests=True) + def test_missing_library(self): + """We call a library that does not exist, and + test to see if our error service hint is in the error message.""" workflow = self.create_workflow('missing_library') - with self.assertRaises(AssertionError) as ae: - workflow_api = self.get_workflow_api(workflow) - # task = workflow_api.next_task - # self.complete_form(workflow, task, {'num_1': 4, 'num_2': 5}) - - print('test_duplicate_workflow_spec_file') \ No newline at end of file + url = f'/v1.0/workflow/{workflow.id}?do_engine_steps=True' + rv = self.app.get(url, + headers=self.logged_in_headers(), + content_type="application/json") + json_data = json.loads(rv.get_data(as_text=True)) + self.assertEqual('workflow_validation_error', json_data['code']) + self.assertIn("'Process_Multiply' was not found", json_data['message']) From 2ecf6cdf86b7895ba210eb321a28af1ba1cf4afb Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Mon, 24 Jan 2022 11:03:49 -0500 Subject: [PATCH 3/4] Validation is the right way to test this. --- tests/workflow/test_workflow_missing_library.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/workflow/test_workflow_missing_library.py b/tests/workflow/test_workflow_missing_library.py index 1bccc6da..76030b53 100644 --- a/tests/workflow/test_workflow_missing_library.py +++ b/tests/workflow/test_workflow_missing_library.py @@ -9,10 +9,8 @@ class TestMissingLibrary(BaseTest): """We call a library that does not exist, and test to see if our error service hint is in the error message.""" workflow = self.create_workflow('missing_library') - url = f'/v1.0/workflow/{workflow.id}?do_engine_steps=True' - rv = self.app.get(url, - headers=self.logged_in_headers(), - content_type="application/json") + rv = self.app.get('/v1.0/workflow-specification/%s/validate' % workflow.workflow_spec_id, headers=self.logged_in_headers()) json_data = json.loads(rv.get_data(as_text=True)) - self.assertEqual('workflow_validation_error', json_data['code']) - self.assertIn("'Process_Multiply' was not found", json_data['message']) + self.assertEqual('workflow_validation_error', json_data[0]['code']) + self.assertIn("'Process_Multiply' was not found", json_data[0]['message']) + self.assertEqual('The workflow spec could not be parsed. If you are loading a library, check whether the name is correct.', json_data[0]['hint']) From 6f31a26772e53da8397ea1d526800a024d1d1ede Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Mon, 24 Jan 2022 11:06:01 -0500 Subject: [PATCH 4/4] Better description --- tests/workflow/test_workflow_missing_library.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/workflow/test_workflow_missing_library.py b/tests/workflow/test_workflow_missing_library.py index 76030b53..237e7f14 100644 --- a/tests/workflow/test_workflow_missing_library.py +++ b/tests/workflow/test_workflow_missing_library.py @@ -6,8 +6,8 @@ import json class TestMissingLibrary(BaseTest): def test_missing_library(self): - """We call a library that does not exist, and - test to see if our error service hint is in the error message.""" + """This workflow calls a library that does not exist, + we validate the workflow, and assert that our error service hint is in the error message.""" workflow = self.create_workflow('missing_library') rv = self.app.get('/v1.0/workflow-specification/%s/validate' % workflow.workflow_spec_id, headers=self.logged_in_headers()) json_data = json.loads(rv.get_data(as_text=True))