You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2018/12/17 23:52:51 UTC

[GitHub] stale[bot] closed pull request #2776: [AIRFLOW-1793] fix DockerOperator using docker_conn_id

stale[bot] closed pull request #2776: [AIRFLOW-1793] fix DockerOperator using docker_conn_id
URL: https://github.com/apache/incubator-airflow/pull/2776
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/operators/docker_operator.py b/airflow/operators/docker_operator.py
index 38edc8b4d7..adaabd2e07 100644
--- a/airflow/operators/docker_operator.py
+++ b/airflow/operators/docker_operator.py
@@ -147,7 +147,7 @@ def __init__(
     def get_hook(self):
         return DockerHook(
             docker_conn_id=self.docker_conn_id,
-            base_url=self.base_url,
+            base_url=self.docker_url,
             version=self.api_version,
             tls=self.__get_tls_config()
         )
diff --git a/tests/operators/docker_operator.py b/tests/operators/docker_operator.py
index a12b6f829f..915992338d 100644
--- a/tests/operators/docker_operator.py
+++ b/tests/operators/docker_operator.py
@@ -188,7 +188,8 @@ def test_execute_no_docker_conn_id_no_hook(self, operator_client_mock):
         )
 
     @mock.patch('airflow.operators.docker_operator.Client')
-    def test_execute_with_docker_conn_id_use_hook(self, operator_client_mock):
+    @mock.patch('airflow.operators.docker_operator.DockerHook')
+    def test_execute_with_docker_conn_id_use_hook(self, docker_hook_mock, 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 = []
@@ -198,6 +199,9 @@ def test_execute_with_docker_conn_id_use_hook(self, operator_client_mock):
         client_mock.wait.return_value = 0
         operator_client_mock.return_value = client_mock
 
+        # Mock out the DockerHook
+        docker_hook_mock.return_value.get_conn.return_value = client_mock
+
         # Create the DockerOperator
         operator = DockerOperator(
             image='publicregistry/someimage',
@@ -206,22 +210,13 @@ def test_execute_with_docker_conn_id_use_hook(self, operator_client_mock):
             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,
+            docker_hook_mock.call_count, 1,
             'Hook was not called although docker_conn_id configured'
         )
         self.assertEqual(
@@ -229,5 +224,6 @@ def test_execute_with_docker_conn_id_use_hook(self, operator_client_mock):
             'Image was not pulled using operator client'
         )
 
+
 if __name__ == "__main__":
     unittest.main()


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services