def delete_snapshot(self, snapshot, options=None): """ Removes an existing snapshot. All messages retained in the snapshot are immediately dropped. After a snapshot is deleted, a new one may be created with the same name, but the new one has no association with the old snapshot or its subscription, unless the same subscription is specified. Example: >>> from google.cloud.gapic.pubsub.v1 import subscriber_client >>> client = subscriber_client.SubscriberClient() >>> snapshot = client.snapshot_path('[PROJECT]', '[SNAPSHOT]') >>> client.delete_snapshot(snapshot) Args: snapshot (string): The name of the snapshot to delete. Format is ``projects/{project}/snapshots/{snap}``. options (:class:`google.gax.CallOptions`): Overrides the default settings for this call, e.g, timeout, retries etc. Raises: :exc:`google.gax.errors.GaxError` if the RPC is aborted. :exc:`ValueError` if the parameters are invalid. """ # Create the request object. request = pubsub_pb2.DeleteSnapshotRequest(snapshot=snapshot) self._delete_snapshot(request, options)
def test_delete_snapshot(self, mock_create_stub): # Mock gRPC layer grpc_stub = mock.Mock() mock_create_stub.return_value = grpc_stub client = subscriber_client.SubscriberClient() # Mock request snapshot = client.snapshot_path('[PROJECT]', '[SNAPSHOT]') client.delete_snapshot(snapshot) grpc_stub.DeleteSnapshot.assert_called_once() args, kwargs = grpc_stub.DeleteSnapshot.call_args self.assertEqual(len(args), 2) self.assertEqual(len(kwargs), 1) self.assertIn('metadata', kwargs) actual_request = args[0] expected_request = pubsub_pb2.DeleteSnapshotRequest(snapshot=snapshot) self.assertEqual(expected_request, actual_request)