當前位置: 首頁>>代碼示例>>Python>>正文


Python vision_v1.ProductSearchClient類代碼示例

本文整理匯總了Python中google.cloud.vision_v1.ProductSearchClient的典型用法代碼示例。如果您正苦於以下問題:Python ProductSearchClient類的具體用法?Python ProductSearchClient怎麽用?Python ProductSearchClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ProductSearchClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: remove_product_from_product_set

    def remove_product_from_product_set(
        self,
        product_set_id,
        product_id,
        location=None,
        project_id=None,
        retry=None,
        timeout=None,
        metadata=None,
    ):
        """
        For the documentation see:
        :py:class:`~airflow.contrib.operators.gcp_vision_operator.CloudVisionRemoveProductFromProductSetOperator`
        """
        client = self.get_conn()

        product_name = ProductSearchClient.product_path(project_id, location, product_id)
        product_set_name = ProductSearchClient.product_set_path(project_id, location, product_set_id)

        self.log.info('Remove Product[name=%s] from Product Set[name=%s]', product_name, product_set_name)

        client.remove_product_from_product_set(
            name=product_set_name, product=product_name, retry=retry, timeout=timeout, metadata=metadata
        )

        self.log.info('Product removed from Product Set')
開發者ID:sekikn,項目名稱:incubator-airflow,代碼行數:26,代碼來源:gcp_vision_hook.py

示例2: test_update_product_explicit_name_different_from_constructed

 def test_update_product_explicit_name_different_from_constructed(self, get_conn):
     # Given
     update_product_method = get_conn.return_value.update_product
     update_product_method.return_value = None
     explicit_p_name = ProductSearchClient.product_path(
         PROJECT_ID_TEST_2, LOC_ID_TEST_2, PRODUCT_ID_TEST_2
     )
     product = Product(name=explicit_p_name)
     template_p_name = ProductSearchClient.product_path(PROJECT_ID_TEST, LOC_ID_TEST, PRODUCT_ID_TEST)
     # When
     # Location and product_id are passed in addition to a Product 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(
             location=LOC_ID_TEST,
             product_id=PRODUCT_ID_TEST,
             product=product,
             update_mask=None,
             project_id=PROJECT_ID_TEST,
             retry=None,
             timeout=None,
             metadata=None,
         )
     err = cm.exception
     self.assertTrue(err)
     self.assertIn(
         "The Product name provided in the object ({}) is different than the name created from the input "
         "parameters ({}). Please either: 1) Remove the Product name, 2) Remove the location and product_"
         "id parameters, 3) Unify the Product name and input parameters.".format(
             explicit_p_name, template_p_name
         ),
         str(err),
     )
     update_product_method.assert_not_called()
開發者ID:Fokko,項目名稱:incubator-airflow,代碼行數:35,代碼來源:test_gcp_vision_hook.py

示例3: test_create_productset_autogenerated_id

 def test_create_productset_autogenerated_id(self, get_conn):
     # Given
     autogenerated_id = 'autogen-id'
     response_product_set = ProductSet(
         name=ProductSearchClient.product_set_path(PROJECT_ID_TEST, LOC_ID_TEST, autogenerated_id)
     )
     create_product_set_method = get_conn.return_value.create_product_set
     create_product_set_method.return_value = response_product_set
     parent = ProductSearchClient.location_path(PROJECT_ID_TEST, LOC_ID_TEST)
     product_set = ProductSet()
     # When
     result = self.hook.create_product_set(
         location=LOC_ID_TEST, product_set_id=None, product_set=product_set, project_id=PROJECT_ID_TEST
     )
     # Then
     # ProductSet ID was not provided in the method call above. Should be extracted from the API response
     # and returned.
     self.assertEqual(result, autogenerated_id)
     create_product_set_method.assert_called_once_with(
         parent=parent,
         product_set=product_set,
         product_set_id=None,
         retry=None,
         timeout=None,
         metadata=None,
     )
開發者ID:Fokko,項目名稱:incubator-airflow,代碼行數:26,代碼來源:test_gcp_vision_hook.py

示例4: test_create_productset_explicit_id

    def test_create_productset_explicit_id(self, get_conn):
        # Given
        create_product_set_method = get_conn.return_value.create_product_set
        create_product_set_method.return_value = None
        parent = ProductSearchClient.location_path(PROJECT_ID_TEST, LOC_ID_TEST)
        product_set = ProductSet()
        # When
        result = self.hook.create_product_set(
            location=LOC_ID_TEST,
            product_set_id=PRODUCTSET_ID_TEST,
            product_set=product_set,
            project_id=PROJECT_ID_TEST,
            retry=None,
            timeout=None,
            metadata=None,
        )

        # Then
        # ProductSet ID was provided explicitly in the method call above, should be returned from the method
        self.assertEqual(result, PRODUCTSET_ID_TEST)
        create_product_set_method.assert_called_once_with(
            parent=parent,
            product_set=product_set,
            product_set_id=PRODUCTSET_ID_TEST,
            retry=None,
            timeout=None,
            metadata=None,
        )
