@@ -724,3 +724,49 @@ def test_provide_authorized_gcloud_via_gcloud_application_default(
724
724
],
725
725
any_order = False
726
726
)
727
+
728
+
729
+ class TestNumRetry (unittest .TestCase ):
730
+
731
+ def test_should_return_int_when_set_int_via_connection (self ):
732
+ instance = hook .GoogleBaseHook (gcp_conn_id = "google_cloud_default" )
733
+ instance .extras = {
734
+ 'extra__google_cloud_platform__num_retries' : 10 ,
735
+ }
736
+
737
+ self .assertIsInstance (instance .num_retries , int )
738
+ self .assertEqual (10 , instance .num_retries )
739
+
740
+ @mock .patch .dict (
741
+ 'os.environ' ,
742
+ AIRFLOW_CONN_GOOGLE_CLOUD_DEFAULT = (
743
+ 'google-cloud-platform://?extra__google_cloud_platform__num_retries=5'
744
+ )
745
+ )
746
+ def test_should_return_int_when_set_via_env_var (self ):
747
+ instance = hook .GoogleBaseHook (gcp_conn_id = "google_cloud_default" )
748
+ self .assertIsInstance (instance .num_retries , int )
749
+
750
+ @mock .patch .dict (
751
+ 'os.environ' ,
752
+ AIRFLOW_CONN_GOOGLE_CLOUD_DEFAULT = (
753
+ 'google-cloud-platform://?extra__google_cloud_platform__num_retries=cat'
754
+ )
755
+ )
756
+ def test_should_raise_when_invalid_value_via_env_var (self ):
757
+ instance = hook .GoogleBaseHook (gcp_conn_id = "google_cloud_default" )
758
+ with self .assertRaisesRegex (
759
+ AirflowException , re .escape ("The num_retries field should be a integer." )
760
+ ):
761
+ self .assertIsInstance (instance .num_retries , int )
762
+
763
+ @mock .patch .dict (
764
+ 'os.environ' ,
765
+ AIRFLOW_CONN_GOOGLE_CLOUD_DEFAULT = (
766
+ 'google-cloud-platform://?extra__google_cloud_platform__num_retries='
767
+ )
768
+ )
769
+ def test_should_fallback_when_empty_string_in_env_var (self ):
770
+ instance = hook .GoogleBaseHook (gcp_conn_id = "google_cloud_default" )
771
+ self .assertIsInstance (instance .num_retries , int )
772
+ self .assertEqual (5 , instance .num_retries )
0 commit comments