3 # Copyright 2011, Google Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following disclaimer
14 # in the documentation and/or other materials provided with the
16 # * Neither the name of Google Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived from
18 # this software without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 """Tests for http_header_util module."""
38 from mod_pywebsocket import http_header_util
41 class UnitTest(unittest.TestCase):
42 """A unittest for http_header_util module."""
44 def test_parse_relative_uri(self):
45 host, port, resource = http_header_util.parse_uri('/ws/test')
46 self.assertEqual(None, host)
47 self.assertEqual(None, port)
48 self.assertEqual('/ws/test', resource)
50 def test_parse_absolute_uri(self):
51 host, port, resource = http_header_util.parse_uri(
52 'ws://localhost:10080/ws/test')
53 self.assertEqual('localhost', host)
54 self.assertEqual(10080, port)
55 self.assertEqual('/ws/test', resource)
57 host, port, resource = http_header_util.parse_uri(
58 'ws://example.com/ws/test')
59 self.assertEqual('example.com', host)
60 self.assertEqual(80, port)
61 self.assertEqual('/ws/test', resource)
63 host, port, resource = http_header_util.parse_uri(
65 self.assertEqual('example.com', host)
66 self.assertEqual(443, port)
67 self.assertEqual('/', resource)
69 host, port, resource = http_header_util.parse_uri(
70 'ws://example.com:8080')
71 self.assertEqual('example.com', host)
72 self.assertEqual(8080, port)
73 self.assertEqual('/', resource)
75 def test_parse_invalid_uri(self):
76 host, port, resource = http_header_util.parse_uri('ws:///')
77 self.assertEqual(None, resource)
79 host, port, resource = http_header_util.parse_uri('ws://localhost:')
80 self.assertEqual(None, resource)
82 host, port, resource = http_header_util.parse_uri('ws://localhost:/ws')
83 self.assertEqual(None, resource)
86 if __name__ == '__main__':