本文整理汇总了Python中airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.update_product_set方法的典型用法代码示例。如果您正苦于以下问题:Python CloudVisionHook.update_product_set方法的具体用法?Python CloudVisionHook.update_product_set怎么用?Python CloudVisionHook.update_product_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook
的用法示例。
在下文中一共展示了CloudVisionHook.update_product_set方法的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_set [as 别名]
#.........这里部分代码省略.........
# 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
):
# Given
update_product_set_method = get_conn.return_value.update_product_set
示例2: CloudVisionProductSetUpdateOperator
# 需要导入模块: from airflow.contrib.hooks.gcp_vision_hook import CloudVisionHook [as 别名]
# 或者: from airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook import update_product_set [as 别名]
class CloudVisionProductSetUpdateOperator(BaseOperator):
"""
Makes changes to a `ProductSet` resource. Only display_name can be updated currently.
.. note:: To locate the `ProductSet` resource, its `name` in the form
`projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID` is necessary.
You can provide the `name` directly as an attribute of the `product_set` object.
However, you can leave it blank and provide `location` and `product_set_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`.
.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:CloudVisionProductSetUpdateOperator`
:param product_set: (Required) The ProductSet resource which replaces the one on the
server. If a dict is provided, it must be of the same form as the protobuf
message `ProductSet`.
:type product_set: dict or google.cloud.vision_v1.types.ProductSet
:param location: (Optional) The region where the ProductSet is located. Valid regions (as of 2019-02-05)
are: us-east1, us-west1, europe-west1, asia-east1
:type location: str
:param product_set_id: (Optional) The resource id of this ProductSet.
:type product_set_id: str
:param project_id: (Optional) The project in which the ProductSet should be created. 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 path is display_name. 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_productset_update_template_fields]
template_fields = ('location', 'project_id', 'product_set_id', 'gcp_conn_id')
# [END vision_productset_update_template_fields]
@apply_defaults
def __init__(
self,
product_set,
location=None,
product_set_id=None,
project_id=None,
update_mask=None,
retry=None,
timeout=None,
metadata=None,
gcp_conn_id='google_cloud_default',
*args,
**kwargs
):
super(CloudVisionProductSetUpdateOperator, self).__init__(*args, **kwargs)
self.product_set = product_set
self.update_mask = update_mask
self.location = location
self.project_id = project_id
self.product_set_id = product_set_id
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_set(
location=self.location,
product_set_id=self.product_set_id,
project_id=self.project_id,
product_set=self.product_set,
update_mask=self.update_mask,
retry=self.retry,
timeout=self.timeout,
metadata=self.metadata,
)