コード例 #1
0
ファイル: objects.py プロジェクト: python-edgy/workflow
class StatefulSubject(Subject, StatefulObject):
    is_duck = False
    is_pumpkin = False
    initial_state = 'human'
    state = StatefulObject.state  # property
    transitions = []
    _workflow = None

    @property
    def workflow(self):
        if not self._workflow:
            self._workflow = Workflow()
            for transition in self.transitions:
                self._workflow.add_transition(transition)
        return self._workflow
コード例 #2
0
ファイル: test_basic.py プロジェクト: python-edgy/workflow
    def test_workflow(self):
        # create a workflow
        workflow = Workflow()
        assert len(workflow._transitions) == 0

        # add an invalid transition
        with self.assertRaises(AttributeError):
            workflow.add_transition(object())
        assert len(workflow._transitions) == 0

        # add our "to_duck" transition to our workflow
        to_duck = create_transition_to_duck()
        workflow.add_transition(to_duck)

        # create a stateful subject
        subject = create_subject()

        # check we can see our transition as available
        available_transitions = workflow.get_available_transitions_for(subject)
        assert available_transitions["to_duck"] == to_duck
        assert len(available_transitions) == 1

        # execute transition and check our subject is now a duck
        to_duck(subject)
        assert subject.is_duck
        assert subject.state == "duck"
コード例 #3
0
ファイル: objects.py プロジェクト: python-edgy/workflow
 def workflow(self):
     if not self._workflow:
         self._workflow = Workflow()
         for transition in self.transitions:
             self._workflow.add_transition(transition)
     return self._workflow