@@ -397,6 +397,122 @@ def test_not_kill_switch_504(self, mock_logging, mock_post):
397397 def tearDown (self ):
398398 pass
399399
400+ class TestClientCheckPost (unittest .TestCase ):
401+
402+ def setUp (self ):
403+ pass
404+
405+ @mock .patch ('netuitive.client.urllib2.urlopen' )
406+ @mock .patch ('netuitive.client.logging' )
407+ def test_success (self , mock_logging , mock_post ):
408+
409+ mock_post .return_value = MockResponse (code = 202 )
410+
411+ # test infrastructure endpoint url creation
412+ a = netuitive .Client (api_key = 'apikey' )
413+
414+ c = netuitive .Check ('check' , 'test' , 60 )
415+
416+ resp = a .post_check (c )
417+
418+ self .assertTrue (resp )
419+
420+ self .assertEqual (mock_logging .exception .call_args_list , [])
421+
422+ @mock .patch ('netuitive.client.urllib2.urlopen' )
423+ @mock .patch ('netuitive.client.logging' )
424+ def test_failure_general_http (self , mock_logging , mock_post ):
425+
426+ mock_post .return_value = MockResponse (code = 500 )
427+
428+ # test infrastructure endpoint url creation
429+ a = netuitive .Client (api_key = 'apikey' )
430+ mock_post .side_effect = urllib2 .HTTPError (a .url , 500 , '' , {}, None )
431+
432+ e = netuitive .Check ('check' , 'test' , 60 )
433+
434+ resp = a .post_event (e )
435+
436+ self .assertNotEqual (resp , True )
437+
438+ self .assertEqual (mock_logging .exception .call_args_list [0 ][0 ][0 ], 'error posting payload to api ingest endpoint (%s): %s' )
439+
440+ @mock .patch ('netuitive.client.urllib2.urlopen' )
441+ @mock .patch ('netuitive.client.logging' )
442+ def test_failure_general (self , mock_logging , mock_post ):
443+ mock_post .side_effect = urllib2 .URLError ('something' )
444+
445+ # test infrastructure endpoint url creation
446+ a = netuitive .Client (api_key = 'apikey' )
447+
448+ c = netuitive .Check ('check' , 'test' , 60 )
449+
450+ resp = a .post_check (c )
451+
452+ self .assertNotEqual (resp , True )
453+
454+ self .assertEqual (mock_logging .exception .call_args_list [0 ][0 ][0 ], 'error posting payload to api ingest endpoint (%s): %s' )
455+
456+ @mock .patch ('netuitive.client.urllib2.urlopen' )
457+ @mock .patch ('netuitive.client.logging' )
458+ def test_kill_switch_410 (self , mock_logging , mock_post ):
459+
460+ mock_post .return_value = MockResponse (code = 410 )
461+ # test infrastructure endpoint url creation
462+ a = netuitive .Client (api_key = 'apikey' )
463+ mock_post .side_effect = urllib2 .HTTPError (a .url , 410 , '' , {}, None )
464+
465+ c = netuitive .Check ('check' , 'test' , 60 )
466+
467+ resp = a .post_check (c )
468+ resp2 = a .post_check (c )
469+
470+ self .assertNotEqual (resp , True )
471+ self .assertFalse (resp2 )
472+ self .assertTrue (a .disabled )
473+ self .assertEqual (mock_logging .exception .call_args_list [0 ][0 ][0 ], 'Posting has been disabled.See previous errors for details.' )
474+
475+ @mock .patch ('netuitive.client.urllib2.urlopen' )
476+ @mock .patch ('netuitive.client.logging' )
477+ def test_kill_switch_418 (self , mock_logging , mock_post ):
478+
479+ mock_post .return_value = MockResponse (code = 418 )
480+
481+ # test infrastructure endpoint url creation
482+ a = netuitive .Client (api_key = 'apikey' )
483+ mock_post .side_effect = urllib2 .HTTPError (a .url , 418 , '' , {}, None )
484+
485+ c = netuitive .Check ('check' , 'test' , 60 )
486+
487+ resp = a .post_check (c )
488+ resp2 = a .post_check (c )
489+
490+ self .assertNotEqual (resp , True )
491+ self .assertFalse (resp2 )
492+ self .assertTrue (a .disabled )
493+ self .assertEqual (mock_logging .exception .call_args_list [0 ][0 ][0 ], 'Posting has been disabled.See previous errors for details.' )
494+
495+ @mock .patch ('netuitive.client.urllib2.urlopen' )
496+ @mock .patch ('netuitive.client.logging' )
497+ def test_not_kill_switch_504 (self , mock_logging , mock_post ):
498+
499+ mock_post .return_value = MockResponse (code = 504 )
500+ # test infrastructure endpoint url creation
501+ a = netuitive .Client (api_key = 'apikey' )
502+ mock_post .side_effect = urllib2 .HTTPError (a .url , 504 , '' , {}, None )
503+
504+ c = netuitive .Check ('check' , 'test' , 60 )
505+
506+ resp = a .post_check (c )
507+ resp2 = a .post_check (c )
508+
509+ self .assertNotEqual (resp , True )
510+ self .assertFalse (resp2 )
511+ self .assertFalse (a .disabled )
512+ self .assertEqual (mock_logging .exception .call_args_list [0 ][0 ][0 ], 'error posting payload to api ingest endpoint (%s): %s' )
513+
514+ def tearDown (self ):
515+ pass
400516
401517class TestClientTimeOffset (unittest .TestCase ):
402518
0 commit comments