airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From criccom...@apache.org
Subject incubator-airflow git commit: [AIRFLOW-1727] Add unit tests for DataProcHook
Date Wed, 18 Oct 2017 18:28:11 GMT
Repository: incubator-airflow
Updated Branches:
  refs/heads/master cb868f49f -> b7a1f8b9c


[AIRFLOW-1727] Add unit tests for DataProcHook

Closes #2697 from cjqian/1727


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/b7a1f8b9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/b7a1f8b9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/b7a1f8b9

Branch: refs/heads/master
Commit: b7a1f8b9cbbf795f663987254a681281cda46abf
Parents: cb868f4
Author: Crystal Qian <crystaljqian@gmail.com>
Authored: Wed Oct 18 11:28:04 2017 -0700
Committer: Chris Riccomini <criccomini@apache.org>
Committed: Wed Oct 18 11:28:04 2017 -0700

----------------------------------------------------------------------
 tests/contrib/hooks/test_gcp_dataproc_hook.py | 48 ++++++++++++++++++++++
 1 file changed, 48 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/b7a1f8b9/tests/contrib/hooks/test_gcp_dataproc_hook.py
----------------------------------------------------------------------
diff --git a/tests/contrib/hooks/test_gcp_dataproc_hook.py b/tests/contrib/hooks/test_gcp_dataproc_hook.py
new file mode 100644
index 0000000..f49ec7d
--- /dev/null
+++ b/tests/contrib/hooks/test_gcp_dataproc_hook.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import unittest
+from airflow.contrib.hooks.gcp_dataproc_hook import DataProcHook
+
+try:
+    from unittest import mock
+except ImportError:
+    try:
+        import mock
+    except ImportError:
+        mock = None
+
+JOB = 'test-job'
+PROJECT_ID = 'test-project-id'
+REGION = 'global'
+TASK_ID = 'test-task-id'
+
+BASE_STRING = 'airflow.contrib.hooks.gcp_api_base_hook.{}'
+DATAPROC_STRING = 'airflow.contrib.hooks.gcp_dataproc_hook.{}'
+
+def mock_init(self, gcp_conn_id, delegate_to=None):
+    pass
+
+class DataProcHookTest(unittest.TestCase):
+    def setUp(self):
+        with mock.patch(BASE_STRING.format('GoogleCloudBaseHook.__init__'),
+                        new=mock_init):
+            self.dataproc_hook = DataProcHook()
+
+    @mock.patch(DATAPROC_STRING.format('_DataProcJob'))
+    def test_submit(self, job_mock):
+      with mock.patch(DATAPROC_STRING.format('DataProcHook.get_conn', return_value=None)):
+        self.dataproc_hook.submit(PROJECT_ID, JOB)
+        job_mock.assert_called_once_with(mock.ANY, PROJECT_ID, JOB, REGION)


Mime
View raw message