def test_get_database_ddl(self): # Setup Expected Response expected_response = {} expected_response = spanner_database_admin_pb2.GetDatabaseDdlResponse( **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_database_v1.DatabaseAdminClient() # Setup Request database = client.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]") response = client.get_database_ddl(database) assert expected_response == response assert len(channel.requests) == 1 expected_request = spanner_database_admin_pb2.GetDatabaseDdlRequest( database=database) actual_request = channel.requests[0][1] assert expected_request == actual_request
def get_database_ddl(self, database, options=None): """ Returns the schema of a Cloud Spanner database as a list of formatted DDL statements. This method does not show pending schema updates, those may be queried using the ``Operations`` API. Example: >>> from google.cloud import spanner_admin_database_v1 >>> >>> client = spanner_admin_database_v1.DatabaseAdminClient() >>> >>> database = client.database_path('[PROJECT]', '[INSTANCE]', '[DATABASE]') >>> >>> response = client.get_database_ddl(database) Args: database (str): Required. The database whose schema we wish to get. options (~google.gax.CallOptions): Overrides the default settings for this call, e.g, timeout, retries etc. Returns: A :class:`~google.cloud.spanner_admin_database_v1.types.GetDatabaseDdlResponse` instance. Raises: :exc:`google.gax.errors.GaxError` if the RPC is aborted. :exc:`ValueError` if the parameters are invalid. """ request = spanner_database_admin_pb2.GetDatabaseDdlRequest( database=database) return self._get_database_ddl(request, options)
def test_get_database_ddl(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = spanner_admin_database_v1.DatabaseAdminClient() # Mock request database = client.database_path('[PROJECT]', '[INSTANCE]', '[DATABASE]') # Mock response expected_response = {} expected_response = spanner_database_admin_pb2.GetDatabaseDdlResponse( **expected_response) grpc_stub.GetDatabaseDdl.return_value = expected_response response = client.get_database_ddl(database) self.assertEqual(expected_response, response) grpc_stub.GetDatabaseDdl.assert_called_once() args, kwargs = grpc_stub.GetDatabaseDdl.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = spanner_database_admin_pb2.GetDatabaseDdlRequest( database=database) self.assertEqual(expected_request, actual_request)
def get_database_ddl( self, database, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None, ): """ Returns the schema of a Cloud Spanner database as a list of formatted DDL statements. This method does not show pending schema updates, those may be queried using the ``Operations`` API. Example: >>> from google.cloud import spanner_admin_database_v1 >>> >>> client = spanner_admin_database_v1.DatabaseAdminClient() >>> >>> database = client.database_path('[PROJECT]', '[INSTANCE]', '[DATABASE]') >>> >>> response = client.get_database_ddl(database) Args: database (str): Required. The database whose schema we wish to get. 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_database_v1.types.GetDatabaseDdlResponse` 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_database_ddl" not in self._inner_api_calls: self._inner_api_calls[ "get_database_ddl"] = google.api_core.gapic_v1.method.wrap_method( self.transport.get_database_ddl, default_retry=self._method_configs["GetDatabaseDdl"].retry, default_timeout=self._method_configs["GetDatabaseDdl"]. timeout, client_info=self._client_info, ) request = spanner_database_admin_pb2.GetDatabaseDdlRequest( database=database) return self._inner_api_calls["get_database_ddl"](request, retry=retry, timeout=timeout, metadata=metadata)
def test_get_database_ddl(self): # Setup Expected Response expected_response = {} expected_response = spanner_database_admin_pb2.GetDatabaseDdlResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = spanner_admin_database_v1.DatabaseAdminClient(channel=channel) # Setup Request database = client.database_path('[PROJECT]', '[INSTANCE]', '[DATABASE]') response = client.get_database_ddl(database) assert expected_response == response assert len(channel.requests) == 1 expected_request = spanner_database_admin_pb2.GetDatabaseDdlRequest( database=database) actual_request = channel.requests[0][1] assert expected_request == actual_request