• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import email
2
3from paste.httpserver import WSGIHandler
4from six.moves import StringIO
5
6
7class MockServer(object):
8    server_address = ('127.0.0.1', 80)
9
10
11class MockSocket(object):
12    def makefile(self, mode, bufsize):
13        return StringIO()
14
15
16def test_environ():
17    mock_socket = MockSocket()
18    mock_client_address = '1.2.3.4'
19    mock_server = MockServer()
20
21    wsgi_handler = WSGIHandler(mock_socket, mock_client_address, mock_server)
22    wsgi_handler.command = 'GET'
23    wsgi_handler.path = '/path'
24    wsgi_handler.request_version = 'HTTP/1.0'
25    wsgi_handler.headers = email.message_from_string('Host: mywebsite')
26
27    wsgi_handler.wsgi_setup()
28
29    assert wsgi_handler.wsgi_environ['HTTP_HOST'] == 'mywebsite'
30
31
32def test_environ_with_multiple_values():
33    mock_socket = MockSocket()
34    mock_client_address = '1.2.3.4'
35    mock_server = MockServer()
36
37    wsgi_handler = WSGIHandler(mock_socket, mock_client_address, mock_server)
38    wsgi_handler.command = 'GET'
39    wsgi_handler.path = '/path'
40    wsgi_handler.request_version = 'HTTP/1.0'
41    wsgi_handler.headers = email.message_from_string('Host: host1\nHost: host2')
42
43    wsgi_handler.wsgi_setup()
44
45    assert wsgi_handler.wsgi_environ['HTTP_HOST'] == 'host1,host2'
46