def test_update_field(self): # Setup Expected Response name = "name3373707" expected_response = {"name": name} expected_response = field_pb2.Field(**expected_response) operation = operations_pb2.Operation( name="operations/test_update_field", done=True) operation.response.Pack(expected_response) # Mock the API response channel = ChannelStub(responses=[operation]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = firestore_admin_v1.FirestoreAdminClient() # Setup Request field = {} response = client.update_field(field) result = response.result() assert expected_response == result assert len(channel.requests) == 1 expected_request = firestore_admin_pb2.UpdateFieldRequest(field=field) actual_request = channel.requests[0][1] assert expected_request == actual_request
def update_field( self, field, update_mask=None, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): """ Updates a field configuration. Currently, field updates apply only to single field index configuration. However, calls to ``FirestoreAdmin.UpdateField`` should provide a field mask to avoid changing any configuration that the caller isn't aware of. The field mask should be specified as: ``{ paths: "index_config" }``. This call returns a ``google.longrunning.Operation`` which may be used to track the status of the field update. The metadata for the operation will be the type ``FieldOperationMetadata``. To configure the default field settings for the database, use the special ``Field`` with resource name: ``projects/{project_id}/databases/{database_id}/collectionGroups/__default__/fields/*``. Example: >>> from google.cloud import firestore_admin_v1 >>> >>> client = firestore_admin_v1.FirestoreAdminClient() >>> >>> # TODO: Initialize `field`: >>> field = {} >>> >>> response = client.update_field(field) Args: field (Union[dict, ~google.cloud.firestore_admin_v1.types.Field]): Required. The field to be updated. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.firestore_admin_v1.types.Field` update_mask (Union[dict, ~google.cloud.firestore_admin_v1.types.FieldMask]): A mask, relative to the field. If specified, only configuration specified by this field\_mask will be updated in the field. If a dict is provided, it must be of the same form as the protobuf message :class:`~google.cloud.firestore_admin_v1.types.FieldMask` retry (Optional[google.api_core.retry.Retry]): A retry object used to retry requests. If ``None`` is specified, requests will be retried using a default configuration. timeout (Optional[float]): 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. metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata that is provided to the method. Returns: A :class:`~google.cloud.firestore_admin_v1.types.Operation` instance. Raises: google.api_core.exceptions.GoogleAPICallError: If the request failed for any reason. google.api_core.exceptions.RetryError: If the request failed due to a retryable error and retry attempts failed. ValueError: If the parameters are invalid. """ # Wrap the transport method to add retry and timeout logic. if "update_field" not in self._inner_api_calls: self._inner_api_calls[ "update_field"] = google.api_core.gapic_v1.method.wrap_method( self.transport.update_field, default_retry=self._method_configs["UpdateField"].retry, default_timeout=self._method_configs["UpdateField"]. timeout, client_info=self._client_info, ) request = firestore_admin_pb2.UpdateFieldRequest( field=field, update_mask=update_mask) if metadata is None: metadata = [] metadata = list(metadata) try: routing_header = [("field.name", field.name)] except AttributeError: pass else: routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata( routing_header) metadata.append(routing_metadata) return self._inner_api_calls["update_field"](request, retry=retry, timeout=timeout, metadata=metadata)