Skip to content

Commit

Permalink
feat: expose extra fields in ExtendedOperation (#351)
Browse files Browse the repository at this point in the history
The operation wrapped by ExtendedOperation may define other fields or methods
that the user may wish to use.
  • Loading branch information
software-dov authored Mar 8, 2022
1 parent 07747ca commit 9abc6f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions google/api_core/extended_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def error_code(self):
def error_message(self):
return self._extended_operation.error_message

def __getattr__(self, name):
return getattr(self._extended_operation, name)

def done(self, retry=polling.DEFAULT_RETRY):
self._refresh_and_update(retry)
return self._extended_operation.done
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/test_extended_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class StatusCode(enum.Enum):
status: StatusCode
error_code: typing.Optional[int] = None
error_message: typing.Optional[str] = None
armor_class: typing.Optional[int] = None

# Note: in generated clients, this property must be generated for each
# extended operation message type.
Expand Down Expand Up @@ -180,3 +181,23 @@ def test_error():

with pytest.raises(exceptions.GoogleAPICallError):
ex_op.result()


def test_pass_through():
responses = [
CustomOperation(
name=TEST_OPERATION_NAME,
status=CustomOperation.StatusCode.PENDING,
armor_class=10,
),
CustomOperation(
name=TEST_OPERATION_NAME,
status=CustomOperation.StatusCode.DONE,
armor_class=20,
),
]
ex_op, _, _ = make_extended_operation(responses)

assert ex_op.armor_class == 10
ex_op.result()
assert ex_op.armor_class == 20

0 comments on commit 9abc6f4

Please sign in to comment.