当前位置: 首页>>代码示例>>Python>>正文


Python BaseDataHandler._find_new_data_check_attachment方法代码示例

本文整理汇总了Python中ion.agents.data.handlers.base_data_handler.BaseDataHandler._find_new_data_check_attachment方法的典型用法代码示例。如果您正苦于以下问题:Python BaseDataHandler._find_new_data_check_attachment方法的具体用法?Python BaseDataHandler._find_new_data_check_attachment怎么用?Python BaseDataHandler._find_new_data_check_attachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ion.agents.data.handlers.base_data_handler.BaseDataHandler的用法示例。


在下文中一共展示了BaseDataHandler._find_new_data_check_attachment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestBaseDataHandlerUnit

# 需要导入模块: from ion.agents.data.handlers.base_data_handler import BaseDataHandler [as 别名]
# 或者: from ion.agents.data.handlers.base_data_handler.BaseDataHandler import _find_new_data_check_attachment [as 别名]

#.........这里部分代码省略.........
            self._bdh.set()

    def test_set_not_dictionary(self):
        with self.assertRaises(InstrumentParameterException) as cm:
            self._bdh.set("not_found")

    def test_set_polling(self):
        # TODO: Need to change back to enums instead of strings. Problem with BaseEnum.
        self._bdh.set({"POLLING_INTERVAL": 7200})
        self.assertEqual(self._bdh.get(["POLLING_INTERVAL"]), {"POLLING_INTERVAL": 7200})

    def test_set_not_found(self):
        with self.assertRaises(InstrumentParameterException) as cm:
            self._bdh.set({"not_found": 1})

    def test_execute_acquire_data_not_dictionary(self):
        with self.assertRaises(ConfigurationError) as cm:
            self._bdh.execute_acquire_data("not_found")

    @patch("ion.agents.data.handlers.base_data_handler.spawn")
    def test_execute_acquire_data_with_stream_id_not_new(self, mock):
        self._bdh._semaphore = Mock()
        self._bdh._glet_queue = Mock()
        self._bdh.execute_acquire_data({"stream_id": "test_stream_id", "constraints": "test_constraints"})
        self._stream_registrar.create_publisher.assert_called_once_with(stream_id="test_stream_id")

    def test_execute_acquire_data_with_stream_id_new_already_acquiring(self):
        self._bdh._semaphore = Mock()
        self._bdh._semaphore.acquire.return_value = False
        self._bdh.execute_acquire_data({"stream_id": "test_stream_id"})
        self._bdh._semaphore.acquire.assert_called_once_with(blocking=False)

    @patch("ion.agents.data.handlers.base_data_handler.ResourceRegistryServiceClient")
    def test__find_new_data_check_attachment(self, rr_cli_cls):
        rr_cli = rr_cli_cls.return_value
        attachment_1 = Mock()
        attachment_1._id = "attachment_1"
        attachment_1.keywords = ["NewDataCheck"]
        attachment_1.content = "content"
        rr_cli.find_attachments.return_value = [attachment_1]

        ret = self._bdh._find_new_data_check_attachment(res_id="res_id")
        self.assertEqual(ret, "content")
        rr_cli.find_attachments.assert_called_once_with(resource_id="res_id", include_content=False, id_only=False)

    @patch("ion.agents.data.handlers.base_data_handler.ResourceRegistryServiceClient")
    def test__find_new_data_check_attachment_no_newdatacheck(self, rr_cli_cls):
        rr_cli = rr_cli_cls.return_value
        attachment_1 = Mock()
        attachment_1._id = "attachment_1"
        attachment_1.keywords = ["not_found"]
        attachment_1.content = "content"
        rr_cli.find_attachments.return_value = [attachment_1]

        ret = self._bdh._find_new_data_check_attachment(res_id="res_id")
        self.assertEqual(ret, None)
        rr_cli.find_attachments.assert_called_once_with(resource_id="res_id", include_content=False, id_only=False)

    @patch("ion.agents.data.handlers.base_data_handler.ResourceRegistryServiceClient")
    def test__find_new_data_check_attachment_raise_notfound(self, rr_cli_cls):
        rr_cli = rr_cli_cls.return_value
        rr_cli.find_attachments.side_effect = NotFound

        with self.assertRaises(InstrumentException) as cm:
            self._bdh._find_new_data_check_attachment(res_id="not_found")
