Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose extra fields in ExtendedOperation #351

Merged
merged 2 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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