本文整理汇总了Python中airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.update_product方法的典型用法代码示例。如果您正苦于以下问题:Python CloudVisionHook.update_product方法的具体用法?Python CloudVisionHook.update_product怎么用?Python CloudVisionHook.update_product使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook
的用法示例。
在下文中一共展示了CloudVisionHook.update_product方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestGcpVisionHook
# 需要导入模块: from airflow.contrib.hooks.gcp_vision_hook import CloudVisionHook [as 别名]
# 或者: from airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook import update_product [as 别名]
#.........这里部分代码省略.........
timeout=None,
metadata=None,
)
# Then
# API response was wrong (None) and thus ProductSet ID extraction should fail.
err = cm.exception
self.assertIn('Unable to get name from response...', str(err))
create_product_set_method.assert_called_once_with(
parent=parent,
product_set=product_set,
product_set_id=None,
retry=None,
timeout=None,
metadata=None,
)
@mock.patch('airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.get_conn')
def test_get_productset(self, get_conn):
# Given
name = ProductSearchClient.product_set_path(PROJECT_ID_TEST, LOC_ID_TEST, PRODUCTSET_ID_TEST)
response_product_set = ProductSet(name=name)
get_product_set_method = get_conn.return_value.get_product_set
get_product_set_method.return_value = response_product_set
# When
response = self.hook.get_product_set(
location=LOC_ID_TEST, product_set_id=PRODUCTSET_ID_TEST, project_id=PROJECT_ID_TEST
)
# Then
self.assertTrue(response)
self.assertEqual(response, MessageToDict(response_product_set))
get_product_set_method.assert_called_once_with(name=name, retry=None, timeout=None, metadata=None)
@mock.patch('airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.get_conn')
def test_update_productset_no_explicit_name(self, get_conn):
# Given
product_set = ProductSet()
update_product_set_method = get_conn.return_value.update_product_set
update_product_set_method.return_value = product_set
productset_name = ProductSearchClient.product_set_path(
PROJECT_ID_TEST, LOC_ID_TEST, PRODUCTSET_ID_TEST
)
# When
result = self.hook.update_product_set(
location=LOC_ID_TEST,
product_set_id=PRODUCTSET_ID_TEST,
product_set=product_set,
update_mask=None,
project_id=PROJECT_ID_TEST,
retry=None,
timeout=None,
metadata=None,
)
# Then
self.assertEqual(result, MessageToDict(product_set))
update_product_set_method.assert_called_once_with(
product_set=ProductSet(name=productset_name),
metadata=None,
retry=None,
timeout=None,
update_mask=None,
)
@parameterized.expand([(None, None), (None, PRODUCTSET_ID_TEST), (LOC_ID_TEST, None)])
@mock.patch('airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.get_conn')
def test_update_productset_no_explicit_name_and_missing_params_for_constructed_name(
self, location, product_set_id, get_conn
示例2: CloudVisionProductUpdateOperator
# 需要导入模块: from airflow.contrib.hooks.gcp_vision_hook import CloudVisionHook [as 别名]
# 或者: from airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook import update_product [as 别名]
class CloudVisionProductUpdateOperator(BaseOperator):
"""
Makes changes to a Product resource. Only the display_name, description, and labels fields can be
updated right now.
If labels are updated, the change will not be reflected in queries until the next index time.
.. note:: To locate the `Product` resource, its `name` in the form
`projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID` is necessary.
You can provide the `name` directly as an attribute of the `product` object. However, you can leave it
blank and provide `location` and `product_id` instead (and optionally `project_id` - if not present,
the connection default will be used) and the `name` will be created by the operator itself.
This mechanism exists for your convenience, to allow leaving the `project_id` empty and having Airflow
use the connection default `project_id`.
Possible errors related to the provided `Product`:
- Returns NOT_FOUND if the Product does not exist.
- Returns INVALID_ARGUMENT if display_name is present in update_mask but is missing from the request or
longer than 4096 characters.
- Returns INVALID_ARGUMENT if description is present in update_mask but is longer than 4096 characters.
- Returns INVALID_ARGUMENT if product_category is present in update_mask.
.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:CloudVisionProductUpdateOperator`
:param product: (Required) The Product resource which replaces the one on the server. product.name is
immutable. If a dict is provided, it must be of the same form as the protobuf message `Product`.
:type product: dict or google.cloud.vision_v1.types.ProductSet
:param location: (Optional) The region where the Product is located. Valid regions (as of 2019-02-05) are:
us-east1, us-west1, europe-west1, asia-east1
:type location: str
:param product_id: (Optional) The resource id of this Product.
:type product_id: str
:param project_id: (Optional) The project in which the Product is located. If set to None or
missing, the default project_id from the GCP connection is used.
:type project_id: str
:param update_mask: (Optional) The `FieldMask` that specifies which fields to update. If update_mask
isn’t specified, all mutable fields are to be updated. Valid mask paths include product_labels,
display_name, and description. If a dict is provided, it must be of the same form as the protobuf
message `FieldMask`.
:type update_mask: dict or google.cloud.vision_v1.types.FieldMask
:param retry: (Optional) A retry object used to retry requests. If `None` is
specified, requests will not be retried.
:type retry: google.api_core.retry.Retry
:param timeout: (Optional) The amount of time, in seconds, to wait for the request to
complete. Note that if retry is specified, the timeout applies to each individual
attempt.
:type timeout: float
:param metadata: (Optional) Additional metadata that is provided to the method.
:type metadata: Sequence[Tuple[str, str]]
:param gcp_conn_id: The connection ID used to connect to Google Cloud Platform.
:type gcp_conn_id: str
"""
# [START vision_product_update_template_fields]
template_fields = ('location', 'project_id', 'product_id', 'gcp_conn_id')
# [END vision_product_update_template_fields]
@apply_defaults
def __init__(
self,
product,
location=None,
product_id=None,
project_id=None,
update_mask=None,
retry=None,
timeout=None,
metadata=None,
gcp_conn_id='google_cloud_default',
*args,
**kwargs
):
super(CloudVisionProductUpdateOperator, self).__init__(*args, **kwargs)
self.product = product
self.location = location
self.product_id = product_id
self.project_id = project_id
self.update_mask = update_mask
self.retry = retry
self.timeout = timeout
self.metadata = metadata
self.gcp_conn_id = gcp_conn_id
self._hook = CloudVisionHook(gcp_conn_id=self.gcp_conn_id)
def execute(self, context):
return self._hook.update_product(
product=self.product,
location=self.location,
product_id=self.product_id,
project_id=self.project_id,
update_mask=self.update_mask,
retry=self.retry,
timeout=self.timeout,
metadata=self.metadata,
)