Ejemplo n.º 1
0
    def _build_state_machine(self):
        self.state = StateMachine(initial_state='new')
        self._add_state('new', 'GREET', 'greeted')
        self._add_state('greeted', 'HELO', 'initialized')

        self._add_state('greeted',
                        'EHLO',
                        'initialized',
                        operations=('set_esmtp', ))

        # ----
        self._add_state('initialized', 'MAIL FROM', 'sender_known')

        self._add_state('initialized',
                        'AUTH PLAIN',
                        'authenticated',
                        condition='if_esmtp')
        self._add_state('initialized',
                        'AUTH LOGIN',
                        'authenticated',
                        condition='if_esmtp')
        self._add_state('authenticated', 'AUTH LOGIN', 'authenticated')
        self._add_state('authenticated', 'MAIL FROM', 'sender_known')
        # ----

        self._add_state('sender_known', 'RCPT TO', 'recipient_known')
        # multiple recipients
        self._add_state('recipient_known', 'RCPT TO', 'recipient_known')
        self._add_state('recipient_known', 'DATA', 'receiving_message')
        self._add_state('receiving_message', 'MSGDATA', 'initialized')
        self._add_help_noop_and_quit_transitions()
        self._add_rset_transitions()
        self.valid_commands = self.state.known_actions()
Ejemplo n.º 2
0
 def test_no_state_if_initial_state_not_available(self):
     state = StateMachine(initial_state='invalid')
     assert_none(state.state())
     assert_true(state.is_impossible_state())
Ejemplo n.º 3
0
 def test_can_ask_for_current_state(self):
     state = StateMachine(initial_state='foo')
     state.add('foo', 'foo', 'noop')
     assert_equals('foo', state.state())
     assert_false(state.is_impossible_state())
Ejemplo n.º 4
0
 def test_can_initialize_statemachine(self):
     StateMachine(initial_state='foo')
Ejemplo n.º 5
0
 def setUp(self):
     self.state = StateMachine(initial_state='new')
Ejemplo n.º 6
0
 def test_raise_exception_if_in_impossible_state(self):
     state = StateMachine(initial_state='invalid')
     state.add('new', 'processed', 'process')
     with assert_raises(StateMachineError):
         self.state.execute('process')