Skip to content

Commit

Permalink
chore: use python-samples-reviewers (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcf-owl-bot[bot] authored Jan 6, 2022
1 parent 817486e commit 3e5bae9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
13 changes: 8 additions & 5 deletions datacatalog/snippets/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,18 @@ def policy_tag_manager_client(credentials):
@pytest.fixture
def random_taxonomy_display_name(policy_tag_manager_client, project_id):
now = datetime.datetime.now()
random_display_name = f'example_taxonomy' \
f'_{now.strftime("%Y%m%d%H%M%S")}' \
f'_{uuid.uuid4().hex[:8]}'
random_display_name = (
f"example_taxonomy"
f'_{now.strftime("%Y%m%d%H%M%S")}'
f"_{uuid.uuid4().hex[:8]}"
)
yield random_display_name
parent = datacatalog_v1.PolicyTagManagerClient.common_location_path(
project_id, 'us'
project_id, "us"
)
taxonomies = policy_tag_manager_client.list_taxonomies(parent=parent)
taxonomy = next(
(t for t in taxonomies if t.display_name == random_display_name), None)
(t for t in taxonomies if t.display_name == random_display_name), None
)
if taxonomy:
policy_tag_manager_client.delete_taxonomy(name=taxonomy.name)
7 changes: 3 additions & 4 deletions datacatalog/snippets/data_catalog_ptm_create_taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ def create_taxonomy(
# TODO(developer): Set project_id to the ID of the project the
# taxonomy will belong to.
project_id: str = "your-project-id",

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

# TODO(developer): Set the display name of the taxonomy.
display_name: str = "example-taxonomy",
):
Expand All @@ -41,10 +39,11 @@ def create_taxonomy(
# TODO(developer): Construct a full Taxonomy object to send to the API.
taxonomy = datacatalog_v1.Taxonomy()
taxonomy.display_name = display_name
taxonomy.description = 'This Taxonomy represents ...'
taxonomy.description = "This Taxonomy represents ..."

# Send the taxonomy to the API for creation.
taxonomy = client.create_taxonomy(parent=parent, taxonomy=taxonomy)
print(f'Created taxonomy {taxonomy.name}')
print(f"Created taxonomy {taxonomy.name}")


# [END data_catalog_ptm_create_taxonomy]
14 changes: 6 additions & 8 deletions datacatalog/snippets/data_catalog_ptm_create_taxonomy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
import data_catalog_ptm_create_taxonomy


def test_create_taxonomy(capsys,
project_id: str,
random_taxonomy_display_name: str):
def test_create_taxonomy(capsys, project_id: str, random_taxonomy_display_name: str):

data_catalog_ptm_create_taxonomy.create_taxonomy(
project_id=project_id, location_id="us", display_name=random_taxonomy_display_name)
out, _ = capsys.readouterr()
assert (
f'Created taxonomy projects/{project_id}/locations/us/taxonomies/'
in out
project_id=project_id,
location_id="us",
display_name=random_taxonomy_display_name,
)
out, _ = capsys.readouterr()
assert f"Created taxonomy projects/{project_id}/locations/us/taxonomies/" in out

0 comments on commit 3e5bae9

Please sign in to comment.