Skip to content

Commit 864f09c

Browse files
authored
test: unskip list_backup_operations sample test (googleapis#170)
* test: unskip list_backup_operations sample test * fix: map operation protos to api_core wrapper * style: fix lint error Co-authored-by: larkee <larkee@users.noreply.github.com>
1 parent 7f4d478 commit 864f09c

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

google/cloud/spanner_v1/instance.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
"""User friendly container for Cloud Spanner Instance."""
1616

17+
import google.api_core.operation
1718
import re
1819

1920
from google.cloud.spanner_admin_instance_v1 import Instance as InstancePB
@@ -465,7 +466,7 @@ def list_backup_operations(self, filter_="", page_size=None):
465466
page_iter = self._client.database_admin_api.list_backup_operations(
466467
request=request, metadata=metadata
467468
)
468-
return page_iter
469+
return map(self._item_to_operation, page_iter)
469470

470471
def list_database_operations(self, filter_="", page_size=None):
471472
"""List database operations for the instance.
@@ -493,4 +494,18 @@ def list_database_operations(self, filter_="", page_size=None):
493494
page_iter = self._client.database_admin_api.list_database_operations(
494495
request=request, metadata=metadata
495496
)
496-
return page_iter
497+
return map(self._item_to_operation, page_iter)
498+
499+
def _item_to_operation(self, operation_pb):
500+
"""Convert an operation protobuf to the native object.
501+
:type operation_pb: :class:`~google.longrunning.operations.Operation`
502+
:param operation_pb: An operation returned from the API.
503+
:rtype: :class:`~google.api_core.operation.Operation`
504+
:returns: The next operation in the page.
505+
"""
506+
operations_client = self._client.database_admin_api.transport.operations_client
507+
metadata_type = _type_string_to_type_pb(operation_pb.metadata.type_url)
508+
response_type = _OPERATION_RESPONSE_TYPES[metadata_type]
509+
return google.api_core.operation.from_gapic(
510+
operation_pb, operations_client, response_type, metadata_type=metadata_type
511+
)

samples/samples/backup_sample_test.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ def test_restore_database(capsys):
7979
assert BACKUP_ID in out
8080

8181

82-
@pytest.mark.skip(
83-
reason=(
84-
"failing due to a production bug"
85-
"https://github.com/googleapis/python-spanner/issues/149"
86-
)
87-
)
8882
def test_list_backup_operations(capsys, spanner_instance):
8983
backup_sample.list_backup_operations(INSTANCE_ID, DATABASE_ID)
9084
out, _ = capsys.readouterr()

0 commit comments

Comments
 (0)