开发者ID:pombredanne,项目名称:coi-services,代码行数:69,代码来源:test_base_data_handler.py

示例2: TestBaseDataHandlerUnit

# 需要导入模块: from ion.agents.data.handlers.base_data_handler import BaseDataHandler [as 别名]
# 或者: from ion.agents.data.handlers.base_data_handler.BaseDataHandler import _find_new_data_check_attachment [as 别名]

#.........这里部分代码省略.........
        with self.assertRaises(ConfigurationError):
            self._bdh.execute_acquire_sample('not_found')

    @patch('ion.agents.data.handlers.base_data_handler.StandaloneStreamPublisher', spec=StandaloneStreamPublisher)
    @patch('ion.agents.data.handlers.base_data_handler.spawn')
    def test_execute_acquire_sample_with_stream_id_not_new(self, mock, StreamPublisher_mock):
        self._bdh._semaphore = Mock()
        self._bdh._glet_queue = Mock()
        stream_route = Mock(spec=StreamRoute)
        stream_route.exchange_point = sentinel.exchange_point
        stream_route.routing_key = sentinel.routing_key

        StreamPublisher_mock.return_value = MagicMock(spec=StandaloneStreamPublisher)

        self._bdh.execute_acquire_sample({'stream_id': 'test_stream_id',
                                          'constraints': 'test_constraints',
                                          'stream_route': stream_route})

    @patch('ion.agents.data.handlers.base_data_handler.StandaloneStreamPublisher', spec=StandaloneStreamPublisher)
    def test_execute_acquire_sample_with_stream_id_new_already_acquiring(self, StreamPublisher_mock):
        self._bdh._semaphore = Mock()
        self._bdh._semaphore.acquire.return_value = False
        stream_route = Mock(spec=StreamRoute)
        stream_route.exchange_point = sentinel.exchange_point
        stream_route.routing_key = sentinel.routing_key

        StreamPublisher_mock.return_value = MagicMock(spec=StandaloneStreamPublisher)

        self._bdh.execute_acquire_sample({'stream_id': 'test_stream_id',
                                          'stream_route': stream_route})
        self._bdh._semaphore.acquire.assert_called_once_with(blocking=False)

    @patch('ion.agents.data.handlers.base_data_handler.ResourceRegistryServiceClient')
    def test__find_new_data_check_attachment(self, rr_cli_cls):
        rr_cli = rr_cli_cls.return_value
        attachment_1 = Mock()
        attachment_1._id = 'attachment_1'
        attachment_1.keywords = ['NewDataCheck']
        attachment_1.content = msgpack.packb('content')
        rr_cli.find_attachments.return_value = [attachment_1]

        ret = self._bdh._find_new_data_check_attachment(res_id='res_id')
        self.assertEqual(ret, 'content')
        rr_cli.find_attachments.assert_called_once_with(resource_id='res_id',
            include_content=True,
            id_only=False)

    @patch('ion.agents.data.handlers.base_data_handler.ResourceRegistryServiceClient')
    def test__find_new_data_check_attachment_no_newdatacheck(self, rr_cli_cls):
        rr_cli = rr_cli_cls.return_value
        attachment_1 = Mock()
        attachment_1._id = 'attachment_1'
        attachment_1.keywords = ['not_found']
        attachment_1.content = 'content'
        rr_cli.find_attachments.return_value = [attachment_1]

        ret = self._bdh._find_new_data_check_attachment(res_id='res_id')
        self.assertEqual(ret, None)
        rr_cli.find_attachments.assert_called_once_with(resource_id='res_id',
            include_content=True,
            id_only=False)

    @patch('ion.agents.data.handlers.base_data_handler.ResourceRegistryServiceClient')
    def test__find_new_data_check_attachment_raise_notfound(self, rr_cli_cls):
        rr_cli = rr_cli_cls.return_value
        rr_cli.find_attachments.side_effect = NotFound
开发者ID:Bobfrat,项目名称:coi-services,代码行数:70,代码来源:test_base_data_handler.py


注:本文中的ion.agents.data.handlers.base_data_handler.BaseDataHandler._find_new_data_check_attachment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。