def test_update_product_set(self): # Create a ProductSet. product_set = vision.ProductSet(display_name="display name") product_set_id = "set" + unique_resource_id() product_set_path = self.ps_client.product_set_path( project=PROJECT_ID, location=self.location, product_set=product_set_id) response = self.ps_client.create_product_set( parent=self.location_path, product_set=product_set, product_set_id=product_set_id, ) self.product_sets_to_delete.append(response.name) self.assertEqual(response.name, product_set_path) # Update the ProductSet. new_display_name = "updated name" updated_product_set_request = vision.ProductSet( name=product_set_path, display_name=new_display_name) update_mask = field_mask.FieldMask(paths=["display_name"]) updated_product_set = self.ps_client.update_product_set( product_set=updated_product_set_request, update_mask=update_mask) self.assertEqual(updated_product_set.display_name, new_display_name)
def test_create_product_set(self): # Create a ProductSet. product_set = vision.ProductSet(display_name="display name") product_set_id = "set" + unique_resource_id() product_set_path = self.ps_client.product_set_path( project=PROJECT_ID, location=self.location, product_set=product_set_id) response = self.ps_client.create_product_set( parent=self.location_path, product_set=product_set, product_set_id=product_set_id, ) self.product_sets_to_delete.append(response.name) # Verify the ProductSet was successfully created. self.assertEqual(response.name, product_set_path)
def test_list_products_in_product_set(self): # Create a ProductSet. product_set = vision.ProductSet(display_name="display name") product_set_id = "set" + unique_resource_id() product_set_path = self.ps_client.product_set_path( project=PROJECT_ID, location=self.location, product_set=product_set_id) response = self.ps_client.create_product_set( parent=self.location_path, product_set=product_set, product_set_id=product_set_id, ) self.product_sets_to_delete.append(response.name) self.assertEqual(response.name, product_set_path) # Create a Product. product = vision.Product(display_name="product display name", product_category="apparel") product_id = "product" + unique_resource_id() product_path = self.ps_client.product_path(project=PROJECT_ID, location=self.location, product=product_id) response = self.ps_client.create_product(parent=self.location_path, product=product, product_id=product_id) self.products_to_delete.append(response.name) self.assertEqual(response.name, product_path) # Add the Product to the ProductSet. self.ps_client.add_product_to_product_set(name=product_set_path, product=product_path) # List the Products in the ProductSet. listed_products = list( self.ps_client.list_products_in_product_set(name=product_set_path)) self.assertEqual(len(listed_products), 1) self.assertEqual(listed_products[0].name, product_path) # Remove the Product from the ProductSet. self.ps_client.remove_product_from_product_set(name=product_set_path, product=product_path)
def test_list_product_sets(self): # Create a ProductSet. product_set = vision.ProductSet(display_name="display name") product_set_id = "set" + unique_resource_id() product_set_path = self.ps_client.product_set_path( project=PROJECT_ID, location=self.location, product_set=product_set_id) response = self.ps_client.create_product_set( parent=self.location_path, product_set=product_set, product_set_id=product_set_id, ) self.product_sets_to_delete.append(response.name) self.assertEqual(response.name, product_set_path) # Verify ProductSets can be listed. product_sets_iterator = self.ps_client.list_product_sets( parent=self.location_path) product_sets_exist = False for product_set in product_sets_iterator: product_sets_exist = True break self.assertTrue(product_sets_exist)
def create_product_set(project_id, location, product_set_id, product_set_display_name): """Create a product set. Args: project_id: Id of the project. location: A compute region name. product_set_id: Id of the product set. product_set_display_name: Display name of the product set. """ client = vision.ProductSearchClient() # A resource that represents Google Cloud Platform location. location_path = f"projects/{project_id}/locations/{location}" # Create a product set with the product set specification in the region. product_set = vision.ProductSet(display_name=product_set_display_name) # The response is the product set with `name` populated. response = client.create_product_set(parent=location_path, product_set=product_set, product_set_id=product_set_id) # Display the product set information. print('Product set name: {}'.format(response.name))
def test_update_product_set_blocked(self): product_set = vision.ProductSet(name=self.product_set_path) with pytest.raises(exceptions.PermissionDenied) as exc: self.ps_client.update_product_set(product_set=product_set) assert exc.value.message.startswith(_VPCSC_PROHIBITED_MESSAGE)