[TIP] How to use wsgi_intercept & httplib ?

Olemis Lang olemis at gmail.com
Wed Apr 7 06:49:26 PDT 2010


Hello !

I read Grig's article [1]_ where he mentions that twill's
`wsgi_intercept` mocks httplib under the hood. I tried to use it
directly and something is not working .

{{{
#!python

>>> twill.add_wsgi_intercept('localhost', 8001, lambda: simple_app)
>>> c = httplib.HTTPConnection("localhost:8001")
>>> r = c.request('GET', '/')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/httplib.py", line 866, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.5/httplib.py", line 889, in _send_request
    self.endheaders()
  File "/usr/lib/python2.5/httplib.py", line 860, in endheaders
    self._send_output()
  File "/usr/lib/python2.5/httplib.py", line 732, in _send_output
    self.send(msg)
  File "/usr/lib/python2.5/httplib.py", line 699, in send
    self.connect()
  File "/usr/lib/python2.5/httplib.py", line 683, in connect
    raise socket.error, msg
socket.error: (111, 'Connection refused')
>>>
>>>
>>> c = httplib.HTTPConnection("localhost", 8001)
>>> r = c.request('GET', '/')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/httplib.py", line 866, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.5/httplib.py", line 889, in _send_request
    self.endheaders()
  File "/usr/lib/python2.5/httplib.py", line 860, in endheaders
    self._send_output()
  File "/usr/lib/python2.5/httplib.py", line 732, in _send_output
    self.send(msg)
  File "/usr/lib/python2.5/httplib.py", line 699, in send
    self.connect()
  File "/usr/lib/python2.5/httplib.py", line 683, in connect
    raise socket.error, msg
socket.error: (111, 'Connection refused')

}}}

Q:
  - Could anybody please tell me what's wrong | missing ?

Thnx in advance !

.. [1] In-process Web app testing with twill, wsgi_intercept and doctest
        (http://agiletesting.blogspot.com/2006/04/in-process-web-app-testing-with-twill.html)

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:



More information about the testing-in-python mailing list