Skip to content

Commit

Permalink
docs: add get_operation code snippets (#12)
Browse files Browse the repository at this point in the history
* Add get_operation code snippets

* update comment

* docs: add sync api samples with json request (#13)

* add code snippets for sync and async api

* remove async test samples

* use f-string

* change project_id to input arg

* add noxfile

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* rename noxfile and add requirements

* rm noxfile

* rm noxfile local

* add root noxfile

* Update noxfile.py

* Update noxfile.py

* Update noxfile.py

Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com>

* Apply suggestions from code review

* Update noxfile.py

* Update noxfile.py

* Update noxfile.py

* Update noxfile.py

* Update noxfile.py

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* Add commit to trigger kokoro

* add indentation

* add type annotations

Co-authored-by: Jeffrey Rennie <rennie@google.com>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>

* rebase and add type annotations

* fix operation_id type

* Update samples/snippets/get_operation.py

Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>

* Update samples/snippets/get_operation_test.py

Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>

* move TODO outside func, create operation in test

* lint fix

* fix asyncmodelconfig

* change model_config to list

* add blank line

* change request to dict

* change parent to project id

* remove model config

* Update samples/snippets/get_operation.py

Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>

* add TODO back

Co-authored-by: Jeffrey Rennie <rennie@google.com>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
  • Loading branch information
6 people authored Apr 8, 2022
1 parent c164666 commit 6fd3c4c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START cloudoptimization_get_operation]
from google.cloud import optimization_v1


def get_operation(operation_full_id: str) -> None:
"""Get operation details and status."""
# TODO(developer): Uncomment and set the following variables
# operation_full_id = \
# "projects/[projectId]/locations/operations/[operationId]"

client = optimization_v1.FleetRoutingClient()
# Get the latest state of a long-running operation.
response = client.transport.operations_client.get_operation(operation_full_id)

print("Name: {}".format(response.name))
print("Operation details:")
print(response)
# [END cloudoptimization_get_operation]
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import google.auth
from google.cloud import optimization_v1
import pytest

import get_operation


@pytest.fixture(scope="function")
def operation_id() -> str:
fleet_routing_client = optimization_v1.FleetRoutingClient()

_, project_id = google.auth.default()
fleet_routing_request = {"parent": f"projects/{project_id}"}

# Make the request
operation = fleet_routing_client.batch_optimize_tours(fleet_routing_request)

yield operation.operation.name


def test_get_operation_status(capsys: pytest.LogCaptureFixture, operation_id: str) -> None:
get_operation.get_operation(operation_id)
out, _ = capsys.readouterr()
assert "Operation details" in out

0 comments on commit 6fd3c4c

Please sign in to comment.