@@ -66,6 +66,14 @@ def test_from_url_full_on(self):
6666 self .assertEqual (grafana .client .verify , False )
6767 self .assertEqual (grafana .client .timeout , 5.0 )
6868
69+ def test_from_url_with_timeout_value (self ):
70+ grafana = GrafanaApi .from_url (timeout = 42.42 )
71+ self .assertEqual (grafana .client .timeout , 42.42 )
72+
73+ def test_from_url_with_timeout_tuple (self ):
74+ grafana = GrafanaApi .from_url (timeout = (3.05 , 27 ))
75+ self .assertEqual (grafana .client .timeout , (3.05 , 27 ))
76+
6977 def test_from_env_default (self ):
7078 grafana = GrafanaApi .from_env ()
7179 self .assertIsInstance (grafana .client .auth , requests .auth .HTTPBasicAuth )
@@ -114,3 +122,22 @@ def test_from_env_full_on(self):
114122 self .assertEqual (grafana .client .url_protocol , "https" )
115123 self .assertEqual (grafana .client .verify , False )
116124 self .assertEqual (grafana .client .timeout , 5.0 )
125+
126+ @mock .patch .dict (os .environ , {"GRAFANA_TIMEOUT" : "84.84" })
127+ def test_from_env_with_timeout_from_env_valid (self ):
128+ grafana = GrafanaApi .from_env ()
129+ self .assertEqual (grafana .client .timeout , 84.84 )
130+
131+ @mock .patch .dict (os .environ , {"GRAFANA_TIMEOUT" : "foobar" })
132+ def test_from_env_with_timeout_from_env_invalid (self ):
133+ with self .assertRaises (ValueError ) as ctx :
134+ GrafanaApi .from_env ()
135+ self .assertEqual (
136+ str (ctx .exception ),
137+ "Unable to parse invalid `float` value from `GRAFANA_TIMEOUT` "
138+ "environment variable: could not convert string to float: 'foobar'" ,
139+ )
140+
141+ def test_from_env_with_timeout_tuple (self ):
142+ grafana = GrafanaApi .from_env (timeout = (3.05 , 27 ))
143+ self .assertEqual (grafana .client .timeout , (3.05 , 27 ))
0 commit comments