本文整理汇总了Python中pyon.event.event.EventPublisher.publish方法的典型用法代码示例。如果您正苦于以下问题:Python EventPublisher.publish方法的具体用法?Python EventPublisher.publish怎么用?Python EventPublisher.publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.event.event.EventPublisher
的用法示例。
在下文中一共展示了EventPublisher.publish方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestEventPublisher
# 需要导入模块: from pyon.event.event import EventPublisher [as 别名]
# 或者: from pyon.event.event.EventPublisher import publish [as 别名]
#.........这里部分代码省略.........
def test__set_event_msg_fields_no_args(self):
msg = Mock() # Mock has a __dict__ member so this works
pre_dict = str(msg.__dict__)
unused = self._pub._set_event_msg_fields(msg, {})
self.assertEquals(len(unused), 0)
self.assertEquals(str(pre_dict), str(msg.__dict__))
def test__set_event_msg_fields_args_not_in_msg(self):
msg = Mock()
pre_dict = str(msg.__dict__)
unused = self._pub._set_event_msg_fields(msg, {'field': sentinel.value, 'field2': sentinel.value2})
self.assertEquals(len(unused), 2)
self.assertIn('field', unused)
self.assertIn('field2', unused)
self.assertEquals(str(pre_dict), str(msg.__dict__))
def test__set_event_msg_fields(self):
msg = Mock()
msg.field = sentinel.old_value
msg.field2 = sentinel.old_value2
msg.field3 = sentinel.old_value3
pre_dict = str(msg.__dict__)
unused = self._pub._set_event_msg_fields(msg, {'field': sentinel.value, 'field2': sentinel.value2})
self.assertEquals(len(unused), 0)
self.assertNotEquals(str(pre_dict), str(msg.__dict__))
self.assertEquals(msg.field, sentinel.value)
self.assertEquals(msg.field2, sentinel.value2)
self.assertEquals(msg.field3, sentinel.old_value3)
@patch('pyon.event.event.bootstrap')
def test_create_event_default_timestamp(self, mockobj):
m = Mock()
m.ts_created = sentinel.old_ts_created
mockobj.IonObject.return_value = m
ev = self._pub.create_event()
mockobj.IonObject.assert_called_once_with(self._pub.msg_type)
self.assertTrue(hasattr(ev, 'ts_created'))
self.assertNotEquals(ev.ts_created, sentinel.old_ts_created)
self.assertIsInstance(ev.ts_created, float)
@patch('pyon.event.event.bootstrap')
def test_create_event_with_kwargs(self, mockobj):
m = Mock()
m.ts_created = sentinel.old_ts_created
m.field = sentinel.old_value
mockobj.IonObject.return_value = m
ev = self._pub.create_event(field=sentinel.value)
mockobj.IonObject.assert_called_once_with(self._pub.msg_type)
self.assertEquals(m.field, sentinel.value)
@patch('pyon.event.event.bootstrap')
def test_create_event_unknown_kwargs(self, mockobj):
m = Mock()
m.ts_created = sentinel.old_ts_created
mockobj.IonObject.return_value = m
with self.assertRaises(EventError) as cm:
self._pub.create_event(extra=sentinel.extra)
self.assertIn('extra', cm.exception.message)
def test_publish_event_no_origin(self):
self.assertRaises(AssertionError, self._pub.publish_event, sentinel.event_msg)
def test_publish_event(self):
self._pub.publish = Mock()
self._pub.publish_event(sentinel.event_msg, origin=sentinel.origin)
self._pub.publish.assert_called_once_with(sentinel.event_msg, to_name=(get_events_exchange_point(), self._pub._topic(sentinel.origin)))
self._pub.publish().close.assert_called_once_with()
def test_publish_event_with_event_repo(self):
self._pub.publish = Mock()
self._pub.event_repo = Mock()
self._pub.publish_event(sentinel.event_msg, origin=sentinel.origin)
self._pub.event_repo.put_event.assert_called_once_with(sentinel.event_msg)
def test_create_and_publish_event(self):
self._pub.create_event = Mock()
self._pub.create_event.return_value = sentinel.event_msg
self._pub.publish_event = Mock()
self._pub.create_and_publish_event(origin=sentinel.origin, field=sentinel.value, field2=sentinel.value2)
self._pub.create_event.assert_called_once_with(origin=sentinel.origin, field=sentinel.value, field2=sentinel.value2)
self._pub.publish_event.assert_called_once_with(sentinel.event_msg, origin=sentinel.origin)