From 07bf4b4944c5f8a2b6988f963f70f6c85546b36d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?micha=C5=82=20s=C5=82owikowski?= Date: Thu, 24 Oct 2019 14:23:22 +0200 Subject: [PATCH 1/2] rename GcfHook to CloudFunctionsHook --- airflow/contrib/hooks/gcp_function_hook.py | 2 +- airflow/gcp/hooks/functions.py | 2 +- airflow/gcp/operators/functions.py | 8 ++-- tests/gcp/hooks/test_functions.py | 48 +++++++++++----------- tests/gcp/operators/test_functions.py | 46 ++++++++++----------- tests/test_core_to_contrib.py | 4 +- 6 files changed, 55 insertions(+), 55 deletions(-) diff --git a/airflow/contrib/hooks/gcp_function_hook.py b/airflow/contrib/hooks/gcp_function_hook.py index 007dd6a5c5bbb..9d1b49c45d086 100644 --- a/airflow/contrib/hooks/gcp_function_hook.py +++ b/airflow/contrib/hooks/gcp_function_hook.py @@ -21,7 +21,7 @@ import warnings # pylint: disable=unused-import -from airflow.gcp.hooks.functions import GcfHook # noqa +from airflow.gcp.hooks.functions import CloudFunctionsHook # noqa warnings.warn( "This module is deprecated. Please use `airflow.gcp.hooks.functions`.", diff --git a/airflow/gcp/hooks/functions.py b/airflow/gcp/hooks/functions.py index 9a426320ae266..5a6b7c69d574d 100644 --- a/airflow/gcp/hooks/functions.py +++ b/airflow/gcp/hooks/functions.py @@ -33,7 +33,7 @@ # noinspection PyAbstractClass -class GcfHook(GoogleCloudBaseHook): +class CloudFunctionsHook(GoogleCloudBaseHook): """ Hook for the Google Cloud Functions APIs. diff --git a/airflow/gcp/operators/functions.py b/airflow/gcp/operators/functions.py index 798e05abada00..09b90fc5fc3f3 100644 --- a/airflow/gcp/operators/functions.py +++ b/airflow/gcp/operators/functions.py @@ -26,7 +26,7 @@ from googleapiclient.errors import HttpError from airflow import AirflowException -from airflow.gcp.hooks.functions import GcfHook +from airflow.gcp.hooks.functions import CloudFunctionsHook from airflow.gcp.utils.field_validator import GcpBodyFieldValidator, GcpFieldValidationException from airflow.models import BaseOperator from airflow.utils.decorators import apply_defaults @@ -190,7 +190,7 @@ def _set_airflow_version_label(self): {'airflow-version': 'v' + version.replace('.', '-').replace('+', '-')}) def execute(self, context): - hook = GcfHook(gcp_conn_id=self.gcp_conn_id, api_version=self.api_version) + hook = CloudFunctionsHook(gcp_conn_id=self.gcp_conn_id, api_version=self.api_version) if self.zip_path_preprocessor.should_upload_function(): self.body[GCF_SOURCE_UPLOAD_URL] = self._upload_source_code(hook) self._validate_all_body_fields() @@ -334,7 +334,7 @@ def _validate_inputs(self): 'Parameter name must match pattern: {}'.format(FUNCTION_NAME_PATTERN)) def execute(self, context): - hook = GcfHook(gcp_conn_id=self.gcp_conn_id, api_version=self.api_version) + hook = CloudFunctionsHook(gcp_conn_id=self.gcp_conn_id, api_version=self.api_version) try: return hook.delete_function(self.name) except HttpError as e: @@ -389,7 +389,7 @@ def __init__( self.api_version = api_version def execute(self, context: Dict): - hook = GcfHook(api_version=self.api_version, gcp_conn_id=self.gcp_conn_id) + hook = CloudFunctionsHook(api_version=self.api_version, gcp_conn_id=self.gcp_conn_id) self.log.info('Calling function %s.', self.function_id) result = hook.call_function( function_id=self.function_id, diff --git a/tests/gcp/hooks/test_functions.py b/tests/gcp/hooks/test_functions.py index e67322c38b61f..ad58a4ded70a1 100644 --- a/tests/gcp/hooks/test_functions.py +++ b/tests/gcp/hooks/test_functions.py @@ -20,7 +20,7 @@ import unittest from airflow import AirflowException -from airflow.gcp.hooks.functions import GcfHook +from airflow.gcp.hooks.functions import CloudFunctionsHook from tests.compat import PropertyMock, mock from tests.gcp.utils.base_gcp_mock import ( GCP_PROJECT_ID_HOOK_UNIT_TEST, get_open_mock, mock_base_gcp_hook_default_project_id, @@ -36,9 +36,9 @@ class TestFunctionHookNoDefaultProjectId(unittest.TestCase): def setUp(self): with mock.patch('airflow.gcp.hooks.base.GoogleCloudBaseHook.__init__', new=mock_base_gcp_hook_no_default_project_id): - self.gcf_function_hook_no_project_id = GcfHook(gcp_conn_id='test', api_version='v1') + self.gcf_function_hook_no_project_id = CloudFunctionsHook(gcp_conn_id='test', api_version='v1') - @mock.patch("airflow.gcp.hooks.functions.GcfHook._authorize") + @mock.patch("airflow.gcp.hooks.functions.CloudFunctionsHook._authorize") @mock.patch("airflow.gcp.hooks.functions.build") def test_gcf_client_creation(self, mock_build, mock_authorize): result = self.gcf_function_hook_no_project_id.get_conn() @@ -53,8 +53,8 @@ def test_gcf_client_creation(self, mock_build, mock_authorize): new_callable=PropertyMock, return_value=None ) - @mock.patch('airflow.gcp.hooks.functions.GcfHook.get_conn') - @mock.patch('airflow.gcp.hooks.functions.GcfHook._wait_for_operation_to_complete') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook.get_conn') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook._wait_for_operation_to_complete') def test_create_new_function_missing_project_id( self, wait_for_operation_to_complete, get_conn, mock_project_id ): @@ -74,8 +74,8 @@ def test_create_new_function_missing_project_id( self.assertIn("The project id must be passed", str(err)) wait_for_operation_to_complete.assert_not_called() - @mock.patch('airflow.gcp.hooks.functions.GcfHook.get_conn') - @mock.patch('airflow.gcp.hooks.functions.GcfHook._wait_for_operation_to_complete') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook.get_conn') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook._wait_for_operation_to_complete') def test_create_new_function_overridden_project_id(self, wait_for_operation_to_complete, get_conn): create_method = get_conn.return_value.projects.return_value.locations. \ return_value.functions.return_value.create @@ -99,7 +99,7 @@ def test_create_new_function_overridden_project_id(self, wait_for_operation_to_c return_value=None ) @mock.patch('requests.put') - @mock.patch('airflow.gcp.hooks.functions.GcfHook.get_conn') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook.get_conn') def test_upload_function_zip_missing_project_id( self, get_conn, requests_put, mock_project_id ): @@ -122,7 +122,7 @@ def test_upload_function_zip_missing_project_id( self.assertIn("The project id must be passed", str(err)) @mock.patch('requests.put') - @mock.patch('airflow.gcp.hooks.functions.GcfHook.get_conn') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook.get_conn') def test_upload_function_zip_overridden_project_id(self, get_conn, requests_put): mck, open_module = get_open_mock() with mock.patch('{}.open'.format(open_module), mck): @@ -152,9 +152,9 @@ class TestFunctionHookDefaultProjectId(unittest.TestCase): def setUp(self): with mock.patch('airflow.gcp.hooks.base.GoogleCloudBaseHook.__init__', new=mock_base_gcp_hook_default_project_id): - self.gcf_function_hook = GcfHook(gcp_conn_id='test', api_version='v1') + self.gcf_function_hook = CloudFunctionsHook(gcp_conn_id='test', api_version='v1') - @mock.patch("airflow.gcp.hooks.functions.GcfHook._authorize") + @mock.patch("airflow.gcp.hooks.functions.CloudFunctionsHook._authorize") @mock.patch("airflow.gcp.hooks.functions.build") def test_gcf_client_creation(self, mock_build, mock_authorize): result = self.gcf_function_hook.get_conn() @@ -169,8 +169,8 @@ def test_gcf_client_creation(self, mock_build, mock_authorize): new_callable=PropertyMock, return_value=GCP_PROJECT_ID_HOOK_UNIT_TEST ) - @mock.patch('airflow.gcp.hooks.functions.GcfHook.get_conn') - @mock.patch('airflow.gcp.hooks.functions.GcfHook._wait_for_operation_to_complete') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook.get_conn') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook._wait_for_operation_to_complete') def test_create_new_function(self, wait_for_operation_to_complete, get_conn, mock_project_id): create_method = get_conn.return_value.projects.return_value.locations.\ return_value.functions.return_value.create @@ -187,8 +187,8 @@ def test_create_new_function(self, wait_for_operation_to_complete, get_conn, moc execute_method.assert_called_once_with(num_retries=5) wait_for_operation_to_complete.assert_called_once_with(operation_name='operation_id') - @mock.patch('airflow.gcp.hooks.functions.GcfHook.get_conn') - @mock.patch('airflow.gcp.hooks.functions.GcfHook._wait_for_operation_to_complete') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook.get_conn') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook._wait_for_operation_to_complete') def test_create_new_function_override_project_id(self, wait_for_operation_to_complete, get_conn): create_method = get_conn.return_value.projects.return_value.locations. \ return_value.functions.return_value.create @@ -206,7 +206,7 @@ def test_create_new_function_override_project_id(self, wait_for_operation_to_com execute_method.assert_called_once_with(num_retries=5) wait_for_operation_to_complete.assert_called_once_with(operation_name='operation_id') - @mock.patch('airflow.gcp.hooks.functions.GcfHook.get_conn') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook.get_conn') def test_get_function(self, get_conn): get_method = get_conn.return_value.projects.return_value.locations. \ return_value.functions.return_value.get @@ -220,8 +220,8 @@ def test_get_function(self, get_conn): get_method.assert_called_once_with(name='function') execute_method.assert_called_once_with(num_retries=5) - @mock.patch('airflow.gcp.hooks.functions.GcfHook.get_conn') - @mock.patch('airflow.gcp.hooks.functions.GcfHook._wait_for_operation_to_complete') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook.get_conn') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook._wait_for_operation_to_complete') def test_delete_function(self, wait_for_operation_to_complete, get_conn): delete_method = get_conn.return_value.projects.return_value.locations. \ return_value.functions.return_value.delete @@ -235,8 +235,8 @@ def test_delete_function(self, wait_for_operation_to_complete, get_conn): delete_method.assert_called_once_with(name='function') execute_method.assert_called_once_with(num_retries=5) - @mock.patch('airflow.gcp.hooks.functions.GcfHook.get_conn') - @mock.patch('airflow.gcp.hooks.functions.GcfHook._wait_for_operation_to_complete') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook.get_conn') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook._wait_for_operation_to_complete') def test_update_function(self, wait_for_operation_to_complete, get_conn): patch_method = get_conn.return_value.projects.return_value.locations. \ return_value.functions.return_value.patch @@ -263,7 +263,7 @@ def test_update_function(self, wait_for_operation_to_complete, get_conn): return_value=GCP_PROJECT_ID_HOOK_UNIT_TEST ) @mock.patch('requests.put') - @mock.patch('airflow.gcp.hooks.functions.GcfHook.get_conn') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook.get_conn') def test_upload_function_zip(self, get_conn, requests_put, mock_project_id): mck, open_module = get_open_mock() with mock.patch('{}.open'.format(open_module), mck): @@ -288,7 +288,7 @@ def test_upload_function_zip(self, get_conn, requests_put, mock_project_id): ) @mock.patch('requests.put') - @mock.patch('airflow.gcp.hooks.functions.GcfHook.get_conn') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook.get_conn') def test_upload_function_zip_overridden_project_id(self, get_conn, requests_put): mck, open_module = get_open_mock() with mock.patch('{}.open'.format(open_module), mck): @@ -313,7 +313,7 @@ def test_upload_function_zip_overridden_project_id(self, get_conn, requests_put) url='http://uploadHere' ) - @mock.patch('airflow.gcp.hooks.functions.GcfHook.get_conn') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook.get_conn') def test_call_function(self, mock_get_conn): payload = {'executionId': 'wh41ppcyoa6l', 'result': 'Hello World!'} call = mock_get_conn.return_value.projects.return_value.\ @@ -338,7 +338,7 @@ def test_call_function(self, mock_get_conn): call.assert_called_once_with(body=input_data, name=name) self.assertDictEqual(result, payload) - @mock.patch('airflow.gcp.hooks.functions.GcfHook.get_conn') + @mock.patch('airflow.gcp.hooks.functions.CloudFunctionsHook.get_conn') def test_call_function_error(self, mock_get_conn): payload = {'error': 'Something very bad'} call = mock_get_conn.return_value.projects.return_value. \ diff --git a/tests/gcp/operators/test_functions.py b/tests/gcp/operators/test_functions.py index 238af763529df..953ca23808a63 100644 --- a/tests/gcp/operators/test_functions.py +++ b/tests/gcp/operators/test_functions.py @@ -70,7 +70,7 @@ def _prepare_test_bodies(): class TestGcfFunctionDeploy(unittest.TestCase): @parameterized.expand(_prepare_test_bodies()) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_body_empty_or_missing_fields(self, body, message, mock_hook): mock_hook.return_value.upload_function_zip.return_value = 'https://uploadUrl' with self.assertRaises(AirflowException) as cm: @@ -84,7 +84,7 @@ def test_body_empty_or_missing_fields(self, body, message, mock_hook): err = cm.exception self.assertIn(message, str(err)) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_deploy_execute(self, mock_hook): mock_hook.return_value.get_function.side_effect = mock.Mock( side_effect=HttpError(resp=MOCK_RESP_404, content=b'not found')) @@ -111,7 +111,7 @@ def test_deploy_execute(self, mock_hook): body=expected_body ) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_update_function_if_exists(self, mock_hook): mock_hook.return_value.get_function.return_value = True mock_hook.return_value.update_function.return_value = True @@ -136,7 +136,7 @@ def test_update_function_if_exists(self, mock_hook): expected_body, expected_body.keys()) mock_hook.return_value.create_new_function.assert_not_called() - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_empty_project_id_is_ok(self, mock_hook): mock_hook.return_value.get_function.side_effect = \ HttpError(resp=MOCK_RESP_404, content=b'not found') @@ -156,7 +156,7 @@ def test_empty_project_id_is_ok(self, mock_hook): location="test_region", body=new_body) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_empty_location(self, mock_hook): with self.assertRaises(AirflowException) as cm: GcfFunctionDeployOperator( @@ -168,7 +168,7 @@ def test_empty_location(self, mock_hook): err = cm.exception self.assertIn("The required parameter 'location' is missing", str(err)) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_empty_body(self, mock_hook): with self.assertRaises(AirflowException) as cm: GcfFunctionDeployOperator( @@ -183,7 +183,7 @@ def test_empty_body(self, mock_hook): @parameterized.expand([ (runtime,) for runtime in VALID_RUNTIMES ]) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_correct_runtime_field(self, runtime, mock_hook): mock_hook.return_value.create_new_function.return_value = True body = deepcopy(VALID_BODY) @@ -207,7 +207,7 @@ def test_correct_runtime_field(self, runtime, mock_hook): "projects/PRÓJECT/global/networks/netwórk-01" ] ]) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_valid_network_field(self, network, mock_hook): mock_hook.return_value.create_new_function.return_value = True body = deepcopy(VALID_BODY) @@ -230,7 +230,7 @@ def test_valid_network_field(self, network, mock_hook): {"label_324234_a_b_c": 'value-01_93'}, ] ]) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_valid_labels_field(self, labels, mock_hook): mock_hook.return_value.create_new_function.return_value = True body = deepcopy(VALID_BODY) @@ -246,7 +246,7 @@ def test_valid_labels_field(self, labels, mock_hook): gcp_conn_id='google_cloud_default') mock_hook.reset_mock() - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_validation_disabled(self, mock_hook): mock_hook.return_value.create_new_function.return_value = True body = { @@ -265,7 +265,7 @@ def test_validation_disabled(self, mock_hook): gcp_conn_id='google_cloud_default') mock_hook.reset_mock() - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_body_validation_simple(self, mock_hook): mock_hook.return_value.create_new_function.return_value = True body = deepcopy(VALID_BODY) @@ -301,7 +301,7 @@ def test_body_validation_simple(self, mock_hook): ('maxInstances', '-1', "The max instances parameter has to be greater than 0"), ('maxInstances', 'ss', "invalid literal for int() with base 10: 'ss'"), ]) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_invalid_field_values(self, key, value, message, mock_hook): mock_hook.return_value.create_new_function.return_value = True body = deepcopy(VALID_BODY) @@ -384,7 +384,7 @@ def test_invalid_source_code_union_field(self, source_code, message): 'repos/b/revisions/c/paths/d'}}, 'test_project_id'), ]) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_valid_source_code_union_field(self, source_code, project_id, mock_hook): mock_hook.return_value.upload_function_zip.return_value = 'https://uploadUrl' mock_hook.return_value.get_function.side_effect = mock.Mock( @@ -450,7 +450,7 @@ def test_valid_source_code_union_field(self, source_code, project_id, mock_hook) "should be of dictionary type") ] ) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_invalid_trigger_union_field(self, trigger, message, mock_hook): mock_hook.return_value.upload_function_zip.return_value = 'https://uploadUrl' body = deepcopy(VALID_BODY) @@ -486,7 +486,7 @@ def test_invalid_trigger_union_field(self, trigger, message, mock_hook): 'service': 'service_name', 'failurePolicy': {'retry': {}}}},) ]) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_valid_trigger_union_field(self, trigger, mock_hook): mock_hook.return_value.upload_function_zip.return_value = 'https://uploadUrl' mock_hook.return_value.get_function.side_effect = mock.Mock( @@ -515,7 +515,7 @@ def test_valid_trigger_union_field(self, trigger, mock_hook): ) mock_hook.reset_mock() - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_extra_parameter(self, mock_hook): mock_hook.return_value.create_new_function.return_value = True body = deepcopy(VALID_BODY) @@ -548,7 +548,7 @@ class TestGcfFunctionDelete(unittest.TestCase): 'updateTime': '2018-08-23T00:00:00Z', 'versionId': '1', 'runtime': 'nodejs6'} - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_delete_execute(self, mock_hook): mock_hook.return_value.delete_function.return_value = \ self._DELETE_FUNCTION_EXPECTED @@ -564,7 +564,7 @@ def test_delete_execute(self, mock_hook): ) self.assertEqual(result['name'], self._FUNCTION_NAME) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_correct_name(self, mock_hook): op = GcfFunctionDeleteOperator( name="projects/project_name/locations/project_location/functions" @@ -575,7 +575,7 @@ def test_correct_name(self, mock_hook): mock_hook.assert_called_once_with(api_version='v1', gcp_conn_id='google_cloud_default') - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_invalid_name(self, mock_hook): with self.assertRaises(AttributeError) as cm: op = GcfFunctionDeleteOperator( @@ -588,7 +588,7 @@ def test_invalid_name(self, mock_hook): FUNCTION_NAME_PATTERN)) mock_hook.assert_not_called() - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_empty_name(self, mock_hook): mock_hook.return_value.delete_function.return_value = \ self._DELETE_FUNCTION_EXPECTED @@ -601,7 +601,7 @@ def test_empty_name(self, mock_hook): self.assertEqual(str(err), 'Empty parameter: name') mock_hook.assert_not_called() - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_gcf_error_silenced_when_function_doesnt_exist(self, mock_hook): op = GcfFunctionDeleteOperator( name=self._FUNCTION_NAME, @@ -616,7 +616,7 @@ def test_gcf_error_silenced_when_function_doesnt_exist(self, mock_hook): 'projects/project_name/locations/project_location/functions/function_name' ) - @mock.patch('airflow.gcp.operators.functions.GcfHook') + @mock.patch('airflow.gcp.operators.functions.CloudFunctionsHook') def test_non_404_gcf_error_bubbled_up(self, mock_hook): op = GcfFunctionDeleteOperator( name=self._FUNCTION_NAME, @@ -638,7 +638,7 @@ def test_non_404_gcf_error_bubbled_up(self, mock_hook): class TestGcfFunctionInvokeOperator(unittest.TestCase): @mock.patch("airflow.gcp.operators.functions.BaseOperator.xcom_push") - @mock.patch("airflow.gcp.operators.functions.GcfHook") + @mock.patch("airflow.gcp.operators.functions.CloudFunctionsHook") def test_execute(self, mock_gcf_hook, mock_xcom): exec_id = 'exec_id' mock_gcf_hook.return_value.call_function.return_value = {'executionId': exec_id} diff --git a/tests/test_core_to_contrib.py b/tests/test_core_to_contrib.py index 5f9d07c3c6e56..22cf0ea18a400 100644 --- a/tests/test_core_to_contrib.py +++ b/tests/test_core_to_contrib.py @@ -45,8 +45,8 @@ "airflow.contrib.hooks.gcp_dlp_hook.CloudDLPHook", ), ( - "airflow.gcp.hooks.functions.GcfHook", - "airflow.contrib.hooks.gcp_function_hook.GcfHook", + "airflow.gcp.hooks.functions.CloudFunctionsHook", + "airflow.contrib.hooks.gcp_function_hook.CloudFunctionsHook", ), ( "airflow.gcp.hooks.kms.GoogleCloudKMSHook", From b22dc7dff069d8a33bae63f5e5682ca71718d7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?micha=C5=82=20s=C5=82owikowski?= Date: Thu, 24 Oct 2019 14:37:21 +0200 Subject: [PATCH 2/2] added to gcp_function_hook.py deprecation warning --- UPDATING.md | 2 +- airflow/contrib/hooks/gcp_function_hook.py | 14 ++++++++++++++ tests/test_core_to_contrib.py | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/UPDATING.md b/UPDATING.md index fd7d4fc9b8df1..f0ad86e5fd351 100644 --- a/UPDATING.md +++ b/UPDATING.md @@ -195,7 +195,7 @@ The following table shows changes in import paths. |airflow.contrib.hooks.gcp_dataflow_hook.DataFlowHook |airflow.gcp.hooks.dataflow.DataFlowHook | |airflow.contrib.hooks.gcp_dataproc_hook.DataProcHook |airflow.gcp.hooks.dataproc.DataProcHook | |airflow.contrib.hooks.gcp_dlp_hook.CloudDLPHook |airflow.gcp.hooks.dlp.CloudDLPHook | -|airflow.contrib.hooks.gcp_function_hook.GcfHook |airflow.gcp.hooks.functions.GcfHook | +|airflow.contrib.hooks.gcp_function_hook.GcfHook |airflow.gcp.hooks.functions.CloudFunctionsHook | |airflow.contrib.hooks.gcp_kms_hook.GoogleCloudKMSHook |airflow.gcp.hooks.kms.GoogleCloudKMSHook | |airflow.contrib.hooks.gcp_mlengine_hook.MLEngineHook |airflow.gcp.hooks.mlengine.MLEngineHook | |airflow.contrib.hooks.gcp_natural_language_hook.CloudNaturalLanguageHook |airflow.gcp.hooks.natural_language.CloudNaturalLanguageHook | diff --git a/airflow/contrib/hooks/gcp_function_hook.py b/airflow/contrib/hooks/gcp_function_hook.py index 9d1b49c45d086..e8ea954c3bfce 100644 --- a/airflow/contrib/hooks/gcp_function_hook.py +++ b/airflow/contrib/hooks/gcp_function_hook.py @@ -27,3 +27,17 @@ "This module is deprecated. Please use `airflow.gcp.hooks.functions`.", DeprecationWarning, stacklevel=2 ) + + +class GcfHook(CloudFunctionsHook): + """ + This class is deprecated. Please use `airflow.gcp.hooks.functions.CloudFunctionsHook`. + """ + + def __init__(self, *args, **kwargs): + warnings.warn( + "This class is deprecated. Please use `airflow.gcp.hooks.functions.CloudFunctionsHook`.", + DeprecationWarning, stacklevel=2 + ) + + super().__init__(*args, **kwargs) diff --git a/tests/test_core_to_contrib.py b/tests/test_core_to_contrib.py index 22cf0ea18a400..350667d52aa17 100644 --- a/tests/test_core_to_contrib.py +++ b/tests/test_core_to_contrib.py @@ -46,7 +46,7 @@ ), ( "airflow.gcp.hooks.functions.CloudFunctionsHook", - "airflow.contrib.hooks.gcp_function_hook.CloudFunctionsHook", + "airflow.contrib.hooks.gcp_function_hook.GcfHook", ), ( "airflow.gcp.hooks.kms.GoogleCloudKMSHook",