示例#1
0
 def test_save_checkpoint(self):
     web_ping = WebPing()
     web_ping.save_checkpoint(self.tmp_dir, "web_ping://TextCritical.com",
                              100)
     self.assertEquals(
         web_ping.last_ran(self.tmp_dir, "web_ping://TextCritical.com"),
         100)
示例#2
0
    def setUp(self):
        super(TestOnCloud, self).setUp()

        # Configure an instance of the class to test
        self.web_ping = WebPing()

        # Force the class to act like it is on cloud
        self.web_ping.is_on_cloud = self.fake_is_on_cloud
 def test_output_result_unavailable(self):
     web_ping = WebPing(timeout=3)
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     result = WebPing.ping( url_field.to_python("http://192.168.30.23/"), timeout=3 )
     
     out = StringIO()
     
     web_ping.output_result(result, "stanza", "title", unbroken=True, close=True, out=out)
     
     self.assertTrue(out.getvalue().find("timed_out=True") >= 0)
 def test_output_result(self):
     web_ping = WebPing(timeout=3)
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     result = WebPing.ping( url_field.to_python("https://www.google.com/"), timeout=3 )
     
     out = StringIO()
     
     web_ping.output_result(result, "stanza", "title", unbroken=True, close=True, out=out)
     
     self.assertTrue(out.getvalue().find("response_code=200") >= 0)
示例#5
0
    def test_output_result(self):
        web_ping = WebPing(timeout=3)

        url_field = URLField("test_ping", "title", "this is a test")
        result = WebPing.ping(url_field.to_python("http://127.0.0.1:" + str(self.web_server_port) + "/test_page"), timeout=3)

        out = StringIO()

        web_ping.output_result(result, "stanza", "title", unbroken=True, close=True, out=out)

        self.assertTrue(out.getvalue().find("response_code=200") >= 0)
 def test_bad_checkpoint(self):
     
     web_ping = WebPing()
     
     # Make sure the call does return the expected error (is attempting to load the data data)
     with self.assertRaises(ValueError):
         web_ping.get_checkpoint_data( os.path.join( self.get_test_dir(), "configs"), throw_errors=True )
     
     # Make sure the test returns None
     data = web_ping.get_checkpoint_data( os.path.join( self.get_test_dir(), "configs", "web_ping://TextCritical.net") )
     
     self.assertEqual(data, None)
 def test_missing_servername(self):
     """
     Some web-servers require that the "Host" be included on SSL connections when the server is hosting multiple domains on the same IP.
     
     Without the host header, the server is unable to determine which certificate to provide and thus closes the connection.
     
     http://lukemurphey.net/issues/1035
     """
     web_ping = WebPing(timeout=3)
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     result = WebPing.ping( url_field.to_python("https://www.penfolds.com"), timeout=3 )
     
     self.assertEquals(result.response_code, 200)
示例#8
0
 def test_custom_user_agent(self):
     """
     http://lukemurphey.net/issues/1341
     """
     web_ping = WebPing(timeout=3)
     
     url_field = URLField( "test_ping", "title", "this is a test" )
     
     # Make sure that the server is validating the user-agent by returning 200 when the user-agent doesn't match
     # This just validates that the test case works
     result = WebPing.ping( url_field.to_python("http://127.0.0.1:8888/user_agent_check"), user_agent="USER_AGENT_CHECK_DOESNT_MATCH", timeout=3 )
     self.assertEquals(result.response_code, 200)
     
     # Make sure that the server is validating the user-agent which returns 201 when the user-agent matches "USER_AGENT_CHECK"
     result = WebPing.ping( url_field.to_python("http://127.0.0.1:8888/user_agent_check"), user_agent="USER_AGENT_CHECK", timeout=3 )
     self.assertEquals(result.response_code, 201)
示例#9
0
    def test_cleanup_threads(self):
        threads_running = [1, 2]
        max_runs = 10

        def thread_function(n):
            total_time = 0
            while n in threads_running and total_time < max_runs:
                time.sleep(1)
                total_time += 1

        thread_1 = threading.Thread(target=thread_function, args=(1,))
        thread_2 = threading.Thread(target=thread_function, args=(2,))
        threads = {
            '1': thread_1,
            '2': thread_2
        }

        thread_1.start()
        thread_2.start()

        web_ping = WebPing()

        self.assertEqual(len(threads), 2)
        self.assertEqual(web_ping.cleanup_threads(threads), 0)
        self.assertEqual(len(threads), 2)

        # Stop the first thread and wait for it to complete
        threads_running = [2]
        thread_1.join()

        self.assertEqual(web_ping.cleanup_threads(threads), 1)
        self.assertEqual(len(threads), 1)

        # Stop the second thread and wait for it to complete
        threads_running = []
        thread_2.join()

        self.assertEqual(web_ping.cleanup_threads(threads), 1)
        self.assertEqual(len(threads), 0)