*** WIP ***

Incremental commit. Mainly cleaning up failing tests.
This commit is contained in:
mike cullerton 2022-01-12 13:16:09 -05:00
parent 4b2319b0da
commit b6b9482a64
7 changed files with 122 additions and 337 deletions

View File

@ -28,29 +28,33 @@ def to_file_api(file_model):
DocumentService.get_dictionary())
def get_files(workflow_spec_id=None, workflow_id=None, form_field_key=None,study_id=None):
if all(v is None for v in [workflow_spec_id, workflow_id, form_field_key,study_id]):
def get_files(workflow_id=None, form_field_key=None,study_id=None):
if workflow_id is None:
raise ApiError('missing_parameter',
'Please specify either a workflow_spec_id or a '
'workflow_id with an optional form_field_key')
'Please specify a workflow_id with an optional form_field_key')
if study_id is not None:
file_models = FileService.get_files_for_study(study_id=study_id, irb_doc_code=form_field_key)
else:
file_models = FileService.get_files(workflow_spec_id=workflow_spec_id,
workflow_id=workflow_id,
irb_doc_code=form_field_key)
file_models = FileService.get_files(workflow_id=workflow_id,
irb_doc_code=form_field_key)
files = (to_file_api(model) for model in file_models)
return FileSchema(many=True).dump(files)
def get_spec_files(workflow_spec_id):
pass
def get_spec_files(workflow_spec_id, include_libraries=False):
if workflow_spec_id is None:
raise ApiError(code='missing_spec_id',
message='Please specify the workflow_spec_id.')
file_models = SpecFileService.get_spec_files(workflow_spec_id=workflow_spec_id,
include_libraries=include_libraries)
files = [to_file_api(model) for model in file_models]
return FileSchema(many=True).dump(files)
def get_reference_files():
results = FileService.get_files(is_reference=True)
results = SpecFileService.get_reference_files()
files = (to_file_api(model) for model in results)
return FileSchema(many=True).dump(files)

View File

