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: Add metadata SDK sample for delete method. #1530

21 changes: 21 additions & 0 deletions samples/model-builder/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,27 @@ def mock_pipeline_job_create(mock_pipeline_job):
yield mock_pipeline_job_create


@pytest.fixture
def mock_artifact_delete():
with patch.object(aiplatform.Artifact, "delete") as mock_artifact_delete:
mock_artifact_delete.return_value = None
yield mock_artifact_delete


@pytest.fixture
def mock_execution_delete():
with patch.object(aiplatform.Execution, "delete") as mock_execution_delete:
mock_execution_delete.return_value = None
yield mock_execution_delete


@pytest.fixture
def mock_context_delete():
with patch.object(aiplatform.Context, "delete") as mock_context_delete:
mock_context_delete.return_value = None
yield mock_context_delete


@pytest.fixture
def mock_pipeline_job_submit(mock_pipeline_job):
with patch.object(mock_pipeline_job, "submit") as mock_pipeline_job_submit:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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
#
# https://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.

from google.cloud import aiplatform


# [START aiplatform_sdk_delete_artifact_sample]
def delete_artifact_sample(
artifact_id: str,
project: str,
location: str,
):
artifact = aiplatform.Artifact.get(
resource_id=artifact_id, project=project, location=location
)
artifact.delete()

# [END aiplatform_sdk_delete_artifact_sample]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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
#
# https://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 delete_artifact_sample

import test_constants


def test_delete_artifact_sample(mock_artifact, mock_artifact_get):
delete_artifact_sample.delete_artifact_sample(
artifact_id=test_constants.RESOURCE_ID,
project=test_constants.PROJECT,
location=test_constants.LOCATION,
)

mock_artifact_get.assert_called_with(
resource_id=test_constants.RESOURCE_ID,
project=test_constants.PROJECT,
location=test_constants.LOCATION,
)
29 changes: 29 additions & 0 deletions samples/model-builder/experiment_tracking/delete_context_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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
#
# https://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.

from google.cloud import aiplatform


# [START aiplatform_sdk_delete_context_sample]
def delete_context_sample(
context_id: str,
project: str,
location: str,
):
context = aiplatform.Context.get(
resource_id=context_id, project=project, location=location
)
context.delete()

# [END aiplatform_sdk_delete_context_sample]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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
#
# https://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 delete_context_sample

import test_constants


def test_delete_context_sample(mock_context, mock_context_get):
delete_context_sample.delete_context_sample(
context_id=test_constants.RESOURCE_ID,
project=test_constants.PROJECT,
location=test_constants.LOCATION,
)

mock_context_get.assert_called_with(
resource_id=test_constants.RESOURCE_ID,
project=test_constants.PROJECT,
location=test_constants.LOCATION,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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
#
# https://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.

from google.cloud import aiplatform


# [START aiplatform_sdk_delete_execution_sample]
def delete_execution_sample(
execution_id: str,
project: str,
location: str,
):
execution = aiplatform.Execution.get(
resource_id=execution_id, project=project, location=location
)
execution.delete()

# [END aiplatform_sdk_delete_execution_sample]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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
#
# https://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 delete_execution_sample

import test_constants


def test_delete_execution_sample(mock_execution, mock_execution_get):
delete_execution_sample.delete_execution_sample(
execution_id=test_constants.RESOURCE_ID,
project=test_constants.PROJECT,
location=test_constants.LOCATION,
)

mock_execution_get.assert_called_with(
resource_id=test_constants.RESOURCE_ID,
project=test_constants.PROJECT,
location=test_constants.LOCATION,
)