From 6d395a86a94a7360713b77d439e163fbf6fe6e83 Mon Sep 17 00:00:00 2001 From: Brendan Lundy Date: Thu, 20 Jun 2019 14:36:25 -0700 Subject: [PATCH] All of the negative vision vpc sc tests should use the same file. (#8439) * All of the negative vision vpc sc tests should use the same file. * One more negative vision vpc sc test image reference to update. Also increase the lro waiting seconds a bit to be safe. --- packages/google-cloud-vision/tests/system.py | 50 +++++++------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/packages/google-cloud-vision/tests/system.py b/packages/google-cloud-vision/tests/system.py index 2416ccd5d6f8..ad34c47b6575 100644 --- a/packages/google-cloud-vision/tests/system.py +++ b/packages/google-cloud-vision/tests/system.py @@ -150,7 +150,7 @@ def test_detect_logos_async(self): response = self.client.async_batch_annotate_images([request], output_config) # Wait for the operation to complete. - lro_waiting_seconds = 60 + lro_waiting_seconds = 90 start_time = time.time() while not response.done() and (time.time() - start_time) < lro_waiting_seconds: time.sleep(1) @@ -209,7 +209,7 @@ def test_async_batch_annotate_files(self): response = self.client.async_batch_annotate_files([request]) # Wait for the operation to complete. - lro_waiting_seconds = 60 + lro_waiting_seconds = 90 start_time = time.time() while not response.done() and (time.time() - start_time) < lro_waiting_seconds: time.sleep(1) @@ -815,6 +815,10 @@ class TestVisionClientVpcsc(VisionSystemTestBase): # Tests to verify Vision API methods are blocked by VPC SC when trying to access a gcs resource outside of a secure perimeter. def setUp(self): VisionSystemTestBase.setUp(self) + self.blocked_file = "LC08/01_$folder$" + self.gcs_uri_blocked_file = "gs://{bucket}/{file}".format( + bucket=BUCKET_OUTSIDE, file=self.blocked_file + ) self._verify_vpc_sc_blocks_gcs_bucket() self.gcs_read_error_message = "Error opening file: gs://" self.gcs_write_error_message = "Error writing final output to: gs://" @@ -824,7 +828,7 @@ def _verify_vpc_sc_blocks_gcs_bucket(self): try: storage_client = storage.Client() outside_bucket = storage_client.get_bucket(BUCKET_OUTSIDE) - blob = outside_bucket.blob("set_up_test.txt") + blob = outside_bucket.blob(self.blocked_file) blob.download_as_string() except google.api_core.exceptions.Forbidden as e: # Verify the Forbidden exception was due to VPC SC. @@ -839,14 +843,16 @@ def _verify_vpc_sc_blocks_gcs_bucket(self): "Unexpected exception raised while accessing gcs bucket: {}".format(e) ) self.fail( - "No exception raised when accessing gcs bucket: {}".format(BUCKET_OUTSIDE) + "No exception raised when accessing gcs bucket: {}".format( + self.gcs_uri_blocked_file + ) ) @unittest.skipUnless(PROJECT_ID, "PROJECT_ID not set in environment.") def test_import_product_sets_blocked(self): # The csv file is outside the secure perimeter. gcs_source = vision.types.ImportProductSetsGcsSource( - csv_file_uri="gs://{bucket}/some_file.csv".format(bucket=BUCKET_OUTSIDE) + csv_file_uri=self.gcs_uri_blocked_file ) input_config = vision.types.ImportProductSetsInputConfig(gcs_source=gcs_source) # Use a valid Project ID. @@ -878,9 +884,7 @@ def test_async_batch_annotate_files_read_blocked(self): # The input file is in a gcs bucket that is outside of the secure perimeter. request = { "input_config": { - "gcs_source": { - "uri": "gs://{bucket}/some_file.pdf".format(bucket=BUCKET_OUTSIDE) - }, + "gcs_source": {"uri": self.gcs_uri_blocked_file}, "mime_type": "application/pdf", }, "features": [{"type": vision.enums.Feature.Type.DOCUMENT_TEXT_DETECTION}], @@ -926,7 +930,7 @@ def test_async_batch_annotate_files_write_blocked(self): } response = self.client.async_batch_annotate_files([request]) # Wait for the operation to complete. - lro_waiting_seconds = 60 + lro_waiting_seconds = 90 start_time = time.time() while not response.done() and (time.time() - start_time) < lro_waiting_seconds: time.sleep(1) @@ -946,13 +950,7 @@ def test_async_batch_annotate_files_write_blocked(self): def test_async_batch_annotate_images_read_blocked(self): # Make the request. The input file is in a gcs bucket that is outside of the secure perimeter. request = { - "image": { - "source": { - "image_uri": "gs://{bucket}/some_image.jpg".format( - bucket=BUCKET_OUTSIDE - ) - } - }, + "image": {"source": {"image_uri": self.gcs_uri_blocked_file}}, "features": [{"type": vision.enums.Feature.Type.LOGO_DETECTION}], } method_name = "test_async_batch_annotate_images_read_blocked" @@ -962,7 +960,7 @@ def test_async_batch_annotate_images_read_blocked(self): output_config = {"gcs_destination": {"uri": output_gcs_uri_prefix}} response = self.client.async_batch_annotate_images([request], output_config) # Wait for the operation to complete. - lro_waiting_seconds = 60 + lro_waiting_seconds = 90 start_time = time.time() while not response.done() and (time.time() - start_time) < lro_waiting_seconds: time.sleep(1) @@ -993,13 +991,7 @@ def test_async_batch_annotate_images_read_blocked(self): def test_async_batch_annotate_images_write_blocked(self): # Make the request. request = { - "image": { - "source": { - "image_uri": "gs://{bucket}/some_image.jpg".format( - bucket=BUCKET_OUTSIDE - ) - } - }, + "image": {"source": {"image_uri": self.gcs_uri_blocked_file}}, "features": [{"type": vision.enums.Feature.Type.LOGO_DETECTION}], } method_name = "test_async_batch_annotate_images_write_blocked" @@ -1010,7 +1002,7 @@ def test_async_batch_annotate_images_write_blocked(self): output_config = {"gcs_destination": {"uri": output_gcs_uri_prefix}} response = self.client.async_batch_annotate_images([request], output_config) # Wait for the operation to complete. - lro_waiting_seconds = 60 + lro_waiting_seconds = 90 start_time = time.time() while not response.done() and (time.time() - start_time) < lro_waiting_seconds: time.sleep(1) @@ -1029,13 +1021,7 @@ def test_async_batch_annotate_images_write_blocked(self): def test_batch_annotate_images_read_blocked(self): response = self.client.logo_detection( - { - "source": { - "image_uri": "gs://{bucket}/some_image.jpg".format( - bucket=BUCKET_OUTSIDE - ) - } - } + {"source": {"image_uri": self.gcs_uri_blocked_file}} ) error = response.error assert error.code == 7