Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,18 @@ 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.CloudFunctionsHook |
|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 |
|airflow.contrib.hooks.gcp_pubsub_hook.PubSubHook |airflow.gcp.hooks.pubsub.PubSubHook |
|airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook |airflow.gcp.hooks.spanner.SpannerHook |
|airflow.contrib.hooks.gcp_speech_to_text_hook.GCPSpeechToTextHook |airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook |
|airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook |airflow.gcp.hooks.spanner.SpannerHook |
|airflow.contrib.hooks.gcp_speech_to_text_hook.GCPSpeechToTextHook |airflow.gcp.hooks.speech_to_text.GCPSpeechToTextHook |
|airflow.contrib.hooks.gcp_sql_hook.CloudSqlDatabaseHook |airflow.gcp.hooks.cloud_sql.CloudSqlDatabaseHook |
|airflow.contrib.hooks.gcp_sql_hook.CloudSqlHook |airflow.gcp.hooks.cloud_sql.CloudSqlHook |
|airflow.contrib.hooks.gcp_tasks_hook.CloudTasksHook |airflow.gcp.hooks.tasks.CloudTasksHook |
|airflow.contrib.hooks.gcp_text_to_speech_hook.GCPTextToSpeechHook |airflow.gcp.hooks.text_to_speech.CloudTextToSpeechHook |
|airflow.contrib.hooks.gcp_text_to_speech_hook.GCPTextToSpeechHook |airflow.gcp.hooks.text_to_speech.CloudTextToSpeechHook |
|airflow.contrib.hooks.gcp_transfer_hook.GCPTransferServiceHook |airflow.gcp.hooks.cloud_storage_transfer_service.GCPTransferServiceHook |
|airflow.contrib.hooks.gcp_translate_hook.CloudTranslateHook |airflow.gcp.hooks.translate.CloudTranslateHook |
|airflow.contrib.hooks.gcp_video_intelligence_hook.CloudVideoIntelligenceHook |airflow.gcp.hooks.video_intelligence.CloudVideoIntelligenceHook |
Expand Down
17 changes: 15 additions & 2 deletions airflow/contrib/hooks/gcp_speech_to_text_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,23 @@

import warnings

# pylint: disable=unused-import
from airflow.gcp.hooks.speech_to_text import GCPSpeechToTextHook # noqa
from airflow.gcp.hooks.speech_to_text import CloudSpeechToTextHook

warnings.warn(
"This module is deprecated. Please use `airflow.gcp.hooks.speech_to_text`",
DeprecationWarning, stacklevel=2
)


class GCPSpeechToTextHook(CloudSpeechToTextHook):
"""
This class is deprecated. Please use `airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook`.
"""

def __init__(self, *args, **kwargs):
warnings.warn(
"This class is deprecated. Please use `airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook`.",
DeprecationWarning, stacklevel=2
)

super().__init__(*args, **kwargs)
2 changes: 1 addition & 1 deletion airflow/gcp/hooks/speech_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from airflow.gcp.hooks.base import GoogleCloudBaseHook


