Skip to content

chore: update return type for delete snippets #9992

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

Merged
merged 3 commits into from
May 17, 2023
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: 2 additions & 1 deletion scheduler/snippets/delete_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from google.cloud import scheduler


def delete_scheduler_job(project_id: str, location_id: str, job_id: str) -> None:
def delete_scheduler_job(project_id: str, location_id: str, job_id: str) -> bool:
"""Delete a job via the Cloud Scheduler API.

Args:
Expand All @@ -35,5 +35,6 @@ def delete_scheduler_job(project_id: str, location_id: str, job_id: str) -> None
# Use the client to send the job deletion request.
client.delete_job(name=job)
print("Job deleted.")
return True

# [END cloudscheduler_delete_job]
10 changes: 3 additions & 7 deletions scheduler/snippets/job_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,19 @@

import os

from _pytest.capture import CaptureFixture

import create_job
import delete_job

TEST_PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
TEST_LOCATION = os.getenv("LOCATION_ID", "us-central1")


def test_create_job(capsys: CaptureFixture):
def test_create_job():
response = create_job.create_scheduler_job(
TEST_PROJECT_ID, TEST_LOCATION, "my-service"
)
assert response.name

job_name = response.name.split("/")[-1]
delete_job.delete_scheduler_job(TEST_PROJECT_ID, TEST_LOCATION, job_name)

out, _ = capsys.readouterr()
assert "Job deleted." in out
is_deleted = delete_job.delete_scheduler_job(TEST_PROJECT_ID, TEST_LOCATION, job_name)
assert is_deleted
12 changes: 6 additions & 6 deletions servicedirectory/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create_namespace(project_id: str, location: str, namespace_id: str) -> Names


# [START servicedirectory_delete_namespace]
def delete_namespace(project_id: str, location: str, namespace_id: str) -> None:
def delete_namespace(project_id: str, location: str, namespace_id: str) -> bool:
"""Deletes a namespace in the given location.

Args:
Expand All @@ -71,8 +71,8 @@ def delete_namespace(project_id: str, location: str, namespace_id: str) -> None:
namespace_name = client.namespace_path(project_id, location, namespace_id)

client.delete_namespace(name=namespace_name)

print(f"Deleted namespace {namespace_name}.")
return True


# [END servicedirectory_delete_namespace]
Expand Down Expand Up @@ -118,7 +118,7 @@ def create_service(
# [START servicedirectory_delete_service]
def delete_service(
project_id: str, location: str, namespace_id: str, service_id: str
) -> None:
) -> bool:
"""Deletes a service in the given namespace.

Args:
Expand All @@ -133,8 +133,8 @@ def delete_service(
service_name = client.service_path(project_id, location, namespace_id, service_id)

client.delete_service(name=service_name)

print(f"Deleted service {service_name}.")
return True


# [END servicedirectory_delete_service]
Expand Down Expand Up @@ -234,7 +234,7 @@ def delete_endpoint(
namespace_id: str,
service_id: str,
endpoint_id: str,
) -> None:
) -> bool:
"""Deletes a endpoint in the given service.

Args:
Expand All @@ -252,8 +252,8 @@ def delete_endpoint(
)

client.delete_endpoint(name=endpoint_name)

print(f"Deleted endpoint {endpoint_name}.")
return True


# [END servicedirectory_delete_endpoint]
25 changes: 9 additions & 16 deletions servicedirectory/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from os import environ
import uuid

from _pytest.capture import CaptureFixture
import backoff
from google.api_core.exceptions import InternalServerError, NotFound, ServiceUnavailable
from google.cloud import servicedirectory_v1
Expand Down Expand Up @@ -95,30 +94,24 @@ def test_resolve_service() -> None:
@backoff.on_exception(
backoff.expo, (InternalServerError, ServiceUnavailable), max_tries=5
)
def test_delete_endpoint(capsys: CaptureFixture) -> None:
snippets.delete_endpoint(
def test_delete_endpoint() -> None:
is_deleted = snippets.delete_endpoint(
PROJECT_ID, LOCATION_ID, NAMESPACE_ID, SERVICE_ID, ENDPOINT_ID
)

out, _ = capsys.readouterr()
assert ENDPOINT_ID in out
assert is_deleted


@backoff.on_exception(
backoff.expo, (InternalServerError, ServiceUnavailable), max_tries=5
)
def test_delete_service(capsys: CaptureFixture) -> None:
snippets.delete_service(PROJECT_ID, LOCATION_ID, NAMESPACE_ID, SERVICE_ID)

out, _ = capsys.readouterr()
assert SERVICE_ID in out
def test_delete_service() -> None:
is_deleted = snippets.delete_service(PROJECT_ID, LOCATION_ID, NAMESPACE_ID, SERVICE_ID)
assert is_deleted


@backoff.on_exception(
backoff.expo, (InternalServerError, ServiceUnavailable), max_tries=5
)
def test_delete_namespace(capsys: CaptureFixture) -> None:
snippets.delete_namespace(PROJECT_ID, LOCATION_ID, NAMESPACE_ID)

out, _ = capsys.readouterr()
assert NAMESPACE_ID in out
def test_delete_namespace() -> None:
is_deleted = snippets.delete_namespace(PROJECT_ID, LOCATION_ID, NAMESPACE_ID)
assert is_deleted
2 changes: 1 addition & 1 deletion workflows/cloud-client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def execute_workflow(
# Wait for execution to finish, then print results.
execution_finished = False
backoff_delay = 1 # Start wait with delay of 1 second
print("Poll every second for result...")
print("Poll for result...")
while not execution_finished:
execution = execution_client.get_execution(request={"name": response.name})
execution_finished = execution.state != executions.Execution.State.ACTIVE
Expand Down