Skip to content

Commit

Permalink
test: unskip list_backup_operations sample test (#170)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
larkee and larkee committed Nov 23, 2020
1 parent 7f4d478 commit 864f09c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 17 additions & 2 deletions google/cloud/spanner_v1/instance.py
Expand Up @@ -14,6 +14,7 @@

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

import google.api_core.operation
import re

from google.cloud.spanner_admin_instance_v1 import Instance as InstancePB
Expand Down Expand Up @@ -465,7 +466,7 @@ def list_backup_operations(self, filter_="", page_size=None):
page_iter = self._client.database_admin_api.list_backup_operations(
request=request, metadata=metadata
)
return page_iter
return map(self._item_to_operation, page_iter)

def list_database_operations(self, filter_="", page_size=None):
"""List database operations for the instance.
Expand Down Expand Up @@ -493,4 +494,18 @@ def list_database_operations(self, filter_="", page_size=None):
page_iter = self._client.database_admin_api.list_database_operations(
request=request, metadata=metadata
)
return page_iter
return map(self._item_to_operation, page_iter)

def _item_to_operation(self, operation_pb):
"""Convert an operation protobuf to the native object.
:type operation_pb: :class:`~google.longrunning.operations.Operation`
:param operation_pb: An operation returned from the API.
:rtype: :class:`~google.api_core.operation.Operation`
:returns: The next operation in the page.
"""
operations_client = self._client.database_admin_api.transport.operations_client
metadata_type = _type_string_to_type_pb(operation_pb.metadata.type_url)
response_type = _OPERATION_RESPONSE_TYPES[metadata_type]
return google.api_core.operation.from_gapic(
operation_pb, operations_client, response_type, metadata_type=metadata_type
)
6 changes: 0 additions & 6 deletions samples/samples/backup_sample_test.py
Expand Up @@ -79,12 +79,6 @@ def test_restore_database(capsys):
assert BACKUP_ID in out


@pytest.mark.skip(
reason=(
"failing due to a production bug"
"https://github.com/googleapis/python-spanner/issues/149"
)
)
def test_list_backup_operations(capsys, spanner_instance):
backup_sample.list_backup_operations(INSTANCE_ID, DATABASE_ID)
out, _ = capsys.readouterr()
Expand Down

0 comments on commit 864f09c

Please sign in to comment.