@ -163,35 +163,20 @@ class FileService(object):
return query.all()
@staticmethod
def get_files(workflow_spec_id=None, workflow_id=None,
name=None, is_reference=False, irb_doc_code=None, include_libraries=False):
query = session.query(FileModel).filter_by(is_reference=is_reference)
if workflow_spec_id:
if include_libraries:
libraries = session.query(WorkflowLibraryModel).filter(
WorkflowLibraryModel.workflow_spec_id==workflow_spec_id).all()
library_workflow_specs = [x.library_spec_id for x in libraries]
library_workflow_specs.append(workflow_spec_id)
query = query.filter(FileModel.workflow_spec_id.in_(library_workflow_specs))
else:
query = query.filter(FileModel.workflow_spec_id == workflow_spec_id)
elif workflow_id:
query = query.filter_by(workflow_id=workflow_id)
def get_files(workflow_id=None, name=None, irb_doc_code=None):
if workflow_id is not None:
query = session.query(FileModel).filter_by(workflow_id=workflow_id)
if irb_doc_code:
query = query.filter_by(irb_doc_code=irb_doc_code)
elif is_reference:
query = query.filter_by(is_reference=True)
if name:
query = query.filter_by(name=name)
if name:
query = query.filter_by(name=name)
query = query.filter(FileModel.archived == False)
query = query.filter(FileModel.archived == False)
query = query.order_by(FileModel.id)
query = query.order_by(FileModel.id)
results = query.all()
return results
results = query.all()
return results
@staticmethod
@ -216,42 +201,6 @@ class FileService(object):
query = query.order_by(desc(FileDataModel.date_created))
return query.first()
@staticmethod
def get_workflow_file_data(workflow, file_name):
"""This method should be deleted, find where it is used, and remove this method.
Given a SPIFF Workflow Model, tracks down a file with the given name in the database and returns its data"""
workflow_spec_model = FileService.find_spec_model_in_db(workflow)
if workflow_spec_model is None:
raise ApiError(code="unknown_workflow",
message="Something is wrong. I can't find the workflow you are using.")
file_data_model = session.query(FileDataModel) \
.join(FileModel) \
.filter(FileModel.name == file_name) \
.filter(FileModel.workflow_spec_id == workflow_spec_model.id).first()
if file_data_model is None:
raise ApiError(code="file_missing",
message="Can not find a file called '%s' within workflow specification '%s'"
% (file_name, workflow_spec_model.id))
return file_data_model
@staticmethod
def find_spec_model_in_db(workflow):
""" Search for the workflow """
# When the workflow spec model is created, we record the primary process id,
# then we can look it up. As there is the potential for sub-workflows, we
# may need to travel up to locate the primary process.
spec = workflow.spec
workflow_model = session.query(WorkflowSpecModel).join(FileModel). \
filter(FileModel.primary_process_id == spec.name).first()
if workflow_model is None and workflow != workflow.outer_workflow:
return FileService.find_spec_model_in_db(workflow.outer_workflow)
return workflow_model
@staticmethod
def delete_file(file_id):
try:
@ -439,50 +388,3 @@ class FileService(object):
dmn_file = prefix + etree.tostring(root)
return dmn_file
# TODO: Get rid of this. We don't have versions any more
# @staticmethod
# def cleanup_file_data(copies_to_keep=1):
# if isinstance(copies_to_keep, int) and copies_to_keep > 0:
#
# deleted_models = []
# saved_models = []
# current_models = []
#
# session.flush()
#
# workflow_spec_models = session.query(WorkflowSpecModel).all()
#
# for wf_spec_model in workflow_spec_models:
# file_models = session.query(FileModel)\
# .filter(FileModel.workflow_spec_id == wf_spec_model.id)\
# .all()
#
# for file_model in file_models:
# file_data_models = session.query(FileDataModel)\
# .filter(FileDataModel.file_model_id == file_model.id)\
# .order_by(desc(FileDataModel.date_created))\
# .all()
# current_models.append(file_data_models[:copies_to_keep])
# for fd_model in file_data_models[copies_to_keep:]:
# dependencies = session.query(WorkflowSpecDependencyFile)\
# .filter(WorkflowSpecDependencyFile.file_data_id == fd_model.id)\
# .all()
# if len(dependencies) > 0:
# saved_models.append(fd_model)
# continue
# lookups = session.query(LookupFileModel)\
# .filter(LookupFileModel.file_data_model_id == fd_model.id)\
# .all()
# if len(lookups) > 0:
# saved_models.append(fd_model)
# continue
# deleted_models.append(fd_model)
# session.delete(fd_model)
#
# session.commit()
# return current_models, saved_models, deleted_models
#
# else:
# raise ApiError(code='bad_keep',
# message='You must keep at least 1 version')

View File

@ -6,7 +6,7 @@ import os
from crc import app, session
from crc.api.common import ApiError
from crc.models.file import FileModel, FileModelSchema, FileDataModel
from crc.models.workflow import WorkflowSpecModel, WorkflowSpecCategoryModel
from crc.models.workflow import WorkflowSpecModel, WorkflowSpecCategoryModel, WorkflowLibraryModel
from crc.services.file_service import FileService, FileType
from SpiffWorkflow.bpmn.parser.ValidationException import ValidationException
@ -47,7 +47,8 @@ class SpecFileService(object):
@staticmethod
def add_workflow_spec_file(workflow_spec: WorkflowSpecModel,
name, content_type, binary_data, primary=False, is_status=False):
"""Create a new file and associate it with a workflow spec."""
"""Create a new file and associate it with a workflow spec.
3 steps; create file model, write file data to filesystem, write file info to file system"""
file_model = session.query(FileModel)\
.filter(FileModel.workflow_spec_id == workflow_spec.id)\
.filter(FileModel.name == name).first()
@ -266,6 +267,57 @@ class SpecFileService(object):
return process_elements[0].attrib['id']
@staticmethod
def get_spec_files(workflow_spec_id, include_libraries=False):
if workflow_spec_id:
if include_libraries:
libraries = session.query(WorkflowLibraryModel).filter(
WorkflowLibraryModel.workflow_spec_id==workflow_spec_id).all()
library_workflow_specs = [x.library_spec_id for x in libraries]
library_workflow_specs.append(workflow_spec_id)
query = session.query(FileModel).filter(FileModel.workflow_spec_id.in_(library_workflow_specs))
else:
query = session.query(FileModel).filter(FileModel.workflow_spec_id == workflow_spec_id)
query = query.filter(FileModel.archived == False)
query = query.order_by(FileModel.id)
results = query.all()
return results
@staticmethod
def get_workflow_file_data(workflow, file_name):
"""This method should be deleted, find where it is used, and remove this method.
Given a SPIFF Workflow Model, tracks down a file with the given name in the database and returns its data"""
workflow_spec_model = SpecFileService.find_spec_model_in_db(workflow)
if workflow_spec_model is None:
raise ApiError(code="unknown_workflow",
message="Something is wrong. I can't find the workflow you are using.")
file_id = session.query(FileModel.id).filter(FileModel.workflow_spec_id==workflow_spec_model.id).filter(FileModel.name==file_name).scalar()
file_data_model = SpecFileService().get_spec_file_data(file_id)
if file_data_model is None:
raise ApiError(code="file_missing",
message="Can not find a file called '%s' within workflow specification '%s'"
% (file_name, workflow_spec_model.id))
return file_data_model
@staticmethod
def find_spec_model_in_db(workflow):
""" Search for the workflow """
# When the workflow spec model is created, we record the primary process id,
# then we can look it up. As there is the potential for sub-workflows, we
# may need to travel up to locate the primary process.
spec = workflow.spec
workflow_model = session.query(WorkflowSpecModel).join(FileModel). \
filter(FileModel.primary_process_id == spec.name).first()
if workflow_model is None and workflow != workflow.outer_workflow:
return SpecFileService.find_spec_model_in_db(workflow.outer_workflow)
return workflow_model
#
# Reference File Methods
#
@ -338,3 +390,10 @@ class SpecFileService(object):
def write_reference_file_info_to_system(self, file_path, file_model):
self.write_file_info_to_system(file_path, file_model)
@staticmethod
def get_reference_files():
reference_files = session.query(FileModel).\
filter_by(is_reference=True).\
filter(FileModel.archived == False).\
all()
return reference_files

