本文整理汇总了Python中recore.fsm.FSM.on_started方法的典型用法代码示例。如果您正苦于以下问题:Python FSM.on_started方法的具体用法?Python FSM.on_started怎么用?Python FSM.on_started使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类recore.fsm.FSM
的用法示例。
在下文中一共展示了FSM.on_started方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_on_started
# 需要导入模块: from recore.fsm import FSM [as 别名]
# 或者: from recore.fsm.FSM import on_started [as 别名]
def test_on_started(self, ended, pdc):
"""Once started, the FSM waits for a response, and then calls on_ended"""
pdc.return_value = True
with nested(
mock.patch('recore.mongo.lookup_state'),
mock.patch('recore.mongo.database')
) as (lookup_state, database):
lookup_state.return_value = _state.copy()
# {
# 'group': 'PROJECT',
# 'dynamic': {},
# 'completed_steps': [],
# 'active_step': 'active_step',
# 'remaining_steps': [],
# }
f = FSM(TEST_PBID, state_id)
f.reply_queue = temp_queue
f.group = 'GROUP'
consume_iter = [
(mock.Mock(name="method_mocked"),
mock.Mock(name="properties_mocked"),
json.dumps(msg_started))
]
publish = mock.Mock()
channel = mock.Mock()
channel.consume.return_value = iter(consume_iter)
channel.basic_publish = publish
f.ch = channel
f.conn = mock.Mock(pika.connection.Connection)
set_field = mock.MagicMock()
filter = mock.MagicMock(return_value=set_field)
f.filter = filter
f._setup()
f.on_started(f.ch, *consume_iter[0])
f.ch.basic_ack.assert_called_once_with(consume_iter[0][0].delivery_tag)
f.ch.cancel.assert_called_once_with()
f.on_ended.assert_called_once_with(f.ch, *consume_iter[0])
示例2: test_on_started
# 需要导入模块: from recore.fsm import FSM [as 别名]
# 或者: from recore.fsm.FSM import on_started [as 别名]
def test_on_started(self, ended):
"""Once started, the FSM waits for a response, and then calls on_ended"""
f = FSM(state_id)
f.reply_queue = temp_queue
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.on_started(f.ch, *consume_iter[0])
f.ch.basic_ack.assert_called_once_with(consume_iter[0][0].delivery_tag)
f.ch.cancel.assert_called_once_with()
ended.assert_called_once_with(f.ch, *consume_iter[0])
示例3: test_step_notification_failed_before_started_received
# 需要导入模块: from recore.fsm import FSM [as 别名]
# 或者: from recore.fsm.FSM import on_started [as 别名]
def test_step_notification_failed_before_started_received(self, send_notification, move_active, run, skipped):
"""Per-step notifications happen if a step fails when the worker attempts to start it"""
f = FSM(state_id)
msg_failed = {'status': 'failed'}
consume_iter = [
(mock.Mock(name="method_mocked"),
mock.Mock(name="properties_mocked"),
json.dumps(msg_failed))
]
# Pre-test scaffolding. Hard-code some mocked out
# attributes/variables because we're skipping the usual
# initialization steps.
f.conn = mock.Mock(pika.connection.Connection)
publish = mock.Mock()
channel = mock.Mock()
channel.consume.return_value = iter(consume_iter)
channel.basic_publish = publish
f.ch = channel
f.active_sequence = {'hosts': ['localhost']}
f.group = 'testgroup'
f.dynamic = {}
f.active_step = new_notify_step('failed')
# Run the ended method with a body having 'status' as completed
f.on_started(channel,
mock.Mock(name="method_mocked"),
mock.Mock(name="header_mocked"),
json.dumps(msg_failed))
self.assertEqual(send_notification.call_count, 1)
self.assertEqual(send_notification.call_args[0][1], 'notify.irc')
self.assertEqual(send_notification.call_args[0][2], state_id)
self.assertEqual(send_notification.call_args[0][3], ['#achannel'])
self.assertEqual(send_notification.call_args[0][4], 'failed')