@@ -108,14 +108,33 @@ def test_success(self, mock_logging, mock_post):
108108
109109 @mock .patch ('netuitive.client.urllib2.urlopen' )
110110 @mock .patch ('netuitive.client.logging' )
111- def test_failure_general (self , mock_logging , mock_post ):
111+ def test_failure_general_http (self , mock_logging , mock_post ):
112112
113113 mock_post .return_value = MockResponse (code = 500 )
114- mock_post .side_effect = urllib2 .HTTPError (* [None ] * 5 )
115114
116115 # test infrastructure endpoint url creation
117116 a = netuitive .Client (api_key = 'apikey' )
117+ mock_post .side_effect = urllib2 .HTTPError (a .url , 500 , '' , {}, None )
118+ e = netuitive .Element ()
119+
120+ e .add_sample (
121+ 'nonsparseDataStrategy' , 1434110794 , 1 , 'COUNTER' , host = 'hostname' )
122+
123+ resp = a .post (e )
124+
125+ self .assertNotEqual (resp , True )
126+ self .assertEqual (mock_logging .exception .call_args_list [0 ][0 ][
127+ 0 ], 'error posting payload to api ingest endpoint (%s): %s' )
118128
129+ @mock .patch ('netuitive.client.urllib2.urlopen' )
130+ @mock .patch ('netuitive.client.logging' )
131+ def test_failure_general (self , mock_logging , mock_post ):
132+
133+ mock_post .return_value = MockResponse (code = 500 )
134+
135+ # test infrastructure endpoint url creation
136+ a = netuitive .Client (api_key = 'apikey' )
137+ mock_post .side_effect = urllib2 .URLError ('something' )
119138 e = netuitive .Element ()
120139
121140 e .add_sample (
@@ -192,6 +211,8 @@ def test_kill_switch_410(self, mock_logging, mock_post):
192211 mock_post .return_value = MockResponse (code = 410 )
193212
194213 a = netuitive .Client (api_key = 'apikey' )
214+ mock_post .side_effect = urllib2 .HTTPError (a .url , 410 , '' , {}, None )
215+
195216 e = netuitive .Element ()
196217
197218 e .add_sample (
@@ -201,20 +222,20 @@ def test_kill_switch_410(self, mock_logging, mock_post):
201222 resp2 = a .post (e )
202223
203224 self .assertNotEqual (resp , True )
204- self .assertNotEqual (resp2 , True )
225+ self .assertFalse (resp2 )
205226
206227 self .assertTrue (a .disabled )
207228
208229 self .assertEqual (mock_logging .exception .call_args_list [0 ][0 ][
209- 0 ], 'error posting payload to api ingest endpoint (%s): %s ' )
230+ 0 ], 'Posting has been disabled.See previous errors for details. ' )
210231
211232 @mock .patch ('netuitive.client.urllib2.urlopen' )
212233 @mock .patch ('netuitive.client.logging' )
213234 def test_kill_switch_418 (self , mock_logging , mock_post ):
214235
215236 mock_post .return_value = MockResponse (code = 418 )
216-
217237 a = netuitive .Client (api_key = 'apikey' )
238+ mock_post .side_effect = urllib2 .HTTPError (a .url , 418 , '' , {}, None )
218239 e = netuitive .Element ()
219240
220241 e .add_sample (
@@ -224,11 +245,11 @@ def test_kill_switch_418(self, mock_logging, mock_post):
224245 resp2 = a .post (e )
225246
226247 self .assertNotEqual (resp , True )
227- self .assertNotEqual (resp2 , True )
248+ self .assertFalse (resp2 )
228249 self .assertTrue (a .disabled )
229250
230251 self .assertEqual (mock_logging .exception .call_args_list [0 ][0 ][
231- 0 ], 'error posting payload to api ingest endpoint (%s): %s ' )
252+ 0 ], 'Posting has been disabled.See previous errors for details. ' )
232253
233254 def tearDown (self ):
234255 pass
@@ -259,10 +280,28 @@ def test_success(self, mock_logging, mock_post):
259280
260281 @mock .patch ('netuitive.client.urllib2.urlopen' )
261282 @mock .patch ('netuitive.client.logging' )
262- def test_failure_general (self , mock_logging , mock_post ):
283+ def test_failure_general_http (self , mock_logging , mock_post ):
263284
264285 mock_post .return_value = MockResponse (code = 500 )
265- mock_post .side_effect = urllib2 .HTTPError (* [None ] * 5 )
286+
287+ # test infrastructure endpoint url creation
288+ a = netuitive .Client (api_key = 'apikey' )
289+ mock_post .side_effect = urllib2 .HTTPError (a .url , 500 , '' , {}, None )
290+
291+ e = netuitive .Event (
292+ 'test' , 'INFO' , 'test event' , 'big old test message' , 'INFO' )
293+
294+ resp = a .post_event (e )
295+
296+ self .assertNotEqual (resp , True )
297+
298+ self .assertEqual (mock_logging .exception .call_args_list [0 ][0 ][
299+ 0 ], 'error posting payload to api ingest endpoint (%s): %s' )
300+
301+ @mock .patch ('netuitive.client.urllib2.urlopen' )
302+ @mock .patch ('netuitive.client.logging' )
303+ def test_failure_general (self , mock_logging , mock_post ):
304+ mock_post .side_effect = urllib2 .URLError ('something' )
266305
267306 # test infrastructure endpoint url creation
268307 a = netuitive .Client (api_key = 'apikey' )
@@ -282,20 +321,21 @@ def test_failure_general(self, mock_logging, mock_post):
282321 def test_kill_switch_410 (self , mock_logging , mock_post ):
283322
284323 mock_post .return_value = MockResponse (code = 410 )
285-
286324 # test infrastructure endpoint url creation
287325 a = netuitive .Client (api_key = 'apikey' )
326+ mock_post .side_effect = urllib2 .HTTPError (a .url , 410 , '' , {}, None )
288327
289328 e = netuitive .Event (
290329 'test' , 'INFO' , 'test event' , 'big old test message' , 'INFO' )
291330
292331 resp = a .post_event (e )
332+ resp2 = a .post_event (e )
293333
294334 self .assertNotEqual (resp , True )
335+ self .assertFalse (resp2 )
295336 self .assertTrue (a .disabled )
296-
297337 self .assertEqual (mock_logging .exception .call_args_list [0 ][0 ][
298- 0 ], 'error posting payload to api ingest endpoint (%s): %s ' )
338+ 0 ], 'Posting has been disabled.See previous errors for details. ' )
299339
300340 @mock .patch ('netuitive.client.urllib2.urlopen' )
301341 @mock .patch ('netuitive.client.logging' )
@@ -305,17 +345,19 @@ def test_kill_switch_418(self, mock_logging, mock_post):
305345
306346 # test infrastructure endpoint url creation
307347 a = netuitive .Client (api_key = 'apikey' )
348+ mock_post .side_effect = urllib2 .HTTPError (a .url , 418 , '' , {}, None )
308349
309350 e = netuitive .Event (
310351 'test' , 'INFO' , 'test event' , 'big old test message' , 'INFO' )
311352
312353 resp = a .post_event (e )
354+ resp2 = a .post_event (e )
313355
314356 self .assertNotEqual (resp , True )
357+ self .assertFalse (resp2 )
315358 self .assertTrue (a .disabled )
316-
317359 self .assertEqual (mock_logging .exception .call_args_list [0 ][0 ][
318- 0 ], 'error posting payload to api ingest endpoint (%s): %s ' )
360+ 0 ], 'Posting has been disabled.See previous errors for details. ' )
319361
320362 def tearDown (self ):
321363 pass
0 commit comments