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 c4c60621adf Remove deprecated from google provider scheduled for
September 2025 except 30 September 2025. (#55683)
c4c60621adf is described below
commit c4c60621adf4f6e8cc6d2dde1e1bd8f526ac251e
Author: Nitochkin <[email protected]>
AuthorDate: Wed Sep 17 05:56:24 2025 +0200
Remove deprecated from google provider scheduled for September 2025 except
30 September 2025. (#55683)
Co-authored-by: Anton Nitochkin <[email protected]>
---
.../tests/unit/always/test_project_structure.py | 7 -
providers/google/docs/changelog.rst | 36 ++
.../operators/marketing_platform/display_video.rst | 127 -----
.../google/cloud/hooks/vertex_ai/auto_ml.py | 173 -------
.../marketing_platform/hooks/display_video.py | 150 ------
.../marketing_platform/operators/display_video.py | 510 ---------------------
.../marketing_platform/sensors/display_video.py | 69 +--
providers/google/tests/deprecations_ignore.yml | 17 -
.../marketing_platform/hooks/test_display_video.py | 290 ------------
.../operators/test_display_video.py | 320 -------------
.../sensors/test_display_video.py | 22 +-
11 files changed, 38 insertions(+), 1683 deletions(-)
diff --git a/airflow-core/tests/unit/always/test_project_structure.py
b/airflow-core/tests/unit/always/test_project_structure.py
index db604faa641..7ff2e92c5e3 100644
--- a/airflow-core/tests/unit/always/test_project_structure.py
+++ b/airflow-core/tests/unit/always/test_project_structure.py
@@ -494,13 +494,6 @@ class
TestGoogleProviderProjectStructure(ExampleCoverageTest, AssetsCoverageTest
"airflow.providers.google.cloud.operators.vertex_ai.endpoint_service.UpdateEndpointOperator",
"airflow.providers.google.cloud.operators.vertex_ai.batch_prediction_job.GetBatchPredictionJobOperator",
"airflow.providers.google.cloud.operators.datacatalog.CloudDataCatalogDeleteEntryOperator",
-
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateQueryOperator",
-
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360RunQueryOperator",
-
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360DeleteReportOperator",
-
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360DownloadReportV2Operator",
-
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360DownloadLineItemsOperator",
-
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360UploadLineItemsOperator",
-
"airflow.providers.google.marketing_platform.sensors.display_video.GoogleDisplayVideo360RunQuerySensor",
"airflow.providers.google.cloud.operators.vertex_ai.generative_model.DeleteExperimentRunOperator",
}
diff --git a/providers/google/docs/changelog.rst
b/providers/google/docs/changelog.rst
index 6d8c6398bd8..3dfe58799bf 100644
--- a/providers/google/docs/changelog.rst
+++ b/providers/google/docs/changelog.rst
@@ -27,6 +27,42 @@
Changelog
---------
+18.0.0
+......
+
+Breaking changes
+~~~~~~~~~~~~~~~~
+
+.. warning::
+ Deprecated classes, parameters and features have been removed from the
Google provider package.
+ The following breaking changes were introduced:
+
+* Operators
+
+ * ``Remove GoogleDisplayVideo360CreateQueryOperator use
airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateSDFDownloadTaskOperator
instead``
+ * ``Remove GoogleDisplayVideo360DeleteReportOperator. Reports were replaced
with SDF export task in v4 of API``
+ * ``Remove GoogleDisplayVideo360DownloadReportV2Operator use
airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360SDFtoGCSOperator
instead``
+ * ``Remove GoogleDisplayVideo360RunQueryOperator use
airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateSDFDownloadTaskOperator
instead``
+ * ``Remove GoogleDisplayVideo360DownloadLineItemsOperator use
airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateSDFDownloadTaskOperator
instead``
+ * ``Remove GoogleDisplayVideo360UploadLineItemsOperator use
airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360SDFtoGCSOperator
instead``
+
+* Hooks
+
+ * ``Remove GoogleDisplayVideo360Hook.get_conn use
airflow.providers.google.marketing_platform.hooks.display_video.get_conn_to_display_video
instead``
+ * ``Remove GoogleDisplayVideo360Hook.create_query use
airflow.providers.google.marketing_platform.hooks.display_video.create_sdf_download_operation
instead``
+ * ``Remove GoogleDisplayVideo360Hook.delete_query``
+ * ``Remove GoogleDisplayVideo360Hook.get_query use
airflow.providers.google.marketing_platform.hooks.display_video.get_sdf_download_operation
instead``
+ * ``Remove GoogleDisplayVideo360Hook.list_queries``
+ * ``Remove GoogleDisplayVideo360Hook.run_query use
airflow.providers.google.marketing_platform.hooks.display_video.create_sdf_download_operation
instead``
+ * ``Remove GoogleDisplayVideo360Hook.get_report``
+ * ``Remove GoogleDisplayVideo360Hook.upload_line_items use
airflow.providers.google.marketing_platform.hooks.display_video.create_sdf_download_operation
instead``
+ * ``Remove GoogleDisplayVideo360Hook.download_line_items use
airflow.providers.google.marketing_platform.hooks.display_video.download_media
instead``
+ * ``Remove AutoMLHook.create_auto_ml_text_training_job. AutoMLText API was
deprecated.``
+
+* Sensors
+
+ * ``Remove GoogleDisplayVideo360RunQuerySensor. Reports were replaced with
SDF export task in v4 of API.``
+
17.2.0
......
diff --git
a/providers/google/docs/operators/marketing_platform/display_video.rst
b/providers/google/docs/operators/marketing_platform/display_video.rst
index 82ee0079711..04cc9acbd04 100644
--- a/providers/google/docs/operators/marketing_platform/display_video.rst
+++ b/providers/google/docs/operators/marketing_platform/display_video.rst
@@ -25,133 +25,6 @@ Prerequisite Tasks
.. include:: /operators/_partials/prerequisite_tasks.rst
-.. _howto/operator:GoogleDisplayVideo360CreateReportOperator:
-
-Creating a Query
-^^^^^^^^^^^^^^^^
-
-.. warning::
- This operator is deprecated and will be removed after September 01, 2025.
Please use
-
:class:`~airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateSDFDownloadTaskOperator`.
-
-To create Display&Video 360 query use
-:class:`~airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateQueryOperator`.
-
-Use :ref:`Jinja templating <concepts:jinja-templating>` with
-:template-fields:`airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateQueryOperator`
-parameters which allow you to dynamically determine values. You can provide
body definition using ``
-.json`` file as this operator supports this template extension.
-The result is saved to :ref:`XCom <concepts:xcom>`, which allows the result to
be used by other operators.
-
-.. _howto/operator:GoogleDisplayVideo360RunQueryOperator:
-
-Run Query
-^^^^^^^^^
-
-.. warning::
- This operator is deprecated and will be removed after September 01, 2025.
Please use
-
:class:`~airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateSDFDownloadTaskOperator`.
-
-:class:`~airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360RunQueryOperator`.
-
-You can use :ref:`Jinja templating <concepts:jinja-templating>` with
-:template-fields:`airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360RunQueryOperator`
-parameters which allow you to dynamically determine values.
-The result is saved to :ref:`XCom <concepts:xcom>`, which allows the result to
be used by other operators.
-
-.. _howto/operator:GoogleDisplayVideo360DeleteReportOperator:
-
-Deleting a report
-^^^^^^^^^^^^^^^^^
-
-.. warning::
- This operator is deprecated and will be removed after September 01, 2025.
- Display & Video 360 API v2 has been deprecated and will be removed.
Reports were replaced with SDF
- export task in v4 of API.
-
-To delete Display&Video 360 report use
-:class:`~airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360DeleteReportOperator`.
-
-You can use :ref:`Jinja templating <concepts:jinja-templating>` with
-:template-fields:`airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360DeleteReportOperator`
-parameters which allow you to dynamically determine values.
-
-.. _howto/operator:GoogleDisplayVideo360RunQuerySensor:
-
-Waiting for query
-^^^^^^^^^^^^^^^^^
-
-.. warning::
- This sensor is deprecated and will be removed after September 01, 2025.
- Display & Video 360 API v2 has been deprecated and will be removed.
Queries were replaced with SDF
- export task in v4 of API.
-
-To wait for the report use
-:class:`~airflow.providers.google.marketing_platform.sensors.display_video.GoogleDisplayVideo360RunQuerySensor`.
-
-Use :ref:`Jinja templating <concepts:jinja-templating>` with
-:template-fields:`airflow.providers.google.marketing_platform.sensors.display_video.GoogleDisplayVideo360RunQuerySensor`
-parameters which allow you to dynamically determine values.
-
-.. _howto/operator:GoogleDisplayVideo360DownloadReportV2Operator:
-
-Downloading a report
-^^^^^^^^^^^^^^^^^^^^
-
-.. warning::
- This operator is deprecated and will be removed after September 01, 2025.
Please use
-
:class:`~airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360SDFtoGCSOperator`.
-
-To download a report to GCS bucket use
-:class:`~airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360DownloadReportV2Operator`.
-
-Use :ref:`Jinja templating <concepts:jinja-templating>` with
-:template-fields:`airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360DownloadReportV2Operator`
-parameters which allow you to dynamically determine values.
-
-.. _howto/operator:GoogleDisplayVideo360DownloadLineItemsOperator:
-
-Downloading Line Items
-^^^^^^^^^^^^^^^^^^^^^^
-
-The operator accepts body request:
-
-- consistent with `Google API
<https://developers.google.com/bid-manager/v1.1/lineitems/downloadlineitems>`_
::
-
- REQUEST_BODY = {
- "filterType": ADVERTISER_ID,
- "format": "CSV",
- "fileSpec": "EWF"
- }
-
-.. warning::
- This operator is deprecated and will be removed after September 01, 2025.
Please use
-
:class:`~airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateSDFDownloadTaskOperator`.
-
-To download line items in CSV format report use
-:class:`~airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360DownloadLineItemsOperator`.
-
-Use :ref:`Jinja templating <concepts:jinja-templating>` with
-:template-fields:`airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360DownloadLineItemsOperator`
-parameters which allow you to dynamically determine values.
-
-
-.. _howto/operator:GoogleDisplayVideo360UploadLineItemsOperator:
-
-Upload line items
-^^^^^^^^^^^^^^^^^
-
-.. warning::
- This operator is deprecated and will be removed after September 01, 2025.
Please use
-
:class:`~airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360SDFtoGCSOperator`.
-
-To run Display&Video 360 uploading line items use
-:class:`~airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360UploadLineItemsOperator`.
-
-Use :ref:`Jinja templating <concepts:jinja-templating>` with
-:template-fields:`airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360UploadLineItemsOperator`
-parameters which allow you to dynamically determine values.
-
.. _howto/operator:GoogleDisplayVideo360CreateSDFDownloadTaskOperator:
Create SDF download task
diff --git
a/providers/google/src/airflow/providers/google/cloud/hooks/vertex_ai/auto_ml.py
b/providers/google/src/airflow/providers/google/cloud/hooks/vertex_ai/auto_ml.py
index 9f8587e537c..96cb6bc392d 100644
---
a/providers/google/src/airflow/providers/google/cloud/hooks/vertex_ai/auto_ml.py
+++
b/providers/google/src/airflow/providers/google/cloud/hooks/vertex_ai/auto_ml.py
@@ -38,7 +38,6 @@ from google.cloud.aiplatform_v1 import JobServiceClient,
PipelineServiceClient
from airflow.exceptions import AirflowException,
AirflowProviderDeprecationWarning
from airflow.providers.google.common.consts import CLIENT_INFO
-from airflow.providers.google.common.deprecated import deprecated
from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
from airflow.providers.google.common.hooks.operation_helpers import
OperationHelper
@@ -951,178 +950,6 @@ class AutoMLHook(GoogleBaseHook, OperationHelper):
)
return model, training_id
- @GoogleBaseHook.fallback_to_default_project_id
- @deprecated(
- planned_removal_date="September 15, 2025",
- category=AirflowProviderDeprecationWarning,
- reason="Deprecation of AutoMLText API",
- )
- def create_auto_ml_text_training_job(
- self,
- project_id: str,
- region: str,
- display_name: str,
- dataset: datasets.TextDataset,
- prediction_type: str,
- multi_label: bool = False,
- sentiment_max: int = 10,
- labels: dict[str, str] | None = None,
- training_encryption_spec_key_name: str | None = None,
- model_encryption_spec_key_name: str | None = None,
- training_fraction_split: float | None = None,
- validation_fraction_split: float | None = None,
- test_fraction_split: float | None = None,
- training_filter_split: str | None = None,
- validation_filter_split: str | None = None,
- test_filter_split: str | None = None,
- model_display_name: str | None = None,
- model_labels: dict[str, str] | None = None,
- sync: bool = True,
- parent_model: str | None = None,
- is_default_version: bool | None = None,
- model_version_aliases: list[str] | None = None,
- model_version_description: str | None = None,
- ) -> tuple[models.Model | None, str]:
- """
- Create an AutoML Text Training Job.
-
- WARNING: Text creation API is deprecated since September 15, 2024
-
(https://cloud.google.com/vertex-ai/docs/tutorials/text-classification-automl/overview).
-
- :param project_id: Required. Project to run training in.
- :param region: Required. Location to run training in.
- :param display_name: Required. The user-defined name of this
TrainingPipeline.
- :param dataset: Required. The dataset within the same Project from
which data will be used to train
- the Model. The Dataset must use schema compatible with Model being
trained, and what is
- compatible should be described in the used TrainingPipeline's
[training_task_definition]
-
[google.cloud.aiplatform.v1beta1.TrainingPipeline.training_task_definition].
- :param prediction_type: The type of prediction the Model is to
produce, one of:
- "classification" - A classification model analyzes text data and
returns a list of categories
- that apply to the text found in the data. Vertex AI offers both
single-label and multi-label text
- classification models.
- "extraction" - An entity extraction model inspects text data for
known entities referenced in the
- data and labels those entities in the text.
- "sentiment" - A sentiment analysis model inspects text data and
identifies the prevailing
- emotional opinion within it, especially to determine a writer's
attitude as positive, negative,
- or neutral.
- :param parent_model: Optional. The resource name or model ID of an
existing model.
- The new model uploaded by this job will be a version of
`parent_model`.
- Only set this field when training a new version of an existing
model.
- :param is_default_version: Optional. When set to True, the newly
uploaded model version will
- automatically have alias "default" included. Subsequent uses of
- the model produced by this job without a version specified will
- use this "default" version.
- When set to False, the "default" alias will not be moved.
- Actions targeting the model version produced by this job will need
- to specifically reference this version by ID or alias.
- New model uploads, i.e. version 1, will always be "default"
aliased.
- :param model_version_aliases: Optional. User provided version aliases
so that the model version
- uploaded by this job can be referenced via alias instead of
- auto-generated version ID. A default version alias will be created
- for the first version of the model.
- The format is [a-z][a-zA-Z0-9-]{0,126}[a-z0-9]
- :param model_version_description: Optional. The description of the
model version
- being uploaded by this job.
- :param multi_label: Required and only applicable for text
classification task. If false, a
- single-label (multi-class) Model will be trained (i.e. assuming
that for each text snippet just
- up to one annotation may be applicable). If true, a multi-label
Model will be trained (i.e.
- assuming that for each text snippet multiple annotations may be
applicable).
- :param sentiment_max: Required and only applicable for sentiment task.
A sentiment is expressed as an
- integer ordinal, where higher value means a more positive
sentiment. The range of sentiments that
- will be used is between 0 and sentimentMax (inclusive on both
ends), and all the values in the
- range must be represented in the dataset before a model can be
created. Only the Annotations with
- this sentimentMax will be used for training. sentimentMax value
must be between 1 and 10
- (inclusive).
- :param labels: Optional. The labels with user-defined metadata to
organize TrainingPipelines. Label
- keys and values can be no longer than 64 characters (Unicode
codepoints), can only contain
- lowercase letters, numeric characters, underscores and dashes.
International characters are
- allowed. See https://goo.gl/xmQnxf for more information and
examples of labels.
- :param training_encryption_spec_key_name: Optional. The Cloud KMS
resource identifier of the customer
- managed encryption key used to protect the training pipeline. Has
the form:
-
``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``.
- The key needs to be in the same region as where the compute
resource is created.
- If set, this TrainingPipeline will be secured by this key.
- Note: Model trained by this TrainingPipeline is also secured by
this key if ``model_to_upload``
- is not set separately.
- :param model_encryption_spec_key_name: Optional. The Cloud KMS
resource identifier of the customer
- managed encryption key used to protect the model. Has the form:
-
``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``.
- The key needs to be in the same region as where the compute
resource is created.
- If set, the trained Model will be secured by this key.
- :param training_fraction_split: Optional. The fraction of the input
data that is to be used to train
- the Model. This is ignored if Dataset is not provided.
- :param validation_fraction_split: Optional. The fraction of the input
data that is to be used to
- validate the Model. This is ignored if Dataset is not provided.
- :param test_fraction_split: Optional. The fraction of the input data
that is to be used to evaluate
- the Model. This is ignored if Dataset is not provided.
- :param training_filter_split: Optional. A filter on DataItems of the
Dataset. DataItems that match
- this filter are used to train the Model. A filter with same syntax
as the one used in
- DatasetService.ListDataItems may be used. If a single DataItem is
matched by more than one of the
- FilterSplit filters, then it is assigned to the first set that
applies to it in the training,
- validation, test order. This is ignored if Dataset is not provided.
- :param validation_filter_split: Optional. A filter on DataItems of the
Dataset. DataItems that match
- this filter are used to validate the Model. A filter with same
syntax as the one used in
- DatasetService.ListDataItems may be used. If a single DataItem is
matched by more than one of the
- FilterSplit filters, then it is assigned to the first set that
applies to it in the training,
- validation, test order. This is ignored if Dataset is not provided.
- :param test_filter_split: Optional. A filter on DataItems of the
Dataset. DataItems that match this
- filter are used to test the Model. A filter with same syntax as
the one used in
- DatasetService.ListDataItems may be used. If a single DataItem is
matched by more than one of the
- FilterSplit filters, then it is assigned to the first set that
applies to it in the training,
- validation, test order. This is ignored if Dataset is not provided.
- :param model_display_name: Optional. The display name of the managed
Vertex AI Model. The name can be
- up to 128 characters long and can consist of any UTF-8 characters.
- If not provided upon creation, the job's display_name is used.
- :param model_labels: Optional. The labels with user-defined metadata
to organize your Models. Label
- keys and values can be no longer than 64 characters (Unicode
codepoints), can only contain
- lowercase letters, numeric characters, underscores and dashes.
International characters are
- allowed. See https://goo.gl/xmQnxf for more information and
examples of labels.
- :param sync: Whether to execute this method synchronously. If False,
this method will be executed in
- concurrent Future and any downstream object will be immediately
returned and synced when the
- Future has completed.
- """
- self._job = AutoMLTextTrainingJob(
- display_name=display_name,
- prediction_type=prediction_type,
- multi_label=multi_label,
- sentiment_max=sentiment_max,
- project=project_id,
- location=region,
- credentials=self.get_credentials(),
- labels=labels,
-
training_encryption_spec_key_name=training_encryption_spec_key_name,
- model_encryption_spec_key_name=model_encryption_spec_key_name,
- )
-
- if not self._job:
- raise AirflowException("AutoMLTextTrainingJob was not created")
-
- model = self._job.run(
- dataset=dataset,
- training_fraction_split=training_fraction_split,
- validation_fraction_split=validation_fraction_split,
- test_fraction_split=test_fraction_split,
- training_filter_split=training_filter_split,
- validation_filter_split=validation_filter_split,
- test_filter_split=test_filter_split,
- model_display_name=model_display_name,
- model_labels=model_labels,
- sync=sync,
- parent_model=parent_model,
- is_default_version=is_default_version,
- model_version_aliases=model_version_aliases,
- model_version_description=model_version_description,
- )
- training_id = self.extract_training_id(self._job.resource_name)
- if model:
- model.wait()
- else:
- self.log.warning(
- "Training did not produce a Managed Model returning None.
AutoML Text Training "
- "Pipeline is not configured to upload a Model."
- )
- return model, training_id
-
@GoogleBaseHook.fallback_to_default_project_id
def create_auto_ml_video_training_job(
self,
diff --git
a/providers/google/src/airflow/providers/google/marketing_platform/hooks/display_video.py
b/providers/google/src/airflow/providers/google/marketing_platform/hooks/display_video.py
index 59946f9197b..4fa4278cb34 100644
---
a/providers/google/src/airflow/providers/google/marketing_platform/hooks/display_video.py
+++
b/providers/google/src/airflow/providers/google/marketing_platform/hooks/display_video.py
@@ -24,8 +24,6 @@ from typing import Any
from googleapiclient.discovery import Resource, build
-from airflow.exceptions import AirflowProviderDeprecationWarning
-from airflow.providers.google.common.deprecated import deprecated
from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
@@ -48,23 +46,6 @@ class GoogleDisplayVideo360Hook(GoogleBaseHook):
)
self.api_version = api_version
- @deprecated(
- planned_removal_date="September 01, 2025",
-
use_instead="airflow.providers.google.marketing_platform.hooks.display_video.get_conn_to_display_video",
- category=AirflowProviderDeprecationWarning,
- )
- def get_conn(self) -> Resource:
- """Retrieve connection to DisplayVideo."""
- if not self._conn:
- http_authorized = self._authorize()
- self._conn = build(
- "doubleclickbidmanager",
- self.api_version,
- http=http_authorized,
- cache_discovery=False,
- )
- return self._conn
-
def get_conn_to_display_video(self) -> Resource:
"""Retrieve connection to DisplayVideo."""
if not self._conn:
@@ -96,137 +77,6 @@ class GoogleDisplayVideo360Hook(GoogleBaseHook):
"""
return [f"gdbm-{partner_id}/entity/{{{{ ds_nodash
}}}}.*.{entity_type}.json"]
- @deprecated(
- planned_removal_date="September 01, 2025",
-
use_instead="airflow.providers.google.marketing_platform.hooks.display_video.create_sdf_download_operation",
- category=AirflowProviderDeprecationWarning,
- )
- def create_query(self, query: dict[str, Any]) -> dict:
- """
- Create a query.
-
- :param query: Query object to be passed to request body.
- """
- response =
self.get_conn().queries().create(body=query).execute(num_retries=self.num_retries)
- return response
-
- @deprecated(
- planned_removal_date="September 01, 2025",
- category=AirflowProviderDeprecationWarning,
- )
- def delete_query(self, query_id: str) -> None:
- """
- Delete a stored query as well as the associated stored reports.
-
- :param query_id: Query ID to delete.
- """
-
self.get_conn().queries().delete(queryId=query_id).execute(num_retries=self.num_retries)
-
- @deprecated(
- planned_removal_date="September 01, 2025",
-
use_instead="airflow.providers.google.marketing_platform.hooks.display_video.get_sdf_download_operation",
- category=AirflowProviderDeprecationWarning,
- )
- def get_query(self, query_id: str) -> dict:
- """
- Retrieve a stored query.
-
- :param query_id: Query ID to retrieve.
- """
- response =
self.get_conn().queries().get(queryId=query_id).execute(num_retries=self.num_retries)
- return response
-
- @deprecated(
- planned_removal_date="September 01, 2025",
- category=AirflowProviderDeprecationWarning,
- )
- def list_queries(self) -> list[dict]:
- """Retrieve stored queries."""
- response =
self.get_conn().queries().list().execute(num_retries=self.num_retries)
- return response.get("queries", [])
-
- @deprecated(
- planned_removal_date="September 01, 2025",
-
use_instead="airflow.providers.google.marketing_platform.hooks.display_video.create_sdf_download_operation",
- category=AirflowProviderDeprecationWarning,
- )
- def run_query(self, query_id: str, params: dict[str, Any] | None) -> dict:
- """
- Run a stored query to generate a report.
-
- :param query_id: Query ID to run.
- :param params: Parameters for the report.
- """
- return (
- self.get_conn().queries().run(queryId=query_id,
body=params).execute(num_retries=self.num_retries)
- )
-
- @deprecated(
- planned_removal_date="September 01, 2025",
- category=AirflowProviderDeprecationWarning,
- )
- def get_report(self, query_id: str, report_id: str) -> dict:
- """
- Retrieve a report.
-
- :param query_id: Query ID for which report was generated.
- :param report_id: Report ID to retrieve.
- """
- return (
- self.get_conn()
- .queries()
- .reports()
- .get(queryId=query_id, reportId=report_id)
- .execute(num_retries=self.num_retries)
- )
-
- @deprecated(
- planned_removal_date="September 01, 2025",
-
use_instead="airflow.providers.google.marketing_platform.hooks.display_video.create_sdf_download_operation",
- category=AirflowProviderDeprecationWarning,
- )
- def upload_line_items(self, line_items: Any) -> list[dict[str, Any]]:
- """
- Upload line items in CSV format.
-
- :param line_items: downloaded data from GCS and passed to the body
request
- :return: response body.
- """
- request_body = {
- "lineItems": line_items,
- "dryRun": False,
- "format": "CSV",
- }
-
- response = (
- self.get_conn()
- .lineitems()
- .uploadlineitems(body=request_body)
- .execute(num_retries=self.num_retries)
- )
- return response
-
- @deprecated(
- planned_removal_date="September 01, 2025",
-
use_instead="airflow.providers.google.marketing_platform.hooks.display_video.download_media",
- category=AirflowProviderDeprecationWarning,
- )
- def download_line_items(self, request_body: dict[str, Any]) -> list[Any]:
- """
- Retrieve line items in CSV format.
-
- :param request_body: dictionary with parameters that should be passed
into.
- More information about it can be found here:
-
https://developers.google.com/bid-manager/v1.1/lineitems/downloadlineitems
- """
- response = (
- self.get_conn()
- .lineitems()
- .downloadlineitems(body=request_body)
- .execute(num_retries=self.num_retries)
- )
- return response["lineItems"]
-
def create_sdf_download_operation(self, body_request: dict[str, Any]) ->
dict[str, Any]:
"""
Create an SDF Download Task and Returns an Operation.
diff --git
a/providers/google/src/airflow/providers/google/marketing_platform/operators/display_video.py
b/providers/google/src/airflow/providers/google/marketing_platform/operators/display_video.py
index ec87868a36d..ad768442227 100644
---
a/providers/google/src/airflow/providers/google/marketing_platform/operators/display_video.py
+++
b/providers/google/src/airflow/providers/google/marketing_platform/operators/display_video.py
@@ -19,20 +19,13 @@
from __future__ import annotations
-import csv
-import json
import os
-import shutil
import tempfile
-import urllib.request
import zipfile
from collections.abc import Sequence
from typing import TYPE_CHECKING, Any
-from urllib.parse import urlsplit
-from airflow.exceptions import AirflowException,
AirflowProviderDeprecationWarning
from airflow.providers.google.cloud.hooks.gcs import GCSHook
-from airflow.providers.google.common.deprecated import deprecated
from airflow.providers.google.marketing_platform.hooks.display_video import
GoogleDisplayVideo360Hook
from airflow.providers.google.version_compat import BaseOperator
@@ -40,509 +33,6 @@ if TYPE_CHECKING:
from airflow.utils.context import Context
-@deprecated(
- planned_removal_date="September 01, 2025",
-
use_instead="airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateSDFDownloadTaskOperator",
- reason="Display & Video 360 API v2 has been deprecated and will be
removed.",
- category=AirflowProviderDeprecationWarning,
-)
-class GoogleDisplayVideo360CreateQueryOperator(BaseOperator):
- """
- Creates a query.
-
- .. seealso::
- For more information on how to use this operator, take a look at the
guide:
- ``GoogleDisplayVideo360CreateQueryOperator``
-
- .. seealso::
- Check also the official API docs:
- `https://developers.google.com/bid-manager/v2/queries/create`
-
- :param body: Report object passed to the request's body as described here:
- https://developers.google.com/bid-manager/v2/queries#Query
- :param api_version: The version of the api that will be requested for
example 'v3'.
- :param gcp_conn_id: The connection ID to use when fetching connection info.
- :param impersonation_chain: Optional service account to impersonate using
short-term
- credentials, or chained list of accounts required to get the
access_token
- of the last account in the list, which will be impersonated in the
request.
- If set as a string, the account must grant the originating account
- the Service Account Token Creator IAM role.
- If set as a sequence, the identities from the list must grant
- Service Account Token Creator IAM role to the directly preceding
identity, with the first
- account from the list granting this role to the originating account
(templated).
- """
-
- template_fields: Sequence[str] = (
- "body",
- "impersonation_chain",
- )
- template_ext: Sequence[str] = (".json",)
-
- def __init__(
- self,
- *,
- body: dict[str, Any],
- api_version: str = "v2",
- gcp_conn_id: str = "google_cloud_default",
- impersonation_chain: str | Sequence[str] | None = None,
- **kwargs,
- ) -> None:
- super().__init__(**kwargs)
- self.body = body
- self.api_version = api_version
- self.gcp_conn_id = gcp_conn_id
- self.impersonation_chain = impersonation_chain
-
- def prepare_template(self) -> None:
- # If .json is passed then we have to read the file
- if isinstance(self.body, str) and self.body.endswith(".json"):
- with open(self.body) as file:
- self.body = json.load(file)
-
- def execute(self, context: Context) -> dict:
- hook = GoogleDisplayVideo360Hook(
- gcp_conn_id=self.gcp_conn_id,
- api_version=self.api_version,
- impersonation_chain=self.impersonation_chain,
- )
- self.log.info("Creating Display & Video 360 query.")
- response = hook.create_query(query=self.body)
- query_id = response["queryId"]
- context["task_instance"].xcom_push(key="query_id", value=query_id)
- self.log.info("Created query with ID: %s", query_id)
- return response
-
-
-@deprecated(
- planned_removal_date="September 01, 2025",
- reason="Display & Video 360 API v2 has been deprecated and will be
removed. "
- "Reports were replaced with SDF export task in v4 of API.",
- category=AirflowProviderDeprecationWarning,
-)
-class GoogleDisplayVideo360DeleteReportOperator(BaseOperator):
- """
- Deletes a stored query as well as the associated stored reports.
-
- .. seealso::
- For more information on how to use this operator, take a look at the
guide:
- :ref:`howto/operator:GoogleDisplayVideo360DeleteReportOperator`
-
- .. seealso::
- Check also the official API docs:
- `https://developers.google.com/bid-manager/v2/queries/delete`
-
- :param report_id: Report ID to delete.
- :param report_name: Name of the report to delete.
- :param api_version: The version of the api that will be requested for
example 'v3'.
- :param gcp_conn_id: The connection ID to use when fetching connection info.
- :param impersonation_chain: Optional service account to impersonate using
short-term
- credentials, or chained list of accounts required to get the
access_token
- of the last account in the list, which will be impersonated in the
request.
- If set as a string, the account must grant the originating account
- the Service Account Token Creator IAM role.
- If set as a sequence, the identities from the list must grant
- Service Account Token Creator IAM role to the directly preceding
identity, with first
- account from the list granting this role to the originating account
(templated).
- """
-
- template_fields: Sequence[str] = (
- "report_id",
- "impersonation_chain",
- )
-
- def __init__(
- self,
- *,
- report_id: str | None = None,
- report_name: str | None = None,
- api_version: str = "v2",
- gcp_conn_id: str = "google_cloud_default",
- impersonation_chain: str | Sequence[str] | None = None,
- **kwargs,
- ) -> None:
- super().__init__(**kwargs)
- self.report_id = report_id
- self.report_name = report_name
- self.api_version = api_version
- self.gcp_conn_id = gcp_conn_id
- self.impersonation_chain = impersonation_chain
-
- if report_name and report_id:
- raise AirflowException("Use only one value - `report_name` or
`report_id`.")
-
- if not (report_name or report_id):
- raise AirflowException("Provide one of the values: `report_name`
or `report_id`.")
-
- def execute(self, context: Context) -> None:
- hook = GoogleDisplayVideo360Hook(
- gcp_conn_id=self.gcp_conn_id,
- api_version=self.api_version,
- impersonation_chain=self.impersonation_chain,
- )
- if self.report_id:
- reports_ids_to_delete = [self.report_id]
- else:
- reports = hook.list_queries()
- reports_ids_to_delete = [
- report["queryId"] for report in reports if
report["metadata"]["title"] == self.report_name
- ]
-
- for report_id in reports_ids_to_delete:
- self.log.info("Deleting report with id: %s", report_id)
- hook.delete_query(query_id=report_id)
- self.log.info("Report deleted.")
-
-
-@deprecated(
- planned_removal_date="September 01, 2025",
-
use_instead="airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360SDFtoGCSOperator",
- reason="Display & Video 360 API v2 has been deprecated and will be
removed.",
- category=AirflowProviderDeprecationWarning,
-)
-class GoogleDisplayVideo360DownloadReportV2Operator(BaseOperator):
- """
- Retrieves a stored query.
-
- .. seealso::
- For more information on how to use this operator, take a look at the
guide:
- :ref:`howto/operator:GoogleDisplayVideo360DownloadReportV2Operator`
-
- .. seealso::
- Check also the official API docs:
- `https://developers.google.com/bid-manager/v2/queries/get`
-
- :param report_id: Report ID to retrieve.
- :param bucket_name: The bucket to upload to.
- :param report_name: The report name to set when uploading the local file.
- :param chunk_size: File will be downloaded in chunks of this many bytes.
- :param gzip: Option to compress local file or file data for upload
- :param api_version: The version of the api that will be requested for
example 'v3'.
- :param gcp_conn_id: The connection ID to use when fetching connection info.
- :param impersonation_chain: Optional service account to impersonate using
short-term
- credentials, or chained list of accounts required to get the
access_token
- of the last account in the list, which will be impersonated in the
request.
- If set as a string, the account must grant the originating account
- the Service Account Token Creator IAM role.
- If set as a sequence, the identities from the list must grant
- Service Account Token Creator IAM role to the directly preceding
identity, with first
- account from the list granting this role to the originating account
(templated).
- """
-
- template_fields: Sequence[str] = (
- "query_id",
- "report_id",
- "bucket_name",
- "report_name",
- "impersonation_chain",
- )
-
- def __init__(
- self,
- *,
- query_id: str,
- report_id: str,
- bucket_name: str,
- report_name: str | None = None,
- gzip: bool = True,
- chunk_size: int = 10 * 1024 * 1024,
- api_version: str = "v2",
- gcp_conn_id: str = "google_cloud_default",
- impersonation_chain: str | Sequence[str] | None = None,
- **kwargs,
- ) -> None:
- super().__init__(**kwargs)
- self.query_id = query_id
- self.report_id = report_id
- self.chunk_size = chunk_size
- self.gzip = gzip
- self.bucket_name = bucket_name
- self.report_name = report_name
- self.api_version = api_version
- self.gcp_conn_id = gcp_conn_id
- self.impersonation_chain = impersonation_chain
-
- def _resolve_file_name(self, name: str) -> str:
- new_name = name if name.endswith(".csv") else f"{name}.csv"
- new_name = f"{new_name}.gz" if self.gzip else new_name
- return new_name
-
- @staticmethod
- def _set_bucket_name(name: str) -> str:
- bucket = name if not name.startswith("gs://") else name[5:]
- return bucket.strip("/")
-
- def execute(self, context: Context):
- hook = GoogleDisplayVideo360Hook(
- gcp_conn_id=self.gcp_conn_id,
- api_version=self.api_version,
- impersonation_chain=self.impersonation_chain,
- )
- gcs_hook = GCSHook(
- gcp_conn_id=self.gcp_conn_id,
- impersonation_chain=self.impersonation_chain,
- )
-
- resource = hook.get_report(query_id=self.query_id,
report_id=self.report_id)
- status = resource.get("metadata", {}).get("status", {}).get("state")
- if resource and status not in ["DONE", "FAILED"]:
- raise AirflowException(f"Report {self.report_id} for query
{self.query_id} is still running")
-
- # If no custom report_name provided, use DV360 name
- file_url = resource["metadata"]["googleCloudStoragePath"]
- if urllib.parse.urlparse(file_url).scheme == "file":
- raise AirflowException("Accessing local file is not allowed in
this operator")
- report_name = self.report_name or
urlsplit(file_url).path.split("/")[-1]
- report_name = self._resolve_file_name(report_name)
-
- # Download the report
- self.log.info("Starting downloading report %s", self.report_id)
- with tempfile.NamedTemporaryFile(delete=False) as temp_file:
- with urllib.request.urlopen(file_url) as response: # nosec
- shutil.copyfileobj(response, temp_file, length=self.chunk_size)
-
- temp_file.flush()
- # Upload the local file to bucket
- bucket_name = self._set_bucket_name(self.bucket_name)
- gcs_hook.upload(
- bucket_name=bucket_name,
- object_name=report_name,
- gzip=self.gzip,
- filename=temp_file.name,
- mime_type="text/csv",
- )
- self.log.info(
- "Report %s was saved in bucket %s as %s.",
- self.report_id,
- self.bucket_name,
- report_name,
- )
- context["task_instance"].xcom_push(key="report_name",
value=report_name)
-
-
-@deprecated(
- planned_removal_date="September 01, 2025",
-
use_instead="airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateSDFDownloadTaskOperator",
- reason="Display & Video 360 API v2 has been deprecated and will be
removed.",
- category=AirflowProviderDeprecationWarning,
-)
-class GoogleDisplayVideo360RunQueryOperator(BaseOperator):
- """
- Runs a stored query to generate a report.
-
- .. seealso::
- For more information on how to use this operator, take a look at the
guide:
- :ref:`howto/operator:GoogleDisplayVideo360RunQueryOperator`
-
- .. seealso::
- Check also the official API docs:
- `https://developers.google.com/bid-manager/v2/queries/run`
-
- :param report_id: Report ID to run.
- :param parameters: Parameters for running a report as described here:
- https://developers.google.com/bid-manager/v2/queries/run
- :param api_version: The version of the api that will be requested for
example 'v3'.
- :param gcp_conn_id: The connection ID to use when fetching connection info.
- :param impersonation_chain: Optional service account to impersonate using
short-term
- credentials, or chained list of accounts required to get the
access_token
- of the last account in the list, which will be impersonated in the
request.
- If set as a string, the account must grant the originating account
- the Service Account Token Creator IAM role.
- If set as a sequence, the identities from the list must grant
- Service Account Token Creator IAM role to the directly preceding
identity, with first
- account from the list granting this role to the originating account
(templated).
- """
-
- template_fields: Sequence[str] = (
- "query_id",
- "parameters",
- "impersonation_chain",
- )
-
- def __init__(
- self,
- *,
- query_id: str,
- parameters: dict[str, Any] | None = None,
- api_version: str = "v2",
- gcp_conn_id: str = "google_cloud_default",
- impersonation_chain: str | Sequence[str] | None = None,
- **kwargs,
- ) -> None:
- super().__init__(**kwargs)
- self.query_id = query_id
- self.api_version = api_version
- self.gcp_conn_id = gcp_conn_id
- self.parameters = parameters
- self.impersonation_chain = impersonation_chain
-
- def execute(self, context: Context) -> dict:
- hook = GoogleDisplayVideo360Hook(
- gcp_conn_id=self.gcp_conn_id,
- api_version=self.api_version,
- impersonation_chain=self.impersonation_chain,
- )
- self.log.info(
- "Running query %s with the following parameters:\n %s",
- self.query_id,
- self.parameters,
- )
- response = hook.run_query(query_id=self.query_id,
params=self.parameters)
- context["task_instance"].xcom_push(key="query_id",
value=response["key"]["queryId"])
- context["task_instance"].xcom_push(key="report_id",
value=response["key"]["reportId"])
- return response
-
-
-@deprecated(
- planned_removal_date="September 01, 2025",
-
use_instead="airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360CreateSDFDownloadTaskOperator",
- reason="Display & Video 360 API v2 has been deprecated and will be
removed.",
- category=AirflowProviderDeprecationWarning,
-)
-class GoogleDisplayVideo360DownloadLineItemsOperator(BaseOperator):
- """
- Retrieves line items in CSV format.
-
- .. seealso::
- For more information on how to use this operator, take a look at the
guide:
- :ref:`howto/operator:GoogleDisplayVideo360DownloadLineItemsOperator`
-
- .. seealso::
- Check also the official API docs:
-
`https://developers.google.com/bid-manager/v1.1/lineitems/downloadlineitems`
-
- :param request_body: dictionary with parameters that should be passed into.
- More information about it can be found here:
-
https://developers.google.com/bid-manager/v1.1/lineitems/downloadlineitems
- """
-
- template_fields: Sequence[str] = (
- "request_body",
- "bucket_name",
- "object_name",
- "impersonation_chain",
- )
-
- def __init__(
- self,
- *,
- request_body: dict[str, Any],
- bucket_name: str,
- object_name: str,
- gzip: bool = False,
- api_version: str = "v1.1",
- gcp_conn_id: str = "google_cloud_default",
- impersonation_chain: str | Sequence[str] | None = None,
- **kwargs,
- ) -> None:
- super().__init__(**kwargs)
- self.request_body = request_body
- self.object_name = object_name
- self.bucket_name = bucket_name
- self.gzip = gzip
- self.api_version = api_version
- self.gcp_conn_id = gcp_conn_id
- self.impersonation_chain = impersonation_chain
-
- def execute(self, context: Context) -> str:
- gcs_hook = GCSHook(
- gcp_conn_id=self.gcp_conn_id,
- impersonation_chain=self.impersonation_chain,
- )
- hook = GoogleDisplayVideo360Hook(
- gcp_conn_id=self.gcp_conn_id,
- api_version=self.api_version,
- impersonation_chain=self.impersonation_chain,
- )
-
- self.log.info("Retrieving report...")
- content: list[str] =
hook.download_line_items(request_body=self.request_body)
-
- with tempfile.NamedTemporaryFile("w+") as temp_file:
- writer = csv.writer(temp_file)
- writer.writerows(content)
- temp_file.flush()
- gcs_hook.upload(
- bucket_name=self.bucket_name,
- object_name=self.object_name,
- filename=temp_file.name,
- mime_type="text/csv",
- gzip=self.gzip,
- )
- return f"{self.bucket_name}/{self.object_name}"
-
-
-@deprecated(
- planned_removal_date="September 01, 2025",
-
use_instead="airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360SDFtoGCSOperator",
- reason="Display & Video 360 API v2 has been deprecated and will be
removed.",
- category=AirflowProviderDeprecationWarning,
-)
-class GoogleDisplayVideo360UploadLineItemsOperator(BaseOperator):
- """
- Uploads line items in CSV format.
-
- .. seealso::
- For more information on how to use this operator, take a look at the
guide:
- :ref:`howto/operator:GoogleDisplayVideo360UploadLineItemsOperator`
-
- .. seealso::
- Check also the official API docs:
-
`https://developers.google.com/bid-manager/v1.1/lineitems/uploadlineitems`
-
- :param request_body: request to upload line items.
- :param bucket_name: The bucket form data is downloaded.
- :param object_name: The object to fetch.
- :param filename: The filename to fetch.
- :param dry_run: Upload status without actually persisting the line items.
- """
-
- template_fields: Sequence[str] = (
- "bucket_name",
- "object_name",
- "impersonation_chain",
- )
-
- def __init__(
- self,
- *,
- bucket_name: str,
- object_name: str,
- api_version: str = "v1.1",
- gcp_conn_id: str = "google_cloud_default",
- impersonation_chain: str | Sequence[str] | None = None,
- **kwargs,
- ) -> None:
- super().__init__(**kwargs)
- self.bucket_name = bucket_name
- self.object_name = object_name
- self.api_version = api_version
- self.gcp_conn_id = gcp_conn_id
- self.impersonation_chain = impersonation_chain
-
- def execute(self, context: Context) -> None:
- gcs_hook = GCSHook(
- gcp_conn_id=self.gcp_conn_id,
- impersonation_chain=self.impersonation_chain,
- )
- hook = GoogleDisplayVideo360Hook(
- gcp_conn_id=self.gcp_conn_id,
- api_version=self.api_version,
- impersonation_chain=self.impersonation_chain,
- )
-
- self.log.info("Uploading file %s...")
- # Saving file in the temporary directory,
- # downloaded file from the GCS could be a 1GB size or even more
- with tempfile.NamedTemporaryFile("w+") as f:
- line_items = gcs_hook.download(
- bucket_name=self.bucket_name,
- object_name=self.object_name,
- filename=f.name,
- )
- f.flush()
- hook.upload_line_items(line_items=line_items)
-
-
class GoogleDisplayVideo360CreateSDFDownloadTaskOperator(BaseOperator):
"""
Creates an SDF operation task.
diff --git
a/providers/google/src/airflow/providers/google/marketing_platform/sensors/display_video.py
b/providers/google/src/airflow/providers/google/marketing_platform/sensors/display_video.py
index 5f0ab4d6d74..a6b6eaf5f7e 100644
---
a/providers/google/src/airflow/providers/google/marketing_platform/sensors/display_video.py
+++
b/providers/google/src/airflow/providers/google/marketing_platform/sensors/display_video.py
@@ -21,8 +21,7 @@ from __future__ import annotations
from collections.abc import Sequence
from typing import TYPE_CHECKING
-from airflow.exceptions import AirflowException,
AirflowProviderDeprecationWarning
-from airflow.providers.google.common.deprecated import deprecated
+from airflow.exceptions import AirflowException
from airflow.providers.google.marketing_platform.hooks.display_video import
GoogleDisplayVideo360Hook
from airflow.providers.google.version_compat import AIRFLOW_V_3_0_PLUS
@@ -94,69 +93,3 @@ class
GoogleDisplayVideo360GetSDFDownloadOperationSensor(BaseSensorOperator):
if operation and operation.get("done"):
return True
return False
-
-
-@deprecated(
- planned_removal_date="September 01, 2025",
- reason="Display & Video 360 API v2 has been deprecated and will be
removed. "
- "Reports were replaced with SDF export task in v4 of API.",
- category=AirflowProviderDeprecationWarning,
-)
-class GoogleDisplayVideo360RunQuerySensor(BaseSensorOperator):
- """
- Sensor for detecting the completion of DV360 reports for API v2.
-
- .. seealso::
- For more information on how to use this operator, take a look at the
guide:
- :ref:`howto/operator:GoogleDisplayVideo360RunQuerySensor`
-
- :param query_id: Query ID for which report was generated
- :param report_id: Report ID for which you want to wait
- :param api_version: The version of the api that will be requested for
example 'v3'.
- :param gcp_conn_id: The connection ID to use when fetching connection info.
- :param impersonation_chain: Optional service account to impersonate using
short-term
- credentials, or chained list of accounts required to get the
access_token
- of the last account in the list, which will be impersonated in the
request.
- If set as a string, the account must grant the originating account
- the Service Account Token Creator IAM role.
- If set as a sequence, the identities from the list must grant
- Service Account Token Creator IAM role to the directly preceding
identity, with first
- account from the list granting this role to the originating account
(templated).
- """
-
- template_fields: Sequence[str] = (
- "query_id",
- "report_id",
- "impersonation_chain",
- )
-
- def __init__(
- self,
- *,
- query_id: str,
- report_id: str,
- api_version: str = "v2",
- gcp_conn_id: str = "google_cloud_default",
- impersonation_chain: str | Sequence[str] | None = None,
- **kwargs,
- ) -> None:
- super().__init__(**kwargs)
- self.query_id = query_id
- self.report_id = report_id
- self.api_version = api_version
- self.gcp_conn_id = gcp_conn_id
- self.impersonation_chain = impersonation_chain
-
- def poke(self, context: Context) -> bool:
- hook = GoogleDisplayVideo360Hook(
- gcp_conn_id=self.gcp_conn_id,
- api_version=self.api_version,
- impersonation_chain=self.impersonation_chain,
- )
-
- response = hook.get_report(query_id=self.query_id,
report_id=self.report_id)
- status = response.get("metadata", {}).get("status", {}).get("state")
- self.log.info("STATUS OF THE REPORT %s FOR QUERY %s: %s",
self.report_id, self.query_id, status)
- if response and status in ["DONE", "FAILED"]:
- return True
- return False
diff --git a/providers/google/tests/deprecations_ignore.yml
b/providers/google/tests/deprecations_ignore.yml
index 58a86951e0b..66a1508a6ec 100644
--- a/providers/google/tests/deprecations_ignore.yml
+++ b/providers/google/tests/deprecations_ignore.yml
@@ -57,23 +57,6 @@
-
providers/google/tests/unit/google/cloud/hooks/test_bigquery.py::TestTimePartitioningInRunJob::test_run_query_with_arg
-
providers/google/tests/unit/google/cloud/hooks/test_bigquery.py::TestTimePartitioningInRunJob::test_run_with_auto_detect
-
providers/google/tests/unit/google/cloud/hooks/test_gcs.py::TestGCSHook::test_list__error_match_glob_and_invalid_delimiter
--
providers/google/tests/unit/google/cloud/hooks/test_display_video.py::TestGoogleDisplayVideo360Hook::test_gen_conn
--
providers/google/tests/unit/google/cloud/hooks/test_display_video.py::TestGoogleDisplayVideo360Hook::create_query
--
providers/google/tests/unit/google/cloud/hooks/test_display_video.py::TestGoogleDisplayVideo360Hook::delete_query
--
providers/google/tests/unit/google/cloud/hooks/test_display_video.py::TestGoogleDisplayVideo360Hook::get_query
--
providers/google/tests/unit/google/cloud/hooks/test_display_video.py::TestGoogleDisplayVideo360Hook::list_queries
--
providers/google/tests/unit/google/cloud/hooks/test_display_video.py::TestGoogleDisplayVideo360Hook::run_query
--
providers/google/tests/unit/google/cloud/hooks/test_display_video.py::TestGoogleDisplayVideo360Hook::get_report
--
providers/google/tests/unit/google/cloud/hooks/test_display_video.py::TestGoogleDisplayVideo360Hook::upload_line_items
--
providers/google/tests/unit/google/cloud/hooks/test_display_video.py::TestGoogleDisplayVideo360Hook::download_line_items
--
providers/google/tests/unit/google/cloud/operators/test_display_video.py::TestGoogleDisplayVideo360DeleteReportOperator::test_execute
--
providers/google/tests/unit/google/cloud/operators/test_display_video.py::TestGoogleDisplayVideo360DownloadReportV2Operator::test_execute
--
providers/google/tests/unit/google/cloud/operators/test_display_video.py::TestGoogleDisplayVideo360DownloadReportV2Operator::test_set_bucket_name
--
providers/google/tests/unit/google/cloud/operators/test_display_video.py::TestGoogleDisplayVideo360RunQueryOperator::test_execute
--
providers/google/tests/unit/google/cloud/operators/test_display_video.py::TestGoogleDisplayVideo360DownloadLineItemsOperator::test_execute
--
providers/google/tests/unit/google/cloud/operators/test_display_video.py::TestGoogleDisplayVideo360UploadLineItemsOperator::test_execute
--
providers/google/tests/unit/google/cloud/operators/test_display_video.py::TestGoogleDisplayVideo360CreateQueryOperator::test_execute
--
providers/google/tests/unit/google/cloud/operators/test_display_video.py::TestGoogleDisplayVideo360CreateQueryOperator::test_prepare_template
-
providers/google/tests/unit/google/cloud/operators/test_dataproc.py::TestDataprocClusterScaleOperator::test_execute
-
providers/google/tests/unit/google/cloud/operators/test_dataproc.py::test_create_cluster_operator_extra_links
-
providers/google/tests/unit/google/cloud/operators/test_dataproc.py::test_scale_cluster_operator_extra_links
diff --git
a/providers/google/tests/unit/google/marketing_platform/hooks/test_display_video.py
b/providers/google/tests/unit/google/marketing_platform/hooks/test_display_video.py
index abe1872e8f4..04a154b4d87 100644
---
a/providers/google/tests/unit/google/marketing_platform/hooks/test_display_video.py
+++
b/providers/google/tests/unit/google/marketing_platform/hooks/test_display_video.py
@@ -19,9 +19,6 @@ from __future__ import annotations
from unittest import mock
-import pytest
-
-from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.providers.google.marketing_platform.hooks.display_video import
GoogleDisplayVideo360Hook
from unit.google.cloud.utils.base_gcp_mock import
mock_base_gcp_hook_default_project_id
@@ -38,21 +35,6 @@ class TestGoogleDisplayVideo360Hook:
):
self.hook = GoogleDisplayVideo360Hook(api_version=API_VERSION,
gcp_conn_id=GCP_CONN_ID)
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook._authorize"
- )
-
@mock.patch("airflow.providers.google.marketing_platform.hooks.display_video.build")
- def test_gen_conn(self, mock_build, mock_authorize):
- with pytest.warns(AirflowProviderDeprecationWarning):
- result = self.hook.get_conn()
- mock_build.assert_called_once_with(
- "doubleclickbidmanager",
- API_VERSION,
- http=mock_authorize.return_value,
- cache_discovery=False,
- )
- assert mock_build.return_value == result
-
@mock.patch(
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook._authorize"
)
@@ -67,173 +49,6 @@ class TestGoogleDisplayVideo360Hook:
)
assert mock_build.return_value == result
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_create_query(self, get_conn_mock):
- body = {"body": "test"}
-
- return_value = "TEST"
-
get_conn_mock.return_value.queries.return_value.create.return_value.execute.return_value
= (
- return_value
- )
- with pytest.warns(AirflowProviderDeprecationWarning):
- result = self.hook.create_query(query=body)
-
-
get_conn_mock.return_value.queries.return_value.create.assert_called_once_with(body=body)
-
- assert return_value == result
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_delete_query(self, get_conn_mock):
- query_id = "QUERY_ID"
-
- return_value = "TEST"
-
get_conn_mock.return_value.queries.return_value.delete.return_value.execute.return_value
= (
- return_value
- )
- with pytest.warns(AirflowProviderDeprecationWarning):
- self.hook.delete_query(query_id=query_id)
-
-
get_conn_mock.return_value.queries.return_value.delete.assert_called_once_with(queryId=query_id)
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_get_query(self, get_conn_mock):
- query_id = "QUERY_ID"
-
- return_value = "TEST"
-
get_conn_mock.return_value.queries.return_value.get.return_value.execute.return_value
= return_value
- with pytest.warns(AirflowProviderDeprecationWarning):
- result = self.hook.get_query(query_id=query_id)
-
-
get_conn_mock.return_value.queries.return_value.get.assert_called_once_with(queryId=query_id)
-
- assert return_value == result
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_list_queries(self, get_conn_mock):
- queries = ["test"]
- return_value = {"queries": queries}
-
get_conn_mock.return_value.queries.return_value.list.return_value.execute.return_value
= return_value
- with pytest.warns(AirflowProviderDeprecationWarning):
- result = self.hook.list_queries()
-
-
get_conn_mock.return_value.queries.return_value.list.assert_called_once_with()
-
- assert queries == result
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_run_query(self, get_conn_mock):
- query_id = "QUERY_ID"
- params = {"params": "test"}
- with pytest.warns(AirflowProviderDeprecationWarning):
- self.hook.run_query(query_id=query_id, params=params)
-
-
get_conn_mock.return_value.queries.return_value.run.assert_called_once_with(
- queryId=query_id, body=params
- )
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_download_line_items_should_be_called_once(self, get_conn_mock):
- request_body = {
- "filterType": "filter_type",
- "filterIds": [],
- "format": "format",
- "fileSpec": "file_spec",
- }
- with pytest.warns(AirflowProviderDeprecationWarning):
- self.hook.download_line_items(request_body=request_body)
-
get_conn_mock.return_value.lineitems.return_value.downloadlineitems.assert_called_once()
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_download_line_items_should_be_called_with_params(self,
get_conn_mock):
- request_body = {
- "filterType": "filter_type",
- "filterIds": [],
- "format": "format",
- "fileSpec": "file_spec",
- }
- with pytest.warns(AirflowProviderDeprecationWarning):
- self.hook.download_line_items(request_body=request_body)
-
-
get_conn_mock.return_value.lineitems.return_value.downloadlineitems.assert_called_once_with(
- body=request_body
- )
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_download_line_items_should_return_equal_values(self,
get_conn_mock):
- line_item = ["holy_hand_grenade"]
- response = {"lineItems": line_item}
- request_body = {
- "filterType": "filter_type",
- "filterIds": [],
- "format": "format",
- "fileSpec": "file_spec",
- }
-
- # fmt: off
- get_conn_mock.return_value.lineitems.return_value \
- .downloadlineitems.return_value.execute.return_value = response
- # fmt: on
- with pytest.warns(AirflowProviderDeprecationWarning):
- result = self.hook.download_line_items(request_body)
- assert line_item == result
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_upload_line_items_should_be_called_once(self, get_conn_mock):
- line_items = ["this", "is", "super", "awesome", "test"]
- with pytest.warns(AirflowProviderDeprecationWarning):
- self.hook.upload_line_items(line_items)
-
get_conn_mock.return_value.lineitems.return_value.uploadlineitems.assert_called_once()
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_upload_line_items_should_be_called_with_params(self,
get_conn_mock):
- line_items = "I spent too much time on this"
- request_body = {
- "lineItems": line_items,
- "dryRun": False,
- "format": "CSV",
- }
- with pytest.warns(AirflowProviderDeprecationWarning):
- self.hook.upload_line_items(line_items)
-
-
get_conn_mock.return_value.lineitems.return_value.uploadlineitems.assert_called_once_with(
- body=request_body
- )
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_upload_line_items_should_return_equal_values(self, get_conn_mock):
- line_items = {"lineItems": "string", "format": "string", "dryRun":
False}
- return_value = "TEST"
- # fmt: off
- get_conn_mock.return_value.lineitems.return_value \
- .uploadlineitems.return_value.execute.return_value = return_value
- # fmt: on
- with pytest.warns(AirflowProviderDeprecationWarning):
- result = self.hook.upload_line_items(line_items)
-
- assert return_value == result
-
@mock.patch(
"airflow.providers.google.marketing_platform.hooks."
"display_video.GoogleDisplayVideo360Hook.get_conn_to_display_video"
@@ -373,21 +188,6 @@ class TestGoogleDisplayVideo360v2Hook:
self.api_version = "v2"
self.hook =
GoogleDisplayVideo360Hook(api_version=self.api_version, gcp_conn_id=GCP_CONN_ID)
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook._authorize"
- )
-
@mock.patch("airflow.providers.google.marketing_platform.hooks.display_video.build")
- def test_gen_conn(self, mock_build, mock_authorize):
- with pytest.warns(AirflowProviderDeprecationWarning):
- result = self.hook.get_conn()
- mock_build.assert_called_once_with(
- "doubleclickbidmanager",
- self.api_version,
- http=mock_authorize.return_value,
- cache_discovery=False,
- )
- assert mock_build.return_value == result
-
@mock.patch(
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook._authorize"
)
@@ -401,93 +201,3 @@ class TestGoogleDisplayVideo360v2Hook:
cache_discovery=False,
)
assert mock_build.return_value == result
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_create_query(self, get_conn_mock):
- body = {"body": "test"}
-
- return_value = "TEST"
-
get_conn_mock.return_value.queries.return_value.create.return_value.execute.return_value
= (
- return_value
- )
- with pytest.warns(AirflowProviderDeprecationWarning):
- result = self.hook.create_query(query=body)
-
-
get_conn_mock.return_value.queries.return_value.create.assert_called_once_with(body=body)
-
- assert return_value == result
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_delete_query(self, get_conn_mock):
- query_id = "QUERY_ID"
-
- return_value = "TEST"
-
get_conn_mock.return_value.queries.return_value.delete.return_value.execute.return_value
= (
- return_value
- )
- with pytest.warns(AirflowProviderDeprecationWarning):
- self.hook.delete_query(query_id=query_id)
-
-
get_conn_mock.return_value.queries.return_value.delete.assert_called_once_with(queryId=query_id)
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_get_query(self, get_conn_mock):
- query_id = "QUERY_ID"
-
- return_value = "TEST"
-
get_conn_mock.return_value.queries.return_value.get.return_value.execute.return_value
= return_value
- with pytest.warns(AirflowProviderDeprecationWarning):
- result = self.hook.get_query(query_id=query_id)
-
-
get_conn_mock.return_value.queries.return_value.get.assert_called_once_with(queryId=query_id)
-
- assert return_value == result
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_list_queries(self, get_conn_mock):
- queries = ["test"]
- return_value = {"queries": queries}
-
get_conn_mock.return_value.queries.return_value.list.return_value.execute.return_value
= return_value
- with pytest.warns(AirflowProviderDeprecationWarning):
- result = self.hook.list_queries()
-
-
get_conn_mock.return_value.queries.return_value.list.assert_called_once_with()
-
- assert queries == result
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_run_query(self, get_conn_mock):
- query_id = "QUERY_ID"
- params = {"params": "test"}
- with pytest.warns(AirflowProviderDeprecationWarning):
- self.hook.run_query(query_id=query_id, params=params)
-
-
get_conn_mock.return_value.queries.return_value.run.assert_called_once_with(
- queryId=query_id, body=params
- )
-
- @mock.patch(
-
"airflow.providers.google.marketing_platform.hooks.display_video.GoogleDisplayVideo360Hook.get_conn"
- )
- def test_get_report(self, get_conn_mock):
- query_id = "QUERY_ID"
- report_id = "REPORT_ID"
-
- return_value = "TEST"
-
get_conn_mock.return_value.queries.return_value.reports.return_value.get.return_value.execute.return_value
= return_value
- with pytest.warns(AirflowProviderDeprecationWarning):
- self.hook.get_report(query_id=query_id, report_id=report_id)
-
-
get_conn_mock.return_value.queries.return_value.reports.return_value.get.assert_called_once_with(
- queryId=query_id, reportId=report_id
- )
diff --git
a/providers/google/tests/unit/google/marketing_platform/operators/test_display_video.py
b/providers/google/tests/unit/google/marketing_platform/operators/test_display_video.py
index dadcc3203b0..0612e8b22f2 100644
---
a/providers/google/tests/unit/google/marketing_platform/operators/test_display_video.py
+++
b/providers/google/tests/unit/google/marketing_platform/operators/test_display_video.py
@@ -17,26 +17,13 @@
# under the License.
from __future__ import annotations
-import json
-from tempfile import NamedTemporaryFile
from unittest import mock
-import pytest
-
-from airflow.exceptions import AirflowException,
AirflowProviderDeprecationWarning
-from airflow.models import TaskInstance as TI
from airflow.providers.google.marketing_platform.operators.display_video
import (
- GoogleDisplayVideo360CreateQueryOperator,
GoogleDisplayVideo360CreateSDFDownloadTaskOperator,
- GoogleDisplayVideo360DeleteReportOperator,
- GoogleDisplayVideo360DownloadLineItemsOperator,
- GoogleDisplayVideo360DownloadReportV2Operator,
- GoogleDisplayVideo360RunQueryOperator,
GoogleDisplayVideo360SDFtoGCSOperator,
- GoogleDisplayVideo360UploadLineItemsOperator,
)
from airflow.utils import timezone
-from airflow.utils.session import create_session
API_VERSION = "v4"
GCP_CONN_ID = "google_cloud_default"
@@ -52,278 +39,6 @@ OPERATION_NAME = "test_operation"
RESOURCE_NAME = "resource/path/to/media"
-class TestGoogleDisplayVideo360DeleteReportOperator:
- @mock.patch(
-
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360Hook"
- )
- def test_execute(self, hook_mock):
- with pytest.warns(AirflowProviderDeprecationWarning): # noqa: PT031
- op = GoogleDisplayVideo360DeleteReportOperator(
- report_id=QUERY_ID, api_version=API_VERSION,
task_id="test_task"
- )
- op.execute(context=None)
- hook_mock.assert_called_once_with(
- gcp_conn_id=GCP_CONN_ID,
- api_version=API_VERSION,
- impersonation_chain=None,
- )
-
hook_mock.return_value.delete_query.assert_called_once_with(query_id=QUERY_ID)
-
-
[email protected]_test
-class TestGoogleDisplayVideo360DownloadReportV2Operator:
- def setup_method(self):
- with create_session() as session:
- session.query(TI).delete()
-
- def teardown_method(self):
- with create_session() as session:
- session.query(TI).delete()
-
- @pytest.mark.parametrize(
- "file_path, should_except", [("https://host/path", False),
("file:/path/to/file", True)]
- )
-
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.shutil")
-
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.urllib.request")
-
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.tempfile")
-
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.GCSHook")
- @mock.patch(
-
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360Hook"
- )
- def test_execute(
- self,
- mock_hook,
- mock_gcs_hook,
- mock_temp,
- mock_request,
- mock_shutil,
- file_path,
- should_except,
- ):
- mock_temp.NamedTemporaryFile.return_value.__enter__.return_value.name
= FILENAME
- mock_hook.return_value.get_report.return_value = {
- "metadata": {
- "status": {"state": "DONE"},
- "googleCloudStoragePath": file_path,
- }
- }
- # Create mock context with task_instance
- mock_context = {"task_instance": mock.Mock()}
-
- with pytest.warns(AirflowProviderDeprecationWarning): # noqa: PT031
- op = GoogleDisplayVideo360DownloadReportV2Operator(
- query_id=QUERY_ID,
- report_id=REPORT_ID,
- bucket_name=BUCKET_NAME,
- report_name=REPORT_NAME,
- task_id="test_task",
- )
- if should_except:
- with pytest.raises(AirflowException):
- op.execute(context=mock_context)
- return
- op.execute(context=mock_context)
- mock_hook.assert_called_once_with(
- gcp_conn_id=GCP_CONN_ID,
- api_version="v2",
- impersonation_chain=None,
- )
-
mock_hook.return_value.get_report.assert_called_once_with(report_id=REPORT_ID,
query_id=QUERY_ID)
-
- mock_gcs_hook.assert_called_once_with(
- gcp_conn_id=GCP_CONN_ID,
- impersonation_chain=None,
- )
- mock_gcs_hook.return_value.upload.assert_called_once_with(
- bucket_name=BUCKET_NAME,
- filename=FILENAME,
- gzip=True,
- mime_type="text/csv",
- object_name=REPORT_NAME + ".gz",
- )
- mock_context["task_instance"].xcom_push.assert_called_once_with(
- key="report_name", value=REPORT_NAME + ".gz"
- )
-
- @pytest.mark.parametrize(
- "test_bucket_name",
- [BUCKET_NAME, f"gs://{BUCKET_NAME}", "XComArg", "{{
ti.xcom_pull(task_ids='taskflow_op') }}"],
- )
-
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.shutil")
-
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.urllib.request")
-
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.tempfile")
-
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.GCSHook")
- @mock.patch(
-
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360Hook"
- )
- def test_set_bucket_name(
- self,
- mock_hook,
- mock_gcs_hook,
- mock_temp,
- mock_request,
- mock_shutil,
- test_bucket_name,
- dag_maker,
- ):
- mock_temp.NamedTemporaryFile.return_value.__enter__.return_value.name
= FILENAME
- mock_hook.return_value.get_report.return_value = {
- "metadata": {"status": {"state": "DONE"},
"googleCloudStoragePath": "TEST"}
- }
- with pytest.warns(AirflowProviderDeprecationWarning): # noqa: PT031
- with dag_maker(dag_id="test_set_bucket_name",
start_date=DEFAULT_DATE) as dag:
- if BUCKET_NAME not in test_bucket_name:
-
- @dag.task(task_id="taskflow_op")
- def f():
- return BUCKET_NAME
-
- taskflow_op = f()
-
- GoogleDisplayVideo360DownloadReportV2Operator(
- query_id=QUERY_ID,
- report_id=REPORT_ID,
- bucket_name=test_bucket_name if test_bucket_name !=
"XComArg" else taskflow_op,
- report_name=REPORT_NAME,
- task_id="test_task",
- )
-
- dr = dag_maker.create_dagrun()
-
- for ti in dr.get_task_instances():
- ti.run()
-
- mock_gcs_hook.return_value.upload.assert_called_once_with(
- bucket_name=BUCKET_NAME,
- filename=FILENAME,
- gzip=True,
- mime_type="text/csv",
- object_name=REPORT_NAME + ".gz",
- )
-
-
-class TestGoogleDisplayVideo360RunQueryOperator:
- @mock.patch(
-
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360Hook"
- )
- def test_execute(self, hook_mock):
- parameters = {"param": "test"}
-
- # Create mock context with task_instance
- mock_context = {"task_instance": mock.Mock()}
-
- hook_mock.return_value.run_query.return_value = {
- "key": {
- "queryId": QUERY_ID,
- "reportId": REPORT_ID,
- }
- }
- with pytest.warns(AirflowProviderDeprecationWarning): # noqa: PT031
- op = GoogleDisplayVideo360RunQueryOperator(
- query_id=QUERY_ID,
- parameters=parameters,
- api_version=API_VERSION,
- task_id="test_task",
- )
- op.execute(context=mock_context)
- hook_mock.assert_called_once_with(
- gcp_conn_id=GCP_CONN_ID,
- api_version=API_VERSION,
- impersonation_chain=None,
- )
-
-
mock_context["task_instance"].xcom_push.assert_any_call(key="query_id",
value=QUERY_ID)
-
mock_context["task_instance"].xcom_push.assert_any_call(key="report_id",
value=REPORT_ID)
-
hook_mock.return_value.run_query.assert_called_once_with(query_id=QUERY_ID,
params=parameters)
-
-
-class TestGoogleDisplayVideo360DownloadLineItemsOperator:
- @mock.patch(
-
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360Hook"
- )
-
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.GCSHook")
-
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.tempfile")
- def test_execute(self, mock_temp, gcs_hook_mock, hook_mock):
- request_body = {
- "filterType": "filter_type",
- "filterIds": [],
- "format": "format",
- "fileSpec": "file_spec",
- }
- mock_temp.NamedTemporaryFile.return_value.__enter__.return_value.name
= FILENAME
- gzip = False
- with pytest.warns(AirflowProviderDeprecationWarning): # noqa: PT031
- op = GoogleDisplayVideo360DownloadLineItemsOperator(
- request_body=request_body,
- bucket_name=BUCKET_NAME,
- object_name=OBJECT_NAME,
- gzip=gzip,
- api_version=API_VERSION,
- gcp_conn_id=GCP_CONN_ID,
- task_id="test_task",
- impersonation_chain=IMPERSONATION_CHAIN,
- )
- op.execute(context=None)
-
- gcs_hook_mock.return_value.upload.assert_called_with(
- bucket_name=BUCKET_NAME,
- object_name=OBJECT_NAME,
- filename=FILENAME,
- gzip=gzip,
- mime_type="text/csv",
- )
-
- gcs_hook_mock.assert_called_once_with(
- gcp_conn_id=GCP_CONN_ID,
- impersonation_chain=IMPERSONATION_CHAIN,
- )
- hook_mock.assert_called_once_with(
- gcp_conn_id=GCP_CONN_ID,
- api_version=API_VERSION,
- impersonation_chain=IMPERSONATION_CHAIN,
- )
-
hook_mock.return_value.download_line_items.assert_called_once_with(request_body=request_body)
-
-
-class TestGoogleDisplayVideo360UploadLineItemsOperator:
-
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.tempfile")
- @mock.patch(
-
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360Hook"
- )
-
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.GCSHook")
- def test_execute(self, gcs_hook_mock, hook_mock, mock_tempfile):
- line_items = "holy_hand_grenade"
- gcs_hook_mock.return_value.download.return_value = line_items
-
mock_tempfile.NamedTemporaryFile.return_value.__enter__.return_value.name =
FILENAME
- with pytest.warns(AirflowProviderDeprecationWarning): # noqa: PT031
- op = GoogleDisplayVideo360UploadLineItemsOperator(
- bucket_name=BUCKET_NAME,
- object_name=OBJECT_NAME,
- api_version=API_VERSION,
- gcp_conn_id=GCP_CONN_ID,
- task_id="test_task",
- )
- op.execute(context=None)
- hook_mock.assert_called_once_with(
- gcp_conn_id=GCP_CONN_ID,
- api_version=API_VERSION,
- impersonation_chain=None,
- )
-
- gcs_hook_mock.assert_called_once_with(
- gcp_conn_id=GCP_CONN_ID,
- impersonation_chain=None,
- )
-
- gcs_hook_mock.return_value.download.assert_called_once_with(
- bucket_name=BUCKET_NAME,
- object_name=OBJECT_NAME,
- filename=FILENAME,
- )
- hook_mock.return_value.upload_line_items.assert_called_once()
-
hook_mock.return_value.upload_line_items.assert_called_once_with(line_items=line_items)
-
-
class TestGoogleDisplayVideo360SDFtoGCSOperator:
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.zipfile")
@mock.patch("airflow.providers.google.marketing_platform.operators.display_video.os")
@@ -430,38 +145,3 @@ class
TestGoogleDisplayVideo360CreateSDFDownloadTaskOperator:
body_request=body_request
)
mock_context["task_instance"].xcom_push.assert_called_once_with(key="name",
value=test_name)
-
-
-class TestGoogleDisplayVideo360CreateQueryOperator:
- @mock.patch(
-
"airflow.providers.google.marketing_platform.operators.display_video.GoogleDisplayVideo360Hook"
- )
- def test_execute(self, hook_mock):
- body = {"body": "test"}
-
- # Create mock context with task_instance
- mock_context = {"task_instance": mock.Mock()}
-
- hook_mock.return_value.create_query.return_value = {"queryId":
QUERY_ID}
- with pytest.warns(AirflowProviderDeprecationWarning): # noqa: PT031
- op = GoogleDisplayVideo360CreateQueryOperator(body=body,
task_id="test_task")
- op.execute(context=mock_context)
- hook_mock.assert_called_once_with(
- gcp_conn_id=GCP_CONN_ID,
- api_version="v2",
- impersonation_chain=None,
- )
- hook_mock.return_value.create_query.assert_called_once_with(query=body)
-
mock_context["task_instance"].xcom_push.assert_called_once_with(key="query_id",
value=QUERY_ID)
-
- def test_prepare_template(self):
- body = {"key": "value"}
- with NamedTemporaryFile("w+", suffix=".json") as f:
- f.write(json.dumps(body))
- f.flush()
- with pytest.warns(AirflowProviderDeprecationWarning): # noqa:
PT031
- op = GoogleDisplayVideo360CreateQueryOperator(body=body,
task_id="test_task")
- op.prepare_template()
-
- assert isinstance(op.body, dict)
- assert op.body == body
diff --git
a/providers/google/tests/unit/google/marketing_platform/sensors/test_display_video.py
b/providers/google/tests/unit/google/marketing_platform/sensors/test_display_video.py
index fbc4d40f416..bdd36b4228a 100644
---
a/providers/google/tests/unit/google/marketing_platform/sensors/test_display_video.py
+++
b/providers/google/tests/unit/google/marketing_platform/sensors/test_display_video.py
@@ -21,10 +21,9 @@ from unittest import mock
import pytest
-from airflow.exceptions import AirflowException,
AirflowProviderDeprecationWarning
+from airflow.exceptions import AirflowException
from airflow.providers.google.marketing_platform.sensors.display_video import (
GoogleDisplayVideo360GetSDFDownloadOperationSensor,
- GoogleDisplayVideo360RunQuerySensor,
)
MODULE_NAME =
"airflow.providers.google.marketing_platform.sensors.display_video"
@@ -33,25 +32,6 @@ API_VERSION = "api_version"
GCP_CONN_ID = "google_cloud_default"
-class TestGoogleDisplayVideo360RunQuerySensor:
- @mock.patch(f"{MODULE_NAME}.GoogleDisplayVideo360Hook")
- @mock.patch(f"{MODULE_NAME}.BaseSensorOperator")
- def test_poke(self, mock_base_op, hook_mock):
- query_id = "QUERY_ID"
- report_id = "REPORT_ID"
- with pytest.warns(AirflowProviderDeprecationWarning): # noqa: PT031
- op = GoogleDisplayVideo360RunQuerySensor(
- query_id=query_id, report_id=report_id, task_id="test_task"
- )
- op.poke(context=None)
- hook_mock.assert_called_once_with(
- gcp_conn_id=GCP_CONN_ID,
- api_version="v2",
- impersonation_chain=None,
- )
-
hook_mock.return_value.get_report.assert_called_once_with(query_id=query_id,
report_id=report_id)
-
-
class TestGoogleDisplayVideo360Sensor:
@mock.patch(f"{MODULE_NAME}.GoogleDisplayVideo360Hook")
@mock.patch(f"{MODULE_NAME}.BaseSensorOperator")