当前位置: 首页>>代码示例>>Python>>正文


Python CloudVisionHook.delete_product_set方法代码示例

本文整理汇总了Python中airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.delete_product_set方法的典型用法代码示例。如果您正苦于以下问题:Python CloudVisionHook.delete_product_set方法的具体用法?Python CloudVisionHook.delete_product_set怎么用?Python CloudVisionHook.delete_product_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook的用法示例。


在下文中一共展示了CloudVisionHook.delete_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 delete_product_set [as 别名]

#.........这里部分代码省略.........
        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(
            parent=PRODUCT_NAME,
            reference_image=REFERENCE_IMAGE_WITHOUT_ID_NAME,
开发者ID:Fokko,项目名称:incubator-airflow,代码行数:70,代码来源:test_gcp_vision_hook.py

示例2: CloudVisionProductSetDeleteOperator

# 需要导入模块: from airflow.contrib.hooks.gcp_vision_hook import CloudVisionHook [as 别名]
# 或者: from airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook import delete_product_set [as 别名]
class CloudVisionProductSetDeleteOperator(BaseOperator):
    """
    Permanently deletes a `ProductSet`. `Products` and `ReferenceImages` in the
    `ProductSet` are not deleted. The actual image files are not deleted from Google
    Cloud Storage.

    .. seealso::
        For more information on how to use this operator, take a look at the guide:
        :ref:`howto/operator:CloudVisionProductSetDeleteOperator`

    :param location: (Required) 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: (Required) 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 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_delete_template_fields]
    template_fields = ('location', 'project_id', 'product_set_id', 'gcp_conn_id')
    # [END vision_productset_delete_template_fields]

    @apply_defaults
    def __init__(
        self,
        location,
        product_set_id,
        project_id=None,
        retry=None,
        timeout=None,
        metadata=None,
        gcp_conn_id='google_cloud_default',
        *args,
        **kwargs
    ):
        super(CloudVisionProductSetDeleteOperator, self).__init__(*args, **kwargs)
        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.delete_product_set(
            location=self.location,
            product_set_id=self.product_set_id,
            project_id=self.project_id,
            retry=self.retry,
            timeout=self.timeout,
            metadata=self.metadata,
        )
开发者ID:wooga,项目名称:airflow,代码行数:70,代码来源:gcp_vision_operator.py


注:本文中的airflow.contrib.hooks.gcp_vision_hook.CloudVisionHook.delete_product_set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。