Exemplo n.º 1
0
    def testSerializeWorkflow(self, path_file=None, data=None):
        if self.serializer is None:
            return
        
        if path_file is None:
            path_file = os.path.join(data_dir, 'spiff', 'workflow1.path')
            path      = open(path_file).read()
        elif os.path.exists(path_file):
            path = open(path_file).read()
        else:
            path = None

        # run a workflow fresh from the spec to completion, see if it
        # serialises and deserialises correctly.
        workflow_without_save  = run_workflow(self, self.wf_spec, path, data)
        try:
            serialized1 = workflow_without_save.serialize(self.serializer)
            restored_wf = Workflow.deserialize(self.serializer, serialized1)
            serialized2 = restored_wf.serialize(self.serializer)
        except TaskNotSupportedError as e:
            return
        else:
            self.assert_(isinstance(serialized1, self.serial_type))
            self.assert_(isinstance(serialized2, self.serial_type))
            self.compareSerialization(serialized1, serialized2)

        # try an freshly started workflow, see if it serialises and
        # deserialiases correctly. (no longer catch for exceptions: if they
        # were going to happen they should have happened already.)
        workflow = Workflow(self.wf_spec)
        serialized1 = workflow.serialize(self.serializer)
        restored_wf = Workflow.deserialize(self.serializer, serialized1)
        serialized2 = restored_wf.serialize(self.serializer)
        self.assert_(isinstance(serialized1, self.serial_type))
        self.assert_(isinstance(serialized2, self.serial_type))
        self.compareSerialization(serialized1, serialized2)
        self.assertFalse(restored_wf.is_completed())

        # Run it to completion, see if it serialises and deserialises correctly
        # also check if the restored and unrestored ones are the same after
        # being run through.
        workflow_unrestored = run_workflow(self, self.wf_spec, path, data, workflow=workflow)
        workflow_restored = run_workflow(self, self.wf_spec, path, data, workflow=restored_wf)

        serialized1 = workflow_restored.serialize(self.serializer)
        restored_wf = Workflow.deserialize(self.serializer, serialized1)
        serialized2 = restored_wf.serialize(self.serializer)
        self.assert_(isinstance(serialized1, self.serial_type))
        self.assert_(isinstance(serialized2, self.serial_type))
        self.compareSerialization(serialized1, serialized2)
        serialized_crosscheck = workflow_unrestored.serialize(self.serializer)
        self.assert_(isinstance(serialized_crosscheck, self.serial_type))
        # compare the restored and unrestored completed ones. Because they ran
        # separately, exclude the last_state_change time. Because you can have
        # dynamically created tasks, don't compare (uu)ids.
        self.compareSerialization(serialized_crosscheck, serialized2,
                                  exclude_dynamic=True)
Exemplo n.º 2
0
import json
from SpiffWorkflow import Workflow
from SpiffWorkflow.serializer.json import JSONSerializer
from nuclear import NuclearStrikeWorkflowSpec
serializer = JSONSerializer()
spec = NuclearStrikeWorkflowSpec()
workflow = Workflow(spec)
data = workflow.serialize(serializer)
pretty = json.dumps(data, indent=4, separators=(',', ': '))
open('workflow.json', 'w').write(pretty)
Exemplo n.º 3
0
import json
from SpiffWorkflow import Workflow
from SpiffWorkflow.serializer.json import JSONSerializer
from nuclear import NuclearStrikeWorkflowSpec

serializer = JSONSerializer()
spec = NuclearStrikeWorkflowSpec()
workflow = Workflow(spec)
data = workflow.serialize(serializer)

# This next line is unnecessary in practice; it just makes the JSON pretty.
pretty = json.dumps(json.loads(data), indent=4, separators=(',', ': '))

open('workflow.json', 'w').write(pretty)
Exemplo n.º 4
0
    def testSerializeWorkflow(self, path_file=None, data=None):
        if self.serializer is None:
            return

        if path_file is None:
            path_file = os.path.join(data_dir, 'spiff', 'workflow1.path')
            path = open(path_file).read()
        elif os.path.exists(path_file):
            path = open(path_file).read()
        else:
            path = None

        # run a workflow fresh from the spec to completion, see if it
        # serialises and deserialises correctly.
        workflow_without_save = run_workflow(self, self.wf_spec, path, data)
        try:
            serialized1 = workflow_without_save.serialize(self.serializer)
            restored_wf = Workflow.deserialize(self.serializer, serialized1)
            serialized2 = restored_wf.serialize(self.serializer)
        except TaskNotSupportedError as e:
            return
        else:
            self.assert_(isinstance(serialized1, self.serial_type))
            self.assert_(isinstance(serialized2, self.serial_type))
            self.compareSerialization(serialized1, serialized2)

        # try an freshly started workflow, see if it serialises and
        # deserialiases correctly. (no longer catch for exceptions: if they
        # were going to happen they should have happened already.)
        workflow = Workflow(self.wf_spec)
        serialized1 = workflow.serialize(self.serializer)
        restored_wf = Workflow.deserialize(self.serializer, serialized1)
        serialized2 = restored_wf.serialize(self.serializer)
        self.assert_(isinstance(serialized1, self.serial_type))
        self.assert_(isinstance(serialized2, self.serial_type))
        self.compareSerialization(serialized1, serialized2)
        self.assertFalse(restored_wf.is_completed())

        # Run it to completion, see if it serialises and deserialises correctly
        # also check if the restored and unrestored ones are the same after
        # being run through.
        workflow_unrestored = run_workflow(self,
                                           self.wf_spec,
                                           path,
                                           data,
                                           workflow=workflow)
        workflow_restored = run_workflow(self,
                                         self.wf_spec,
                                         path,
                                         data,
                                         workflow=restored_wf)

        serialized1 = workflow_restored.serialize(self.serializer)
        restored_wf = Workflow.deserialize(self.serializer, serialized1)
        serialized2 = restored_wf.serialize(self.serializer)
        self.assert_(isinstance(serialized1, self.serial_type))
        self.assert_(isinstance(serialized2, self.serial_type))
        self.compareSerialization(serialized1, serialized2)
        serialized_crosscheck = workflow_unrestored.serialize(self.serializer)
        self.assert_(isinstance(serialized_crosscheck, self.serial_type))
        # compare the restored and unrestored completed ones. Because they ran
        # separately, exclude the last_state_change time. Because you can have
        # dynamically created tasks, don't compare (uu)ids.
        self.compareSerialization(serialized_crosscheck,
                                  serialized2,
                                  exclude_dynamic=True)