コード例 #1
0
ファイル: test_fsm.py プロジェクト: Acidburn0zzz/re-core
    def test__run(self, setup, dequeue, on_started):
        """The _run() method can send a proper message to a worker"""
        f = FSM(state_id)
        f.reply_queue = temp_queue

        f.project = "mock tests"
        f.dynamic = {}
        f.active = {
            'plugin': 'fake',
            'parameters': {'no': 'parameters'}
        }
        consume_iter = [
            (mock.Mock(name="method_mocked"),
             mock.Mock(name="properties_mocked"),
             json.dumps(msg_completed))
         ]

        publish = mock.Mock()
        channel = mock.Mock()
        channel.consume.return_value = iter(consume_iter)
        channel.basic_publish = publish
        f.ch = channel

        f._run()

        setup.assert_called_once_with()
        dequeue.assert_called_once_with()
        f.ch.basic_ack.assert_called_once_with(consume_iter[0][0].delivery_tag)
        f.ch.cancel.assert_called_once_with()
        on_started.assert_called_once_with(f.ch, *consume_iter[0])
コード例 #2
0
ファイル: test_fsm.py プロジェクト: Acidburn0zzz/re-core
    def test_move_active_to_completed(self):
        """FSM can update after completing a step"""
        f = FSM(state_id)
        active_step = {"plugin": "not real"}
        f.active = active_step.copy()
        f.completed = []

        # For .called_once_with()
        _update_state = {
            '$set': {
                'active_step': None,
                'completed_steps': [active_step]
            }
        }

        with mock.patch.object(f, 'update_state') as (us):
            f.move_active_to_completed()
            us.assert_called_once_with(_update_state)
            self.assertEqual(f.active, None)
            self.assertEqual(f.completed, [active_step])