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


Python DockerOperator.get_hook方法代码示例

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


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

示例1: test_execute_no_docker_conn_id_no_hook

# 需要导入模块: from airflow.operators.docker_operator import DockerOperator [as 别名]
# 或者: from airflow.operators.docker_operator.DockerOperator import get_hook [as 别名]
    def test_execute_no_docker_conn_id_no_hook(self, operator_client_mock):
        # Mock out a Docker client, so operations don't raise errors
        client_mock = mock.Mock(name='DockerOperator.APIClient mock', spec=APIClient)
        client_mock.images.return_value = []
        client_mock.create_container.return_value = {'Id': 'some_id'}
        client_mock.logs.return_value = []
        client_mock.pull.return_value = []
        client_mock.wait.return_value = {"StatusCode": 0}
        operator_client_mock.return_value = client_mock

        # Create the DockerOperator
        operator = DockerOperator(
            image='publicregistry/someimage',
            owner='unittest',
            task_id='unittest'
        )

        # Mock out the DockerHook
        hook_mock = mock.Mock(name='DockerHook mock', spec=DockerHook)
        hook_mock.get_conn.return_value = client_mock
        operator.get_hook = mock.Mock(
            name='DockerOperator.get_hook mock',
            spec=DockerOperator.get_hook,
            return_value=hook_mock
        )

        operator.execute(None)
        self.assertEqual(
            operator.get_hook.call_count, 0,
            'Hook called though no docker_conn_id configured'
        )
开发者ID:MiguelPeralvo,项目名称:incubator-airflow,代码行数:33,代码来源:test_docker_operator.py

示例2: test_execute_with_docker_conn_id_use_hook

# 需要导入模块: from airflow.operators.docker_operator import DockerOperator [as 别名]
# 或者: from airflow.operators.docker_operator.DockerOperator import get_hook [as 别名]
    def test_execute_with_docker_conn_id_use_hook(self, operator_client_mock):
        # Mock out a Docker client, so operations don't raise errors
        client_mock = mock.Mock(name='DockerOperator.Client mock', spec=Client)
        client_mock.images.return_value = []
        client_mock.create_container.return_value = {'Id': 'some_id'}
        client_mock.logs.return_value = []
        client_mock.pull.return_value = []
        client_mock.wait.return_value = 0
        operator_client_mock.return_value = client_mock

        # Create the DockerOperator
        operator = DockerOperator(
            image='publicregistry/someimage',
            owner='unittest',
            task_id='unittest',
            docker_conn_id='some_conn_id'
        )

        # Mock out the DockerHook
        hook_mock = mock.Mock(name='DockerHook mock', spec=DockerHook)
        hook_mock.get_conn.return_value = client_mock
        operator.get_hook = mock.Mock(
            name='DockerOperator.get_hook mock',
            spec=DockerOperator.get_hook,
            return_value=hook_mock
        )

        operator.execute(None)
        self.assertEqual(
            operator_client_mock.call_count, 0,
            'Client was called on the operator instead of the hook'
        )
        self.assertEqual(
            operator.get_hook.call_count, 1,
            'Hook was not called although docker_conn_id configured'
        )
        self.assertEqual(
            client_mock.pull.call_count, 1,
            'Image was not pulled using operator client'
        )
开发者ID:7digital,项目名称:incubator-airflow,代码行数:42,代码来源:docker_operator.py


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