def test_list_backups_defaults(self): from google.cloud.spanner_admin_database_v1 import Backup as BackupPB from google.cloud.spanner_admin_database_v1 import DatabaseAdminClient from google.cloud.spanner_admin_database_v1 import ListBackupsRequest from google.cloud.spanner_admin_database_v1 import ListBackupsResponse api = DatabaseAdminClient(credentials=mock.Mock()) client = _Client(self.PROJECT) client.database_admin_api = api instance = self._make_one(self.INSTANCE_ID, client) backups_pb = ListBackupsResponse(backups=[ BackupPB(name=instance.name + "/backups/op1"), BackupPB(name=instance.name + "/backups/op2"), BackupPB(name=instance.name + "/backups/op3"), ]) lbo_api = api._transport._wrapped_methods[ api._transport.list_backups] = mock.Mock(return_value=backups_pb) backups = instance.list_backups() for backup in backups: self.assertIsInstance(backup, BackupPB) expected_metadata = ( ("google-cloud-resource-prefix", instance.name), ("x-goog-request-params", "parent={}".format(instance.name)), ) lbo_api.assert_called_once_with( ListBackupsRequest(parent=self.INSTANCE_NAME), metadata=expected_metadata, retry=mock.ANY, timeout=mock.ANY, )
def list_backups(self, filter_="", page_size=None): """List backups for the instance. :type filter_: str :param filter_: Optional. A string specifying a filter for which backups to list. :type page_size: int :param page_size: Optional. The maximum number of databases in each page of results from this request. Non-positive values are ignored. Defaults to a sensible value set by the API. :rtype: :class:`~google.api_core.page_iterator.Iterator` :returns: Iterator of :class:`~google.cloud.spanner_v1.backup.Backup` resources within the current instance. """ metadata = _metadata_with_prefix(self.name) request = ListBackupsRequest( parent=self.name, filter=filter_, page_size=page_size, ) page_iter = self._client.database_admin_api.list_backups( request=request, metadata=metadata) return page_iter