本文整理匯總了Python中airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.delete_product方法的典型用法代碼示例。如果您正苦於以下問題:Python CloudVisionHook.delete_product方法的具體用法?Python CloudVisionHook.delete_product怎麽用?Python CloudVisionHook.delete_product使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook
的用法示例。
在下文中一共展示了CloudVisionHook.delete_product方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestGcpVisionHook
# 需要導入模塊: from airflow.contrib.hooks.gcp_vision_hook import CloudVisionHook [as 別名]
# 或者: from airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook import delete_product [as 別名]
#.........這裏部分代碼省略.........
)
product_set = ProductSet(name=explicit_ps_name)
template_ps_name = ProductSearchClient.product_set_path(
PROJECT_ID_TEST, LOC_ID_TEST, PRODUCTSET_ID_TEST
)
# When
# Location and product_set_id are passed in addition to a ProductSet with an explicit name,
# but both names differ (constructed != explicit).
# Should throw AirflowException in this case.
with self.assertRaises(AirflowException) as cm:
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,
)
err = cm.exception
# self.assertIn("The required parameter 'project_id' is missing", str(err))
self.assertTrue(err)
self.assertIn(
"The ProductSet name provided in the object ({}) is different than the name "
"created from the input parameters ({}). Please either: 1) Remove the ProductSet "
"name, 2) Remove the location and productset_id parameters, 3) Unify the "
"ProductSet name and input parameters.".format(explicit_ps_name, template_ps_name),
str(err),
)
update_product_set_method.assert_not_called()
@mock.patch('airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.get_conn')
def test_delete_productset(self, get_conn):
# Given
delete_product_set_method = get_conn.return_value.delete_product_set
delete_product_set_method.return_value = None
name = ProductSearchClient.product_set_path(PROJECT_ID_TEST, LOC_ID_TEST, PRODUCTSET_ID_TEST)
# When
response = self.hook.delete_product_set(
location=LOC_ID_TEST, product_set_id=PRODUCTSET_ID_TEST, project_id=PROJECT_ID_TEST
)
# Then
self.assertIsNone(response)
delete_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',
**{'return_value.create_reference_image.return_value': REFERENCE_IMAGE_TEST}
)
def test_create_reference_image_explicit_id(self, get_conn):
# Given
create_reference_image_method = get_conn.return_value.create_reference_image
# When
result = self.hook.create_reference_image(
project_id=PROJECT_ID_TEST,
location=LOC_ID_TEST,
product_id=PRODUCT_ID_TEST,
reference_image=REFERENCE_IMAGE_WITHOUT_ID_NAME,
reference_image_id=REFERENCE_IMAGE_ID_TEST,
)
# Then
# Product ID was provided explicitly in the method call above, should be returned from the method
self.assertEqual(result, REFERENCE_IMAGE_ID_TEST)
create_reference_image_method.assert_called_once_with(
示例2: CloudVisionProductDeleteOperator
# 需要導入模塊: from airflow.contrib.hooks.gcp_vision_hook import CloudVisionHook [as 別名]
# 或者: from airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook import delete_product [as 別名]
class CloudVisionProductDeleteOperator(BaseOperator):
"""
Permanently deletes a product and its reference images.
Metadata of the product and all its images will be deleted right away, but search queries against
ProductSets containing the product may still work until all related caches are refreshed.
Possible errors:
- Returns NOT_FOUND if the product does not exist.
.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:CloudVisionProductDeleteOperator`
:param location: (Required) 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: (Required) 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 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_delete_template_fields]
template_fields = ('location', 'project_id', 'product_id', 'gcp_conn_id')
# [END vision_product_delete_template_fields]
@apply_defaults
def __init__(
self,
location,
product_id,
project_id=None,
retry=None,
timeout=None,
metadata=None,
gcp_conn_id='google_cloud_default',
*args,
**kwargs
):
super(CloudVisionProductDeleteOperator, self).__init__(*args, **kwargs)
self.location = location
self.product_id = product_id
self.project_id = project_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.delete_product(
location=self.location,
product_id=self.product_id,
project_id=self.project_id,
retry=self.retry,
timeout=self.timeout,
metadata=self.metadata,
)