def get_instance(self, name, options=None): """ Gets information about a particular instance. Example: >>> from google.cloud import spanner_admin_instance_v1 >>> >>> client = spanner_admin_instance_v1.InstanceAdminClient() >>> >>> name = client.instance_path('[PROJECT]', '[INSTANCE]') >>> >>> response = client.get_instance(name) Args: name (str): Required. The name of the requested instance. Values are of the form ``projects/<project>/instances/<instance>``. options (~google.gax.CallOptions): Overrides the default settings for this call, e.g, timeout, retries etc. Returns: A :class:`~google.cloud.spanner_admin_instance_v1.types.Instance` instance. Raises: :exc:`google.gax.errors.GaxError` if the RPC is aborted. :exc:`ValueError` if the parameters are invalid. """ request = spanner_instance_admin_pb2.GetInstanceRequest(name=name) return self._get_instance(request, options)
def test_get_instance(self): # Setup Expected Response name_2 = "name2-1052831874" config = "config-1354792126" display_name = "displayName1615086568" node_count = 1539922066 expected_response = { "name": name_2, "config": config, "display_name": display_name, "node_count": node_count, } expected_response = spanner_instance_admin_pb2.Instance(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = spanner_admin_instance_v1.InstanceAdminClient() # Setup Request name = client.instance_path("[PROJECT]", "[INSTANCE]") response = client.get_instance(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = spanner_instance_admin_pb2.GetInstanceRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_instance(self): # Setup Expected Response name_2 = 'name2-1052831874' config = 'config-1354792126' display_name = 'displayName1615086568' node_count = 1539922066 expected_response = { 'name': name_2, 'config': config, 'display_name': display_name, 'node_count': node_count } expected_response = spanner_instance_admin_pb2.Instance( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = spanner_admin_instance_v1.InstanceAdminClient(channel=channel) # Setup Request name = client.instance_path('[PROJECT]', '[INSTANCE]') response = client.get_instance(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = spanner_instance_admin_pb2.GetInstanceRequest( name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def get_instance( self, name, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): """ Gets information about a particular instance. Example: >>> from google.cloud import spanner_admin_instance_v1 >>> >>> client = spanner_admin_instance_v1.InstanceAdminClient() >>> >>> name = client.instance_path('[PROJECT]', '[INSTANCE]') >>> >>> response = client.get_instance(name) Args: name (str): Required. The name of the requested instance. Values are of the form ``projects/<project>/instances/<instance>``. retry (Optional[google.api_core.retry.Retry]): A retry object used to retry requests. If ``None`` is specified, requests will not be retried. 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.spanner_admin_instance_v1.types.Instance` 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 "get_instance" not in self._inner_api_calls: self._inner_api_calls[ "get_instance"] = google.api_core.gapic_v1.method.wrap_method( self.transport.get_instance, default_retry=self._method_configs["GetInstance"].retry, default_timeout=self._method_configs["GetInstance"]. timeout, client_info=self._client_info, ) request = spanner_instance_admin_pb2.GetInstanceRequest(name=name) return self._inner_api_calls["get_instance"](request, retry=retry, timeout=timeout, metadata=metadata)
def test_get_instance(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = spanner_admin_instance_v1.InstanceAdminClient() # Mock request name = client.instance_path('[PROJECT]', '[INSTANCE]') # Mock response name_2 = 'name2-1052831874' config = 'config-1354792126' display_name = 'displayName1615086568' node_count = 1539922066 expected_response = { 'name': name_2, 'config': config, 'display_name': display_name, 'node_count': node_count } expected_response = spanner_instance_admin_pb2.Instance( **expected_response) grpc_stub.GetInstance.return_value = expected_response response = client.get_instance(name) self.assertEqual(expected_response, response) grpc_stub.GetInstance.assert_called_once() args, kwargs = grpc_stub.GetInstance.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = spanner_instance_admin_pb2.GetInstanceRequest( name=name) self.assertEqual(expected_request, actual_request)