開發者ID:Fokko,項目名稱:incubator-airflow,代碼行數:28,代碼來源:test_gcp_vision_hook.py

示例5: test_update_product_explicit_name_missing_params_for_constructed_name

 def test_update_product_explicit_name_missing_params_for_constructed_name(
     self, location, product_id, get_conn
 ):
     # Given
     explicit_p_name = ProductSearchClient.product_path(
         PROJECT_ID_TEST_2, LOC_ID_TEST_2, PRODUCT_ID_TEST_2
     )
     product = Product(name=explicit_p_name)
     update_product_method = get_conn.return_value.update_product
     update_product_method.return_value = product
     # When
     result = self.hook.update_product(
         location=location,
         product_id=product_id,
         product=product,
         update_mask=None,
         project_id=PROJECT_ID_TEST,
         retry=None,
         timeout=None,
         metadata=None,
     )
     # Then
     self.assertEqual(result, MessageToDict(product))
     update_product_method.assert_called_once_with(
         product=Product(name=explicit_p_name), metadata=None, retry=None, timeout=None, update_mask=None
     )
開發者ID:Fokko,項目名稱:incubator-airflow,代碼行數:26,代碼來源:test_gcp_vision_hook.py

示例6: test_update_productset_no_explicit_name

 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,
     )
開發者ID:Fokko,項目名稱:incubator-airflow,代碼行數:28,代碼來源:test_gcp_vision_hook.py

示例7: test_create_productset_autogenerated_id_wrong_api_response

 def test_create_productset_autogenerated_id_wrong_api_response(self, get_conn):
     # Given
     response_product_set = None
     create_product_set_method = get_conn.return_value.create_product_set
     create_product_set_method.return_value = response_product_set
     parent = ProductSearchClient.location_path(PROJECT_ID_TEST, LOC_ID_TEST)
     product_set = ProductSet()
     # When
     with self.assertRaises(AirflowException) as cm:
         self.hook.create_product_set(
             location=LOC_ID_TEST,
             product_set_id=None,
             product_set=product_set,
             project_id=PROJECT_ID_TEST,
             retry=None,
             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,
     )
開發者ID:Fokko,項目名稱:incubator-airflow,代碼行數:30,代碼來源:test_gcp_vision_hook.py

示例8: create_product

    def create_product(
        self, location, product, project_id=None, product_id=None, retry=None, timeout=None, metadata=None
    ):
        """
        For the documentation see:
        :class:`~airflow.contrib.operators.gcp_vision_operator.CloudVisionProductCreateOperator`
        """
        client = self.get_conn()
        parent = ProductSearchClient.location_path(project_id, location)
        self.log.info('Creating a new Product under the parent: %s', parent)
        response = self._handle_request(
            lambda **kwargs: client.create_product(**kwargs),
            parent=parent,
            product=product,
            product_id=product_id,
            retry=retry,
            timeout=timeout,
            metadata=metadata,
        )
        self.log.info('Product created: %s', response.name if response else '')
        self.log.debug('Product created:\n%s', response)

        if not product_id:
            # Product id was generated by the API
            product_id = self._get_autogenerated_id(response)
            self.log.info('Extracted autogenerated Product ID from the response: %s', product_id)

        return product_id
開發者ID:wooga,項目名稱:airflow,代碼行數:28,代碼來源:gcp_vision_hook.py

示例9: delete_product

 def delete_product(self, location, product_id, project_id=None, retry=None, timeout=None, metadata=None):
     """
     For the documentation see:
     :class:`~airflow.contrib.operators.gcp_vision_operator.CloudVisionProductDeleteOperator`
     """
     client = self.get_conn()
     name = ProductSearchClient.product_path(project_id, location, product_id)
     self.log.info('Deleting ProductSet: %s', name)
     client.delete_product(name=name, retry=retry, timeout=timeout, metadata=metadata)
     self.log.info('Product with the name [%s] deleted:', name)
開發者ID:sekikn,項目名稱:incubator-airflow,代碼行數:10,代碼來源:gcp_vision_hook.py