class GCPSpeechToTextHook(GoogleCloudBaseHook):
class CloudSpeechToTextHook(GoogleCloudBaseHook):
"""
Hook for Google Cloud Speech API.

Expand Down
4 changes: 2 additions & 2 deletions airflow/gcp/operators/speech_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from google.cloud.speech_v1.types import RecognitionConfig

from airflow import AirflowException
from airflow.gcp.hooks.speech_to_text import GCPSpeechToTextHook, RecognitionAudio
from airflow.gcp.hooks.speech_to_text import CloudSpeechToTextHook, RecognitionAudio
from airflow.models import BaseOperator
from airflow.utils.decorators import apply_defaults

Expand Down Expand Up @@ -90,7 +90,7 @@ def _validate_inputs(self):
raise AirflowException("The required parameter 'config' is empty")

def execute(self, context):
hook = GCPSpeechToTextHook(gcp_conn_id=self.gcp_conn_id)
hook = CloudSpeechToTextHook(gcp_conn_id=self.gcp_conn_id)
return hook.recognize_speech(
config=self.config, audio=self.audio, retry=self.retry, timeout=self.timeout
)
4 changes: 2 additions & 2 deletions airflow/gcp/operators/translate_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from google.protobuf.json_format import MessageToDict

from airflow import AirflowException
from airflow.gcp.hooks.speech_to_text import GCPSpeechToTextHook
from airflow.gcp.hooks.speech_to_text import CloudSpeechToTextHook
from airflow.gcp.hooks.translate import CloudTranslateHook
from airflow.models import BaseOperator
from airflow.utils.decorators import apply_defaults
Expand Down Expand Up @@ -127,7 +127,7 @@ def __init__(
self.gcp_conn_id = gcp_conn_id

def execute(self, context):
speech_to_text_hook = GCPSpeechToTextHook(gcp_conn_id=self.gcp_conn_id)
speech_to_text_hook = CloudSpeechToTextHook(gcp_conn_id=self.gcp_conn_id)
translate_hook = CloudTranslateHook(gcp_conn_id=self.gcp_conn_id)

recognize_result = speech_to_text_hook.recognize_speech(
Expand Down
10 changes: 5 additions & 5 deletions tests/gcp/hooks/test_speech_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import unittest

from airflow.gcp.hooks.speech_to_text import GCPSpeechToTextHook
from airflow.gcp.hooks.speech_to_text import CloudSpeechToTextHook
from tests.compat import PropertyMock, patch
from tests.gcp.utils.base_gcp_mock import mock_base_gcp_hook_default_project_id

Expand All @@ -35,10 +35,10 @@ def setUp(self):
"airflow.gcp.hooks.base.GoogleCloudBaseHook.__init__",
new=mock_base_gcp_hook_default_project_id,
):
self.gcp_speech_to_text_hook = GCPSpeechToTextHook(gcp_conn_id="test")
self.gcp_speech_to_text_hook = CloudSpeechToTextHook(gcp_conn_id="test")

@patch("airflow.gcp.hooks.speech_to_text.GCPSpeechToTextHook.client_info", new_callable=PropertyMock)
@patch("airflow.gcp.hooks.speech_to_text.GCPSpeechToTextHook._get_credentials")
@patch("airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook.client_info", new_callable=PropertyMock)
@patch("airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook._get_credentials")
@patch("airflow.gcp.hooks.speech_to_text.SpeechClient")
def test_speech_client_creation(self, mock_client, mock_get_creds, mock_client_info):
result = self.gcp_speech_to_text_hook.get_conn()
Expand All @@ -49,7 +49,7 @@ def test_speech_client_creation(self, mock_client, mock_get_creds, mock_client_i
self.assertEqual(mock_client.return_value, result)
self.assertEqual(self.gcp_speech_to_text_hook._client, result)

@patch("airflow.gcp.hooks.speech_to_text.GCPSpeechToTextHook.get_conn")
@patch("airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook.get_conn")
def test_synthesize_speech(self, get_conn):
recognize_method = get_conn.return_value.recognize
recognize_method.return_value = None
Expand Down
6 changes: 3 additions & 3 deletions tests/gcp/operators/test_speech_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


class TestCloudSql(unittest.TestCase):
@patch("airflow.gcp.operators.speech_to_text.GCPSpeechToTextHook")
@patch("airflow.gcp.operators.speech_to_text.CloudSpeechToTextHook")
def test_recognize_speech_green_path(self, mock_hook):
mock_hook.return_value.recognize_speech.return_value = True

Expand All @@ -43,7 +43,7 @@ def test_recognize_speech_green_path(self, mock_hook):
config=CONFIG, audio=AUDIO, retry=None, timeout=None
)

@patch("airflow.gcp.operators.speech_to_text.GCPSpeechToTextHook")
@patch("airflow.gcp.operators.speech_to_text.CloudSpeechToTextHook")
def test_missing_config(self, mock_hook):
mock_hook.return_value.recognize_speech.return_value = True

Expand All @@ -56,7 +56,7 @@ def test_missing_config(self, mock_hook):
self.assertIn("config", str(err))
mock_hook.assert_not_called()

@patch("airflow.gcp.operators.speech_to_text.GCPSpeechToTextHook")
@patch("airflow.gcp.operators.speech_to_text.CloudSpeechToTextHook")
def test_missing_audio(self, mock_hook):
mock_hook.return_value.recognize_speech.return_value = True

Expand Down
4 changes: 2 additions & 2 deletions tests/gcp/operators/test_translate_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


class TestCloudTranslateSpeech(unittest.TestCase):
@mock.patch('airflow.gcp.operators.translate_speech.GCPSpeechToTextHook')
@mock.patch('airflow.gcp.operators.translate_speech.CloudSpeechToTextHook')
@mock.patch('airflow.gcp.operators.translate_speech.CloudTranslateHook')
def test_minimal_green_path(self, mock_translate_hook, mock_speech_hook):
mock_speech_hook.return_value.recognize_speech.return_value = RecognizeResponse(
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_minimal_green_path(self, mock_translate_hook, mock_speech_hook):
return_value,
)

@mock.patch('airflow.gcp.operators.translate_speech.GCPSpeechToTextHook')
@mock.patch('airflow.gcp.operators.translate_speech.CloudSpeechToTextHook')
@mock.patch('airflow.gcp.operators.translate_speech.CloudTranslateHook')
def test_bad_recognition_response(self, mock_translate_hook, mock_speech_hook):
mock_speech_hook.return_value.recognize_speech.return_value = RecognizeResponse(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_core_to_contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook",
),
(
"airflow.gcp.hooks.speech_to_text.GCPSpeechToTextHook",
"airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook",
"airflow.contrib.hooks.gcp_speech_to_text_hook.GCPSpeechToTextHook",
),
(
Expand Down