@@ -66,6 +66,14 @@ def test_from_url_full_on(self):
66
66
self .assertEqual (grafana .client .verify , False )
67
67
self .assertEqual (grafana .client .timeout , 5.0 )
68
68
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
+
69
77
def test_from_env_default (self ):
70
78
grafana = GrafanaApi .from_env ()
71
79
self .assertIsInstance (grafana .client .auth , requests .auth .HTTPBasicAuth )
@@ -114,3 +122,22 @@ def test_from_env_full_on(self):
114
122
self .assertEqual (grafana .client .url_protocol , "https" )
115
123
self .assertEqual (grafana .client .verify , False )
116
124
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