Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
fix(samples): add sample for create_taxonomy
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardolsmendes committed Jan 7, 2021
1 parent fda528a commit d0f34ba
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
5 changes: 5 additions & 0 deletions samples/tests/conftest.py
Expand Up @@ -27,6 +27,11 @@ def client(credentials):
return datacatalog_v1beta1.DataCatalogClient(credentials=credentials)


@pytest.fixture(scope="session")
def policy_tag_manager_client(credentials):
return datacatalog_v1beta1.PolicyTagManagerClient(credentials=credentials)


@pytest.fixture(scope="session")
def default_credentials():
return google.auth.default()
Expand Down
27 changes: 27 additions & 0 deletions samples/tests/test_create_taxonomy.py
@@ -0,0 +1,27 @@
# Copyright 2020 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 ..v1beta1 import create_taxonomy


def test_create_taxonomy(capsys, policy_tag_manager_client, project_id):

create_taxonomy.create_taxonomy(policy_tag_manager_client, project_id)
out, err = capsys.readouterr()
assert (
"Created taxonomy"
" projects/{}/locations/{}/taxonomies/".format(project_id, "us")
in out
)
45 changes: 45 additions & 0 deletions samples/v1beta1/create_taxonomy.py
@@ -0,0 +1,45 @@
# Copyright 2020 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.


def create_taxonomy(client, project_id):

# [START datacatalog_create_taxonomy_tag]
from google.cloud import datacatalog_v1beta1

# TODO(developer): Construct a Policy Tag Manager client object.
# client = datacatalog_v1beta1.PolicyTagManagerClient()

# TODO(developer): Set project_id to the ID of the project the
# taxonomy will belong to.
# project_id = "your-project-id"

# TODO(developer): Specify the geographic location where the
# taxonomy should reside.
location_id = "us"

# Construct a full location path to be the parent of the taxonomy.
parent = datacatalog_v1beta1.PolicyTagManagerClient.location_path(
project_id, location_id
)

# Construct a full Taxonomy object to send to the API.
taxonomy = datacatalog_v1beta1.types.Taxonomy()
taxonomy.display_name = "My Taxonomy"
taxonomy.description = "This Taxonomy represents ..."

# Send the taxonomy to the API for creation.
taxonomy = client.create_taxonomy(parent, taxonomy) # Make an API request.
print("Created taxonomy {}".format(taxonomy.name))
# [END datacatalog_create_taxonomy_tag]

0 comments on commit d0f34ba

Please sign in to comment.