View File

@ -35,6 +35,7 @@ from crc.services.document_service import DocumentService
from crc.services.file_service import FileService
from crc.services.jinja_service import JinjaService
from crc.services.lookup_service import LookupService
from crc.services.spec_file_service import SpecFileService
from crc.services.study_service import StudyService
from crc.services.user_service import UserService
from crc.services.workflow_processor import WorkflowProcessor
@ -762,7 +763,7 @@ class WorkflowService(object):
try:
doc_file_name = spiff_task.task_spec.name + ".md"
data_model = FileService.get_workflow_file_data(spiff_task.workflow, doc_file_name)
data_model = SpecFileService.get_workflow_file_data(spiff_task.workflow, doc_file_name)
raw_doc = data_model.data.decode("utf-8")
except ApiError:
raw_doc = documentation

View File

@ -1,150 +0,0 @@
from tests.base_test import BaseTest
from crc import session
from crc.models.file import FileModel, FileDataModel, LookupFileModel
from crc.models.workflow import WorkflowSpecModel, WorkflowSpecDependencyFile
from crc.services.file_service import FileService
from sqlalchemy import desc
import io
import json
class TestFileDataCleanup(BaseTest):
xml_str_one = b"""<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="Definitions_0e68fp5" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.0.0-dev">
<bpmn:process id="Process_054hyyv" isExecutable="true">
<bpmn:startEvent id="StartEvent_1" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_054hyyv">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="159" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>"""
xml_str_two = b"""<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0e68fp5" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
<bpmn:process id="Process_054hyyv" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_1v0s5ht</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="Activity_08xcoa5" name="Say Hello">
<bpmn:documentation># Hello</bpmn:documentation>
<bpmn:incoming>Flow_1v0s5ht</bpmn:incoming>
<bpmn:outgoing>Flow_12k5ua1</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_1v0s5ht" sourceRef="StartEvent_1" targetRef="Activity_08xcoa5" />
<bpmn:endEvent id="Event_10ufcgd">
<bpmn:incoming>Flow_12k5ua1</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_12k5ua1" sourceRef="Activity_08xcoa5" targetRef="Event_10ufcgd" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_054hyyv">
<bpmndi:BPMNEdge id="Flow_1v0s5ht_di" bpmnElement="Flow_1v0s5ht">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_12k5ua1_di" bpmnElement="Flow_12k5ua1">
<di:waypoint x="370" y="117" />
<di:waypoint x="432" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_08xcoa5_di" bpmnElement="Activity_08xcoa5">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_10ufcgd_di" bpmnElement="Event_10ufcgd">
<dc:Bounds x="432" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
"""
# TODO: Get rid of this? We don't have versions anymore
def test_file_data_cleanup(self):
"""Update a file twice. Make sure we clean up the correct files"""
self.load_example_data()
workflow = self.create_workflow('empty_workflow')
file_data_model_count = session.query(FileDataModel).count()
# Use for comparison after cleanup
replaced_models = []
# Get `empty_workflow` workflow spec
workflow_spec_model = session.query(WorkflowSpecModel)\
.filter(WorkflowSpecModel.id == 'empty_workflow')\
.first()
# Get file model for empty_workflow spec
file_model = session.query(FileModel)\
.filter(FileModel.workflow_spec_id == workflow_spec_model.id)\
.first()
# Grab the file data model for empty_workflow file_model
original_file_data_model = session.query(FileDataModel)\
.filter(FileDataModel.file_model_id == file_model.id)\
.order_by(desc(FileDataModel.date_created))\
.first()
# Add file to dependencies
# It should not get deleted
wf_spec_depend_model = WorkflowSpecDependencyFile(file_data_id=original_file_data_model.id,
workflow_id=workflow.id)
session.add(wf_spec_depend_model)
session.commit()
# Update first time
replaced_models.append(original_file_data_model)
data = {'file': (io.BytesIO(self.xml_str_one), file_model.name)}
rv = self.app.put('/v1.0/file/%i/data' % file_model.id, data=data, follow_redirects=True,
content_type='multipart/form-data', headers=self.logged_in_headers())
self.assert_success(rv)
file_json_first = json.loads(rv.get_data(as_text=True))
# Update second time
# replaced_models.append(old_file_data_model)
data = {'file': (io.BytesIO(self.xml_str_two), file_model.name)}
rv = self.app.put('/v1.0/file/%i/data' % file_model.id, data=data, follow_redirects=True,
content_type='multipart/form-data', headers=self.logged_in_headers())
self.assert_success(rv)
file_json_second = json.loads(rv.get_data(as_text=True))
# Add lookup file
data = {'file': (io.BytesIO(b'asdf'), 'lookup_1.xlsx')}
rv = self.app.post('/v1.0/file?workflow_spec_id=%s' % workflow_spec_model.id, data=data, follow_redirects=True,
content_type='multipart/form-data', headers=self.logged_in_headers())
self.assert_success(rv)
file_json = json.loads(rv.get_data(as_text=True))
lookup_file_id = file_json['id']
lookup_data_model = session.query(FileDataModel).filter(FileDataModel.file_model_id == lookup_file_id).first()
lookup_model = LookupFileModel(file_data_model_id=lookup_data_model.id,
workflow_spec_id=workflow_spec_model.id)
session.add(lookup_model)
session.commit()
# Update lookup file
data = {'file': (io.BytesIO(b'1234'), 'lookup_1.xlsx')}
rv = self.app.put('/v1.0/file/%i/data' % lookup_file_id, data=data, follow_redirects=True,
content_type='multipart/form-data', headers=self.logged_in_headers())
self.assert_success(rv)
# Run the cleanup files process
current_models, saved_models, deleted_models = FileService.cleanup_file_data()
# assert correct versions are removed
new_count = session.query(FileDataModel).count()
self.assertEqual(8, new_count)
self.assertEqual(4, len(current_models))
self.assertEqual(2, len(saved_models))
self.assertEqual(1, len(deleted_models))
print('test_file_data_cleanup')

