-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathsimple_http_requests_test.py
More file actions
executable file
·115 lines (94 loc) · 4.2 KB
/
simple_http_requests_test.py
File metadata and controls
executable file
·115 lines (94 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#! /usr/bin/env python
import sys
if sys.version_info > (3,):
import http.client as httplib
else:
import httplib
import rospy
import unittest
import time
class TestSimpleHttpRequests(unittest.TestCase):
def setUp(self):
self.conn = httplib.HTTPConnection("localhost:9849")
def test_ok(self):
self.conn.request("GET", "/response/ok")
response = self.conn.getresponse()
self.assertEqual(200, response.status)
def test_created(self):
self.conn.request("GET", "/response/created")
response = self.conn.getresponse()
self.assertEqual(201, response.status)
def test_accepted(self):
self.conn.request("GET", "/response/accepted")
response = self.conn.getresponse()
self.assertEqual(202, response.status)
def test_forbidden(self):
self.conn.request("GET", "/response/forbidden")
response = self.conn.getresponse()
self.assertEqual(403, response.status)
def test_not_found(self):
self.conn.request("GET", "/response/not_found")
response = self.conn.getresponse()
self.assertEqual(404, response.status)
def test_internal_server_error(self):
self.conn.request("GET", "/response/internal_server_error")
response = self.conn.getresponse()
self.assertEqual(500, response.status)
def test_default_action(self):
self.conn.request("GET", "/some_random_url12345")
response = self.conn.getresponse()
self.assertEqual(404, response.status)
def test_default_action(self):
self.conn.request("GET", "/a_static_response")
response = self.conn.getresponse()
self.assertEqual(200, response.status)
self.assertEqual(b"A RESPONSE", response.read())
def test_http_echo1(self):
test_content = b"hello HELLO"*1000 # make sure to exceed MTU
self.conn.request("GET", "/http_body_echo", test_content)
response = self.conn.getresponse()
self.assertEqual(200, response.status)
self.assertEqual(test_content, response.read())
def test_http_echo2(self):
test_content = b"THIS is A test"*1000 # make sure to exceed MTU
self.conn.request("POST", "/http_body_echo", test_content)
response = self.conn.getresponse()
self.assertEqual(200, response.status)
self.assertEqual(test_content, response.read())
def test_http_path_echo(self):
self.conn.request("GET", "/http_path_echo/this_is_a_test")
response = self.conn.getresponse()
self.assertEqual(200, response.status)
self.assertEqual(b"/http_path_echo/this_is_a_test", response.read())
def test_http_query_echo(self):
self.conn.request("GET", "/http_query_echo?hello=1&b=test&c=10")
response = self.conn.getresponse()
self.assertEqual(200, response.status)
self.assertEqual(b"b=test\nc=10\nhello=1\n", response.read())
def test_file(self):
self.conn.request("GET", "/test_file")
response = self.conn.getresponse()
self.assertEqual(200, response.status)
self.assertEqual(b"<html></html>\n", response.read())
def test_file_from_filesystem(self):
self.conn.request("GET", "/test_files/test_dir/test_file.txt")
response = self.conn.getresponse()
self.assertEqual(200, response.status)
self.assertEqual(b"test\n", response.read())
def test_directory_listing_forbidden_from_filesystem1(self):
self.conn.request("GET", "/test_files/test_dir/")
response = self.conn.getresponse()
self.assertEqual(403, response.status)
def test_directory_listing_forbidden_from_filesystem2(self):
self.conn.request("GET", "/test_files/test_dir")
response = self.conn.getresponse()
self.assertEqual(403, response.status)
def test_directory_listing_from_filesystem(self):
self.conn.request("GET", "/test_files_with_dir/test_dir/")
response = self.conn.getresponse()
self.assertEqual(200, response.status)
if __name__ == '__main__':
time.sleep(1) # ensure server is up
import rostest
rospy.init_node('simple_http_requests_test')
rostest.rosrun('async_web_server_cpp', 'simple_http_requests', TestSimpleHttpRequests)