You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2021/12/30 12:49:31 UTC
[airflow] branch main updated: Change download_video parameter to resourceName (#20528)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new a6e60ce Change download_video parameter to resourceName (#20528)
a6e60ce is described below
commit a6e60ce25d9f3d621a7b4089834ca5e50cd123db
Author: Mikhail Stepanov <mi...@gmail.com>
AuthorDate: Thu Dec 30 15:48:55 2021 +0300
Change download_video parameter to resourceName (#20528)
Added mock for xcom_push support. Restored old way to provide
resourse_name received from get_sdf_download_operation. Renamed
operation to operation_state for clarity.
---
.../providers/google/marketing_platform/hooks/display_video.py | 2 +-
.../google/marketing_platform/operators/display_video.py | 8 ++++++--
.../google/marketing_platform/hooks/test_display_video.py | 2 +-
.../google/marketing_platform/operators/test_display_video.py | 10 +++++++++-
4 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/airflow/providers/google/marketing_platform/hooks/display_video.py b/airflow/providers/google/marketing_platform/hooks/display_video.py
index e29938b..cca66c5 100644
--- a/airflow/providers/google/marketing_platform/hooks/display_video.py
+++ b/airflow/providers/google/marketing_platform/hooks/display_video.py
@@ -221,5 +221,5 @@ class GoogleDisplayVideo360Hook(GoogleBaseHook):
:param resource_name: of the media that is being downloaded.
:type resource_name: str
"""
- request = self.get_conn_to_display_video().media().download_media(resource_name=resource_name)
+ request = self.get_conn_to_display_video().media().download_media(resourceName=resource_name)
return request
diff --git a/airflow/providers/google/marketing_platform/operators/display_video.py b/airflow/providers/google/marketing_platform/operators/display_video.py
index 8c956c0..c6503b1 100644
--- a/airflow/providers/google/marketing_platform/operators/display_video.py
+++ b/airflow/providers/google/marketing_platform/operators/display_video.py
@@ -648,6 +648,10 @@ class GoogleDisplayVideo360CreateSDFDownloadTaskOperator(BaseOperator):
self.log.info("Creating operation for SDF download task...")
operation = hook.create_sdf_download_operation(body_request=self.body_request)
+ name = operation["name"]
+ self.xcom_push(context, key="name", value=name)
+ self.log.info("Created SDF operation with name: %s", name)
+
return operation
@@ -736,10 +740,10 @@ class GoogleDisplayVideo360SDFtoGCSOperator(BaseOperator):
)
self.log.info("Retrieving operation...")
- operation = hook.get_sdf_download_operation(operation_name=self.operation_name)
+ operation_state = hook.get_sdf_download_operation(operation_name=self.operation_name)
self.log.info("Creating file for upload...")
- media = hook.download_media(resource_name=operation)
+ media = hook.download_media(resource_name=operation_state)
self.log.info("Sending file to the Google Cloud Storage...")
with tempfile.NamedTemporaryFile() as temp_file:
diff --git a/tests/providers/google/marketing_platform/hooks/test_display_video.py b/tests/providers/google/marketing_platform/hooks/test_display_video.py
index 777d79c..18f171b 100644
--- a/tests/providers/google/marketing_platform/hooks/test_display_video.py
+++ b/tests/providers/google/marketing_platform/hooks/test_display_video.py
@@ -367,5 +367,5 @@ class TestGoogleDisplayVideo360Hook(TestCase):
self.hook.download_media(resource_name=resource_name)
get_conn_to_display_video.return_value.media.return_value.download_media.assert_called_once_with(
- resource_name=resource_name
+ resourceName=resource_name
)
diff --git a/tests/providers/google/marketing_platform/operators/test_display_video.py b/tests/providers/google/marketing_platform/operators/test_display_video.py
index 2f1842d..e7b21cd 100644
--- a/tests/providers/google/marketing_platform/operators/test_display_video.py
+++ b/tests/providers/google/marketing_platform/operators/test_display_video.py
@@ -355,6 +355,7 @@ class TestGoogleDisplayVideo360SDFtoGCSOperator(TestCase):
def test_execute(self, mock_temp, gcs_mock_hook, mock_hook):
operation_name = "operation_name"
operation = {"key": "value"}
+ operation = {"response": {"resourceName": "test_name"}}
gzip = False
# mock_hook.return_value.create_sdf_download_operation.return_value = response_name
@@ -415,14 +416,20 @@ class TestGoogleDisplayVideo360SDFtoGCSOperator(TestCase):
class TestGoogleDisplayVideo360CreateSDFDownloadTaskOperator(TestCase):
@mock.patch(
+ "airflow.providers.google.marketing_platform.operators."
+ "display_video.GoogleDisplayVideo360CreateSDFDownloadTaskOperator.xcom_push"
+ )
+ @mock.patch(
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360Hook"
)
- def test_execute(self, mock_hook):
+ def test_execute(self, mock_hook, xcom_mock):
body_request = {
"version": "1",
"id": "id",
"filter": {"id": []},
}
+ test_name = 'test_task'
+ mock_hook.return_value.create_sdf_download_operation.return_value = {"name": test_name}
op = GoogleDisplayVideo360CreateSDFDownloadTaskOperator(
body_request=body_request,
@@ -443,3 +450,4 @@ class TestGoogleDisplayVideo360CreateSDFDownloadTaskOperator(TestCase):
mock_hook.return_value.create_sdf_download_operation.assert_called_once_with(
body_request=body_request
)
+ xcom_mock.assert_called_once_with(None, key="name", value=test_name)