@@ -150,7 +150,7 @@ def test_detect_logos_async(self):
150150 response = self .client .async_batch_annotate_images ([request ], output_config )
151151
152152 # Wait for the operation to complete.
153- lro_waiting_seconds = 60
153+ lro_waiting_seconds = 90
154154 start_time = time .time ()
155155 while not response .done () and (time .time () - start_time ) < lro_waiting_seconds :
156156 time .sleep (1 )
@@ -209,7 +209,7 @@ def test_async_batch_annotate_files(self):
209209 response = self .client .async_batch_annotate_files ([request ])
210210
211211 # Wait for the operation to complete.
212- lro_waiting_seconds = 60
212+ lro_waiting_seconds = 90
213213 start_time = time .time ()
214214 while not response .done () and (time .time () - start_time ) < lro_waiting_seconds :
215215 time .sleep (1 )
@@ -815,6 +815,10 @@ class TestVisionClientVpcsc(VisionSystemTestBase):
815815 # Tests to verify Vision API methods are blocked by VPC SC when trying to access a gcs resource outside of a secure perimeter.
816816 def setUp (self ):
817817 VisionSystemTestBase .setUp (self )
818+ self .blocked_file = "LC08/01_$folder$"
819+ self .gcs_uri_blocked_file = "gs://{bucket}/{file}" .format (
820+ bucket = BUCKET_OUTSIDE , file = self .blocked_file
821+ )
818822 self ._verify_vpc_sc_blocks_gcs_bucket ()
819823 self .gcs_read_error_message = "Error opening file: gs://"
820824 self .gcs_write_error_message = "Error writing final output to: gs://"
@@ -824,7 +828,7 @@ def _verify_vpc_sc_blocks_gcs_bucket(self):
824828 try :
825829 storage_client = storage .Client ()
826830 outside_bucket = storage_client .get_bucket (BUCKET_OUTSIDE )
827- blob = outside_bucket .blob ("set_up_test.txt" )
831+ blob = outside_bucket .blob (self . blocked_file )
828832 blob .download_as_string ()
829833 except google .api_core .exceptions .Forbidden as e :
830834 # Verify the Forbidden exception was due to VPC SC.
@@ -839,14 +843,16 @@ def _verify_vpc_sc_blocks_gcs_bucket(self):
839843 "Unexpected exception raised while accessing gcs bucket: {}" .format (e )
840844 )
841845 self .fail (
842- "No exception raised when accessing gcs bucket: {}" .format (BUCKET_OUTSIDE )
846+ "No exception raised when accessing gcs bucket: {}" .format (
847+ self .gcs_uri_blocked_file
848+ )
843849 )
844850
845851 @unittest .skipUnless (PROJECT_ID , "PROJECT_ID not set in environment." )
846852 def test_import_product_sets_blocked (self ):
847853 # The csv file is outside the secure perimeter.
848854 gcs_source = vision .types .ImportProductSetsGcsSource (
849- csv_file_uri = "gs://{bucket}/some_file.csv" . format ( bucket = BUCKET_OUTSIDE )
855+ csv_file_uri = self . gcs_uri_blocked_file
850856 )
851857 input_config = vision .types .ImportProductSetsInputConfig (gcs_source = gcs_source )
852858 # Use a valid Project ID.
@@ -878,9 +884,7 @@ def test_async_batch_annotate_files_read_blocked(self):
878884 # The input file is in a gcs bucket that is outside of the secure perimeter.
879885 request = {
880886 "input_config" : {
881- "gcs_source" : {
882- "uri" : "gs://{bucket}/some_file.pdf" .format (bucket = BUCKET_OUTSIDE )
883- },
887+ "gcs_source" : {"uri" : self .gcs_uri_blocked_file },
884888 "mime_type" : "application/pdf" ,
885889 },
886890 "features" : [{"type" : vision .enums .Feature .Type .DOCUMENT_TEXT_DETECTION }],
@@ -926,7 +930,7 @@ def test_async_batch_annotate_files_write_blocked(self):
926930 }
927931 response = self .client .async_batch_annotate_files ([request ])
928932 # Wait for the operation to complete.
929- lro_waiting_seconds = 60
933+ lro_waiting_seconds = 90
930934 start_time = time .time ()
931935 while not response .done () and (time .time () - start_time ) < lro_waiting_seconds :
932936 time .sleep (1 )
@@ -946,13 +950,7 @@ def test_async_batch_annotate_files_write_blocked(self):
946950 def test_async_batch_annotate_images_read_blocked (self ):
947951 # Make the request. The input file is in a gcs bucket that is outside of the secure perimeter.
948952 request = {
949- "image" : {
950- "source" : {
951- "image_uri" : "gs://{bucket}/some_image.jpg" .format (
952- bucket = BUCKET_OUTSIDE
953- )
954- }
955- },
953+ "image" : {"source" : {"image_uri" : self .gcs_uri_blocked_file }},
956954 "features" : [{"type" : vision .enums .Feature .Type .LOGO_DETECTION }],
957955 }
958956 method_name = "test_async_batch_annotate_images_read_blocked"
@@ -962,7 +960,7 @@ def test_async_batch_annotate_images_read_blocked(self):
962960 output_config = {"gcs_destination" : {"uri" : output_gcs_uri_prefix }}
963961 response = self .client .async_batch_annotate_images ([request ], output_config )
964962 # Wait for the operation to complete.
965- lro_waiting_seconds = 60
963+ lro_waiting_seconds = 90
966964 start_time = time .time ()
967965 while not response .done () and (time .time () - start_time ) < lro_waiting_seconds :
968966 time .sleep (1 )
@@ -993,13 +991,7 @@ def test_async_batch_annotate_images_read_blocked(self):
993991 def test_async_batch_annotate_images_write_blocked (self ):
994992 # Make the request.
995993 request = {
996- "image" : {
997- "source" : {
998- "image_uri" : "gs://{bucket}/some_image.jpg" .format (
999- bucket = BUCKET_OUTSIDE
1000- )
1001- }
1002- },
994+ "image" : {"source" : {"image_uri" : self .gcs_uri_blocked_file }},
1003995 "features" : [{"type" : vision .enums .Feature .Type .LOGO_DETECTION }],
1004996 }
1005997 method_name = "test_async_batch_annotate_images_write_blocked"
@@ -1010,7 +1002,7 @@ def test_async_batch_annotate_images_write_blocked(self):
10101002 output_config = {"gcs_destination" : {"uri" : output_gcs_uri_prefix }}
10111003 response = self .client .async_batch_annotate_images ([request ], output_config )
10121004 # Wait for the operation to complete.
1013- lro_waiting_seconds = 60
1005+ lro_waiting_seconds = 90
10141006 start_time = time .time ()
10151007 while not response .done () and (time .time () - start_time ) < lro_waiting_seconds :
10161008 time .sleep (1 )
@@ -1029,13 +1021,7 @@ def test_async_batch_annotate_images_write_blocked(self):
10291021
10301022 def test_batch_annotate_images_read_blocked (self ):
10311023 response = self .client .logo_detection (
1032- {
1033- "source" : {
1034- "image_uri" : "gs://{bucket}/some_image.jpg" .format (
1035- bucket = BUCKET_OUTSIDE
1036- )
1037- }
1038- }
1024+ {"source" : {"image_uri" : self .gcs_uri_blocked_file }}
10391025 )
10401026 error = response .error
10411027 assert error .code == 7
0 commit comments