simple_http_requests_test.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import httplib
00004 import rospy
00005 import unittest
00006 import time
00007 
00008 class TestSimpleHttpRequests(unittest.TestCase):
00009     def setUp(self):
00010         self.conn = httplib.HTTPConnection("localhost:9849")
00011 
00012     def test_ok(self):
00013         self.conn.request("GET", "/response/ok")
00014         response = self.conn.getresponse()
00015         self.assertEqual(200, response.status)
00016 
00017     def test_created(self):
00018         self.conn.request("GET", "/response/created")
00019         response = self.conn.getresponse()
00020         self.assertEqual(201, response.status)
00021 
00022     def test_accepted(self):
00023         self.conn.request("GET", "/response/accepted")
00024         response = self.conn.getresponse()
00025         self.assertEqual(202, response.status)
00026 
00027     def test_forbidden(self):
00028         self.conn.request("GET", "/response/forbidden")
00029         response = self.conn.getresponse()
00030         self.assertEqual(403, response.status)
00031 
00032     def test_not_found(self):
00033         self.conn.request("GET", "/response/not_found")
00034         response = self.conn.getresponse()
00035         self.assertEqual(404, response.status)
00036 
00037     def test_internal_server_error(self):
00038         self.conn.request("GET", "/response/internal_server_error")
00039         response = self.conn.getresponse()
00040         self.assertEqual(500, response.status)
00041 
00042     def test_default_action(self):
00043         self.conn.request("GET", "/some_random_url12345")
00044         response = self.conn.getresponse()
00045         self.assertEqual(404, response.status)
00046 
00047     def test_default_action(self):
00048         self.conn.request("GET", "/a_static_response")
00049         response = self.conn.getresponse()
00050         self.assertEqual(200, response.status)
00051         self.assertEqual("A RESPONSE", response.read())
00052 
00053     def test_http_echo1(self):
00054         test_content = "hello HELLO"*1000 # make sure to exceed MTU
00055         self.conn.request("GET", "/http_body_echo", test_content)
00056         response = self.conn.getresponse()
00057         self.assertEqual(200, response.status)
00058         self.assertEqual(test_content, response.read())
00059 
00060     def test_http_echo2(self):
00061         test_content = "THIS is A test"*1000 # make sure to exceed MTU
00062         self.conn.request("POST", "/http_body_echo", test_content)
00063         response = self.conn.getresponse()
00064         self.assertEqual(200, response.status)
00065         self.assertEqual(test_content, response.read())
00066 
00067     def test_http_path_echo(self):
00068         self.conn.request("GET", "/http_path_echo/this_is_a_test")
00069         response = self.conn.getresponse()
00070         self.assertEqual(200, response.status)
00071         self.assertEqual("/http_path_echo/this_is_a_test", response.read())
00072 
00073     def test_http_query_echo(self):
00074         self.conn.request("GET", "/http_query_echo?hello=1&b=test&c=10")
00075         response = self.conn.getresponse()
00076         self.assertEqual(200, response.status)
00077         self.assertEqual("b=test\nc=10\nhello=1\n", response.read())
00078 
00079     def test_file(self):
00080         self.conn.request("GET", "/test_file")
00081         response = self.conn.getresponse()
00082         self.assertEqual(200, response.status)
00083         self.assertEqual("<html></html>\n", response.read())
00084 
00085     def test_file_from_filesystem(self):
00086         self.conn.request("GET", "/test_files/test_dir/test_file.txt")
00087         response = self.conn.getresponse()
00088         self.assertEqual(200, response.status)
00089         self.assertEqual("test\n", response.read())
00090 
00091     def test_directory_listing_forbidden_from_filesystem1(self):
00092         self.conn.request("GET", "/test_files/test_dir/")
00093         response = self.conn.getresponse()
00094         self.assertEqual(403, response.status)
00095 
00096     def test_directory_listing_forbidden_from_filesystem2(self):
00097         self.conn.request("GET", "/test_files/test_dir")
00098         response = self.conn.getresponse()
00099         self.assertEqual(403, response.status)
00100 
00101     def test_directory_listing_from_filesystem(self):
00102         self.conn.request("GET", "/test_files_with_dir/test_dir/")
00103         response = self.conn.getresponse()
00104         self.assertEqual(200, response.status)
00105 
00106 if __name__ == '__main__':
00107     time.sleep(1) # ensure server is up
00108 
00109     import rostest
00110     rospy.init_node('simple_http_requests_test')
00111     rostest.rosrun('async_web_server_cpp', 'simple_http_requests', TestSimpleHttpRequests)


async_web_server_cpp
Author(s): Mitchell Wills
autogenerated on Sat Jun 8 2019 18:56:50