Skip to content

Commit

Permalink
docs(samples): add entry group greation to custom entry sample (#215)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthonios Partheniou <[email protected]>
  • Loading branch information
steffnay and parthea authored Sep 2, 2021
1 parent 6cfd2ec commit 0041c18
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
19 changes: 0 additions & 19 deletions datacatalog/snippets/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,3 @@ def random_existing_tag_template_id(client, project_id, resources_to_delete):
)
yield random_tag_template_id
resources_to_delete["templates"].append(random_tag_template.name)


@pytest.fixture
def random_existing_entry_group(
client, project_id, random_entry_group_id, resources_to_delete
):
entry_group_obj = datacatalog_v1.types.EntryGroup()
entry_group_obj.display_name = f"python_sample_{temp_suffix()}"
entry_group_obj.description = "Data Catalog samples test entry group."

entry_group = datacatalog.create_entry_group(
parent=datacatalog_v1.DataCatalogClient.common_location_path(
project_id, LOCATION
),
entry_group_id=random_entry_group_id,
entry_group=entry_group_obj,
)
yield entry_group
resources_to_delete["entry_groups"].append(entry_group.name)
25 changes: 20 additions & 5 deletions datacatalog/snippets/create_custom_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,39 @@ def create_custom_entry(override_values):

# Google Cloud Platform project.
project_id = "my-project"
# Entry group to be created.
# For sample code demonstrating entry group creation, see quickstart:
# https://cloud.google.com/data-catalog/docs/quickstart-tagging
entry_group_name = "my_existing_entry_group"
# Entry Group to be created.
entry_group_id = "my_new_entry_group_id"
# Entry to be created.
entry_id = "my_new_entry_id"
# Currently, Data Catalog stores metadata in the us-central1 region.
location = "us-central1"

# [END data_catalog_create_custom_entry]

# To facilitate testing, we replace values with alternatives
# provided by the testing harness.
project_id = override_values.get("project_id", project_id)
entry_group_name = override_values.get("entry_group_name", entry_group_name)
entry_id = override_values.get("entry_id", entry_id)
entry_group_id = override_values.get("entry_group_id", entry_group_id)

# [START data_catalog_create_custom_entry]
datacatalog = datacatalog_v1.DataCatalogClient()

# Create an Entry Group.
entry_group_obj = datacatalog_v1.types.EntryGroup()
entry_group_obj.display_name = "My awesome Entry Group"
entry_group_obj.description = "This Entry Group represents an external system"

entry_group = datacatalog.create_entry_group(
parent=datacatalog_v1.DataCatalogClient.common_location_path(
project_id, location
),
entry_group_id=entry_group_id,
entry_group=entry_group_obj,
)
entry_group_name = entry_group.name
print("Created entry group: {}".format(entry_group_name))

# Create an Entry.
entry = datacatalog_v1.types.Entry()
entry.user_specified_system = "onprem_data_system"
Expand Down
7 changes: 5 additions & 2 deletions datacatalog/snippets/create_custom_entry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@ def test_create_custom_entry(
capsys,
client,
project_id,
random_existing_entry_group,
random_entry_group_id,
random_entry_id,
resources_to_delete,
):
location = "us-central1"
override_values = {
"project_id": project_id,
"entry_group_name": random_existing_entry_group.name,
"entry_id": random_entry_id,
"entry_group_id": random_entry_group_id,
}
expected_entry_group = client.entry_group_path(
project_id, location, random_entry_group_id
)
expected_entry = client.entry_path(
project_id, location, random_entry_group_id, random_entry_id
)
create_custom_entry.create_custom_entry(override_values)
out, err = capsys.readouterr()
assert f"Created entry group: {expected_entry_group}" in out
assert f"Created entry: {expected_entry}" in out
resources_to_delete["entries"].append(expected_entry)

0 comments on commit 0041c18

Please sign in to comment.