[TIP] How to use wsgi_intercept & httplib ?

C. Titus Brown ctb at msu.edu
Wed Apr 7 07:37:43 PDT 2010


On Wed, Apr 07, 2010 at 09:49:26AM -0400, Olemis Lang wrote:
> 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 .

Hi, Olemis,

the twill 'add_wsgi_intercept' function installs the handler for twill
only.  You need to use a different wsgi_intercept function; see the
example on the main page of

	http://code.google.com/p/wsgi-intercept/

cheers,
--titus

> {{{
> #!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:
> 
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python

-- 
C. Titus Brown, ctb at msu.edu



More information about the testing-in-python mailing list