View File

@ -23,7 +23,7 @@ class TestFilesApi(BaseTest):
self.load_example_data(use_crc_data=True)
spec_id = 'core_info'
spec = session.query(WorkflowSpecModel).filter_by(id=spec_id).first()
rv = self.app.get('/v1.0/file?workflow_spec_id=%s' % spec_id,
rv = self.app.get('/v1.0/spec_file?workflow_spec_id=%s' % spec_id,
follow_redirects=True,
content_type="application/json", headers=self.logged_in_headers())
self.assert_success(rv)
@ -36,11 +36,10 @@ class TestFilesApi(BaseTest):
def test_list_multiple_files_for_workflow_spec(self):
self.load_example_data()
spec = self.load_test_spec("random_fact")
svgFile = FileModel(name="test.svg", type=FileType.svg,
primary=False, workflow_spec_id=spec.id)
session.add(svgFile)
session.flush()
rv = self.app.get('/v1.0/file?workflow_spec_id=%s' % spec.id,
data = {'file': (io.BytesIO(b"abcdef"), 'test.svg')}
self.app.post('/v1.0/spec_file?workflow_spec_id=%s' % spec.id, data=data, follow_redirects=True,
content_type='multipart/form-data', headers=self.logged_in_headers())
rv = self.app.get('/v1.0/spec_file?workflow_spec_id=%s' % spec.id,
follow_redirects=True,
content_type="application/json", headers=self.logged_in_headers())
self.assert_success(rv)
@ -224,54 +223,32 @@ class TestFilesApi(BaseTest):
spec = session.query(WorkflowSpecModel).first()
data = {}
data['file'] = io.BytesIO(self.minimal_bpmn("abcdef")), 'my_new_file.bpmn'
rv = self.app.post('/v1.0/spec_file?workflow_spec_id=%s' % spec.id, data=data, follow_redirects=True,
content_type='multipart/form-data', headers=self.logged_in_headers())
file_json = json.loads(rv.get_data(as_text=True))
self.assertEqual(80, file_json['size'])
rv_1 = self.app.post('/v1.0/spec_file?workflow_spec_id=%s' % spec.id, data=data, follow_redirects=True,
content_type='multipart/form-data', headers=self.logged_in_headers())
file_json_1 = json.loads(rv_1.get_data(as_text=True))
self.assertEqual(80, file_json_1['size'])
data['file'] = io.BytesIO(self.minimal_bpmn("efghijk")), 'my_new_file.bpmn'
rv = self.app.put('/v1.0/spec_file/%i/data' % file_json['id'], data=data, follow_redirects=True,
content_type='multipart/form-data', headers=self.logged_in_headers())
self.assert_success(rv)
self.assertIsNotNone(rv.get_data())
file_json = json.loads(rv.get_data(as_text=True))
# self.assertEqual(2, file_json['latest_version'])
self.assertEqual(FileType.bpmn.value, file_json['type'])
self.assertEqual("application/octet-stream", file_json['content_type'])
self.assertEqual(spec.id, file_json['workflow_spec_id'])
rv_2 = self.app.put('/v1.0/spec_file/%i/data' % file_json_1['id'], data=data, follow_redirects=True,
content_type='multipart/form-data', headers=self.logged_in_headers())
self.assert_success(rv_2)
self.assertIsNotNone(rv_2.get_data())
file_json_2 = json.loads(rv_2.get_data(as_text=True))
self.assertEqual(FileType.bpmn.value, file_json_2['type'])
self.assertEqual("application/octet-stream", file_json_2['content_type'])
self.assertEqual(spec.id, file_json_2['workflow_spec_id'])
# Assure it is updated in the database and properly persisted.
file_model = session.query(FileModel).filter(FileModel.id == file_json['id']).first()
file_model = session.query(FileModel).filter(FileModel.id == file_json_2['id']).first()
file_data = SpecFileService().get_spec_file_data(file_model.id)
# TODO: Not sure what to do here. We don't have versions any more.
# self.assertEqual(2, file_data.version)
self.assertEqual(81, len(file_data.data))
rv = self.app.get('/v1.0/spec_file/%i/data' % file_json['id'], headers=self.logged_in_headers())
self.assert_success(rv)
data = rv.get_data()
rv_3 = self.app.get('/v1.0/spec_file/%i/data' % file_json_2['id'], headers=self.logged_in_headers())
self.assert_success(rv_3)
data = rv_3.get_data()
self.assertIsNotNone(data)
self.assertEqual(self.minimal_bpmn("efghijk"), data)
# TODO: Not sure what to test. We don't have versions any more.
def test_update_with_same_exact_data_does_not_increment_version(self):
self.load_example_data()
spec = session.query(WorkflowSpecModel).first()
data = {}
data['file'] = io.BytesIO(self.minimal_bpmn("abcdef")), 'my_new_file.bpmn'
rv = self.app.post('/v1.0/spec_file?workflow_spec_id=%s' % spec.id, data=data, follow_redirects=True,
content_type='multipart/form-data', headers=self.logged_in_headers())
self.assertIsNotNone(rv.get_data())
json_data = json.loads(rv.get_data(as_text=True))
# TODO: Not sure what to test. We don't have versions any more.
# self.assertEqual(1, json_data['latest_version'])
data['file'] = io.BytesIO(self.minimal_bpmn("abcdef")), 'my_new_file.bpmn'
rv = self.app.put('/v1.0/spec_file/%i/data' % json_data['id'], data=data, follow_redirects=True,
content_type='multipart/form-data', headers=self.logged_in_headers())
self.assertIsNotNone(rv.get_data())
json_data = json.loads(rv.get_data(as_text=True))
# TODO: Not sure what to test. We don't have versions any more.
# self.assertEqual(1, json_data['latest_version'])
def test_get_file(self):
self.load_example_data()
spec = session.query(WorkflowSpecModel).first()

View File

@ -182,34 +182,29 @@ class TestTasksApi(BaseTest):
self.assertIsNotNone(workflow_api.next_task.documentation)
self.assertTrue("norris" in workflow_api.next_task.documentation)
# TODO: Decide what to do about this test because we don't have versions any more
def test_load_workflow_from_outdated_spec(self):
# Start the basic two_forms workflow and complete a task.
workflow = self.create_workflow('two_forms')
workflow_api = self.get_workflow_api(workflow)
self.complete_form(workflow, workflow_api.next_task, {"color": "blue"})
# self.assertTrue(workflow_api.is_latest_spec)
workflow_api_1 = self.get_workflow_api(workflow)
self.complete_form(workflow, workflow_api_1.next_task, {"color": "blue"})
# Modify the specification, with a major change that alters the flow and can't be deserialized
# effectively, if it uses the latest spec files.
file_path = os.path.join(app.root_path, '..', 'tests', 'data', 'two_forms', 'modified', 'two_forms_struc_mod.bpmn')
self.replace_file("two_forms.bpmn", file_path)
workflow_api = self.get_workflow_api(workflow)
# TODO: Decide what to do about this test because we don't have versions any more
# self.assertTrue(workflow_api.spec_version.startswith("v1 "))
# self.assertFalse(workflow_api.is_latest_spec)
# This should use the original workflow spec, and just move to the next task
workflow_api_2 = self.get_workflow_api(workflow)
self.assertEqual('StepTwo', workflow_api_2.next_task.name)
workflow_api = self.restart_workflow_api(workflow_api, clear_data=True)
# TODO: Decide what to do about this test because we don't have versions any more
# self.assertTrue(workflow_api.spec_version.startswith("v2 "))
# self.assertTrue(workflow_api.is_latest_spec)
workflow_api_3 = self.restart_workflow_api(workflow_api_2, clear_data=True)
# This should restart the workflow and we should be back on StepOne
self.assertEqual('StepOne', workflow_api_3.next_task.name)
# Assure this hard_reset sticks (added this after a bug was found)
workflow_api = self.get_workflow_api(workflow)
# TODO: Decide what to do about this test because we don't have versions any more
# self.assertTrue(workflow_api.spec_version.startswith("v2 "))
# self.assertTrue(workflow_api.is_latest_spec)
# Again, we should be on StepOne
workflow_api_4 = self.get_workflow_api(workflow)
self.assertEqual('StepOne', workflow_api_4.next_task.name)
def test_reset_workflow_from_broken_spec(self):
# Start the basic two_forms workflow and complete a task.
@ -234,18 +229,15 @@ class TestTasksApi(BaseTest):
def test_manual_task_with_external_documentation(self):
workflow = self.create_workflow('manual_task_with_external_documentation')
# get the first form in the two form workflow.
# Complete the form in the workflow.
task = self.get_workflow_api(workflow).next_task
workflow_api = self.complete_form(workflow, task, {"name": "Dan"})
workflow = self.get_workflow_api(workflow)
self.assertEqual('Task_Manual_One', workflow.next_task.name)
self.assertEqual('ManualTask', workflow_api.next_task.type)
# TODO: Not sure what to do here. The following assertion fails.
# The documentation field in this workflow doesn't have anything in it.
# I'm not sure where 'Markdown' and 'Dan' come from.
# self.assertTrue('Markdown' in workflow_api.next_task.documentation)
# self.assertTrue('Dan' in workflow_api.next_task.documentation)
self.assertTrue('Markdown' in workflow_api.next_task.documentation)
self.assertTrue('Dan' in workflow_api.next_task.documentation)
def test_bpmn_extension_properties_are_populated(self):
workflow = self.create_workflow('manual_task_with_external_documentation')