diff --git a/samples/snippets/inspect_content.py b/samples/snippets/inspect_content.py index 336f7981..b1e97ae3 100644 --- a/samples/snippets/inspect_content.py +++ b/samples/snippets/inspect_content.py @@ -473,7 +473,7 @@ def inspect_gcs_file( } operation = dlp.create_dlp_job(parent, inspect_job=inspect_job) - + print("Inspection operation started: {}".format(operation.name)) # Create a Pub/Sub client and find the subscription. The subscription is # expected to already be listening to the topic. subscriber = google.cloud.pubsub.SubscriberClient() diff --git a/samples/snippets/inspect_content_test.py b/samples/snippets/inspect_content_test.py index d444c22e..ad493ecc 100644 --- a/samples/snippets/inspect_content_test.py +++ b/samples/snippets/inspect_content_test.py @@ -20,6 +20,7 @@ import google.api_core.exceptions import google.cloud.bigquery import google.cloud.datastore +import google.cloud.dlp_v2 import google.cloud.exceptions import google.cloud.pubsub import google.cloud.storage @@ -94,9 +95,7 @@ def subscription_id(topic_id): # Subscribes to a topic. subscriber = google.cloud.pubsub.SubscriberClient() topic_path = subscriber.topic_path(GCLOUD_PROJECT, topic_id) - subscription_path = subscriber.subscription_path( - GCLOUD_PROJECT, SUBSCRIPTION_ID - ) + subscription_path = subscriber.subscription_path(GCLOUD_PROJECT, SUBSCRIPTION_ID) try: subscriber.create_subscription(subscription_path, topic_path) except google.api_core.exceptions.AlreadyExists: @@ -290,7 +289,6 @@ def test_inspect_image_file(capsys): assert "Info type: PHONE_NUMBER" in out -@flaky def test_inspect_gcs_file(bucket, topic_id, subscription_id, capsys): inspect_content.inspect_gcs_file( GCLOUD_PROJECT, @@ -303,10 +301,14 @@ def test_inspect_gcs_file(bucket, topic_id, subscription_id, capsys): ) out, _ = capsys.readouterr() - assert "Info type: EMAIL_ADDRESS" in out + assert "Inspection operation started" in out + # Cancel the operation + operation_id = out.split("Inspection operation started: ")[1].split("\n")[0] + print(operation_id) + client = google.cloud.dlp_v2.DlpServiceClient() + client.cancel_dlp_job(operation_id) -@flaky def test_inspect_gcs_file_with_custom_info_types( bucket, topic_id, subscription_id, capsys ): @@ -326,14 +328,16 @@ def test_inspect_gcs_file_with_custom_info_types( ) out, _ = capsys.readouterr() - assert "Info type: CUSTOM_DICTIONARY_0" in out - assert "Info type: CUSTOM_REGEX_0" in out + assert "Inspection operation started" in out + # Cancel the operation + operation_id = out.split("Inspection operation started: ")[1].split("\n")[0] + print(operation_id) + client = google.cloud.dlp_v2.DlpServiceClient() + client.cancel_dlp_job(operation_id) -@flaky -def test_inspect_gcs_file_no_results( - bucket, topic_id, subscription_id, capsys -): + +def test_inspect_gcs_file_no_results(bucket, topic_id, subscription_id, capsys): inspect_content.inspect_gcs_file( GCLOUD_PROJECT, bucket.name, @@ -345,7 +349,13 @@ def test_inspect_gcs_file_no_results( ) out, _ = capsys.readouterr() - assert "No findings" in out + + assert "Inspection operation started" in out + # Cancel the operation + operation_id = out.split("Inspection operation started: ")[1].split("\n")[0] + print(operation_id) + client = google.cloud.dlp_v2.DlpServiceClient() + client.cancel_dlp_job(operation_id) @pytest.mark.skip(reason="nondeterministically failing") @@ -363,7 +373,6 @@ def test_inspect_gcs_image_file(bucket, topic_id, subscription_id, capsys): assert "Info type: EMAIL_ADDRESS" in out -@flaky def test_inspect_gcs_multiple_files(bucket, topic_id, subscription_id, capsys): inspect_content.inspect_gcs_file( GCLOUD_PROJECT, @@ -375,14 +384,17 @@ def test_inspect_gcs_multiple_files(bucket, topic_id, subscription_id, capsys): ) out, _ = capsys.readouterr() - assert "Info type: EMAIL_ADDRESS" in out - assert "Info type: PHONE_NUMBER" in out + + assert "Inspection operation started" in out + # Cancel the operation + operation_id = out.split("Inspection operation started: ")[1].split("\n")[0] + print(operation_id) + client = google.cloud.dlp_v2.DlpServiceClient() + client.cancel_dlp_job(operation_id) @flaky -def test_inspect_datastore( - datastore_project, topic_id, subscription_id, capsys -): +def test_inspect_datastore(datastore_project, topic_id, subscription_id, capsys): @eventually_consistent.call def _(): inspect_content.inspect_datastore( @@ -402,17 +414,19 @@ def _(): def test_inspect_datastore_no_results( datastore_project, topic_id, subscription_id, capsys ): - inspect_content.inspect_datastore( - GCLOUD_PROJECT, - datastore_project, - DATASTORE_KIND, - topic_id, - subscription_id, - ["PHONE_NUMBER"], - ) + @eventually_consistent.call + def _(): + inspect_content.inspect_datastore( + GCLOUD_PROJECT, + datastore_project, + DATASTORE_KIND, + topic_id, + subscription_id, + ["PHONE_NUMBER"], + ) - out, _ = capsys.readouterr() - assert "No findings" in out + out, _ = capsys.readouterr() + assert "No findings" in out @pytest.mark.skip(reason="unknown issue") diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 3cdb8fb8..ca423e2c 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,5 +1,5 @@ -google-cloud-dlp==0.12.1 +google-cloud-dlp==0.13.0 google-cloud-storage==1.26.0 -google-cloud-pubsub==1.0.0 -google-cloud-datastore==1.9.0 -google-cloud-bigquery==1.20.0 +google-cloud-pubsub==1.3.1 +google-cloud-datastore==1.11.0 +google-cloud-bigquery==1.24.0