示例10: get_product

 def get_product(self, location, product_id, project_id=None, retry=None, timeout=None, metadata=None):
     """
     For the documentation see:
     :class:`~airflow.contrib.operators.gcp_vision_operator.CloudVisionProductGetOperator`
     """
     client = self.get_conn()
     name = ProductSearchClient.product_path(project_id, location, product_id)
     self.log.info('Retrieving Product: %s', name)
     response = client.get_product(name=name, retry=retry, timeout=timeout, metadata=metadata)
     self.log.info('Product retrieved.')
     self.log.debug('Product retrieved:\n%s', response)
     return MessageToDict(response)
開發者ID:sekikn,項目名稱:incubator-airflow,代碼行數:12,代碼來源:gcp_vision_hook.py

示例11: test_delete_product

 def test_delete_product(self, get_conn):
     # Given
     delete_product_method = get_conn.return_value.delete_product
     delete_product_method.return_value = None
     name = ProductSearchClient.product_path(PROJECT_ID_TEST, LOC_ID_TEST, PRODUCT_ID_TEST)
     # When
     response = self.hook.delete_product(
         location=LOC_ID_TEST, product_id=PRODUCT_ID_TEST, project_id=PROJECT_ID_TEST
     )
     # Then
     self.assertIsNone(response)
     delete_product_method.assert_called_once_with(name=name, retry=None, timeout=None, metadata=None)
開發者ID:Fokko,項目名稱:incubator-airflow,代碼行數:12,代碼來源:test_gcp_vision_hook.py

示例12: test_get_productset

 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)
開發者ID:Fokko,項目名稱:incubator-airflow,代碼行數:14,代碼來源:test_gcp_vision_hook.py

示例13: delete_product_set

 def delete_product_set(
     self, location, product_set_id, project_id=None, retry=None, timeout=None, metadata=None
 ):
     """
     For the documentation see:
     :class:`~airflow.contrib.operators.gcp_vision_operator.CloudVisionProductSetDeleteOperator`
     """
     client = self.get_conn()
     name = ProductSearchClient.product_set_path(project_id, location, product_set_id)
     self.log.info('Deleting ProductSet: %s', name)
     response = self._handle_request(
         lambda **kwargs: client.delete_product_set(**kwargs),
         name=name,
         retry=retry,
         timeout=timeout,
         metadata=metadata,
     )
     self.log.info('ProductSet with the name [%s] deleted.', name)
     return response
開發者ID:wooga,項目名稱:airflow,代碼行數:19,代碼來源:gcp_vision_hook.py

示例14: test_create_product_autogenerated_id_wrong_name_in_response

 def test_create_product_autogenerated_id_wrong_name_in_response(self, get_conn):
     # Given
     wrong_name = 'wrong_name_not_a_correct_path'
     response_product = Product(name=wrong_name)
     create_product_method = get_conn.return_value.create_product
     create_product_method.return_value = response_product
     parent = ProductSearchClient.location_path(PROJECT_ID_TEST, LOC_ID_TEST)
     product = Product()
     # When
     with self.assertRaises(AirflowException) as cm:
         self.hook.create_product(
             location=LOC_ID_TEST, product_id=None, product=product, project_id=PROJECT_ID_TEST
         )
     # Then
     # API response was wrong (wrong name format) and thus ProductSet ID extraction should fail.
     err = cm.exception
     self.assertIn('Unable to get id from name', str(err))
     create_product_method.assert_called_once_with(
         parent=parent, product=product, product_id=None, retry=None, timeout=None, metadata=None
     )
開發者ID:Fokko,項目名稱:incubator-airflow,代碼行數:20,代碼來源:test_gcp_vision_hook.py

示例15: create_reference_image

    def create_reference_image(
        self,
        location,
        product_id,
        reference_image,
        reference_image_id=None,
        project_id=None,
        retry=None,
        timeout=None,
        metadata=None,
    ):
        """
        For the documentation see:
        :py:class:`~airflow.contrib.operators.gcp_vision_operator.CloudVisionReferenceImageCreateOperator`
        """
        client = self.get_conn()
        self.log.info('Creating ReferenceImage')
        parent = ProductSearchClient.product_path(project=project_id, location=location, product=product_id)

        response = client.create_reference_image(
            parent=parent,
            reference_image=reference_image,
            reference_image_id=reference_image_id,
            retry=retry,
            timeout=timeout,
            metadata=metadata,
        )

        self.log.info('ReferenceImage created: %s', response.name if response else '')
        self.log.debug('ReferenceImage created:\n%s', response)

        if not reference_image_id:
            # Refernece image  id was generated by the API
            reference_image_id = self._get_autogenerated_id(response)
            self.log.info(
                'Extracted autogenerated ReferenceImage ID from the response: %s', reference_image_id
            )

        return reference_image_id
開發者ID:sekikn,項目名稱:incubator-airflow,代碼行數:39,代碼來源:gcp_vision_hook.py


注:本文中的google.cloud.vision_v1.ProductSearchClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。