[TIP] Capture HTTP traffic
Sylvain Hellegouarch
sh at defuze.org
Wed Nov 3 03:42:10 PDT 2010
On Wed, Nov 3, 2010 at 11:10 AM, Alex <alex.lavoro.propio at gmail.com> wrote:
> I am developing an automated test in Python/Windows and I have to
> ensure certain HTTP requests are made and verify the GET parameters
> and responses. I need a tool to help me easily to capture and filter
> the HTTP requests.
>
> A typical test case is like:
>
> def setUp()
> self.capture = HttpCapture() # hypothetic
> def testFoo(self):
> self.capture.start("http://update.foobar.com")
> subprocess.Popen(...)
> self.capture.end()
> # suppose self.capture.result() returns a list of strings,
> containing the URLs
> # have been visited betwen begin() and end()
> self.failUnless("http://update.foobar.com/" in
> self.capture.result() )
>
> It seems to me that it's not trivial to integrate 'pycap' into this
> picture. I wouldn't mind that the hypothetic HttpCatpure() launchs an
> external application. In fact, I did try to automate Wireshark by
> myself but it didn't seem to fit well into this test case design
> neither.
>
>
There might be some existing tools for such task but off the top of my head,
I would consider writing a simple module performing those requests either
using httplib2 [1] if you know the URLs to be used. Or, in a case where it
should act more like a browser and perform the requests transparently, use
mechanize [2] or multi-mechanize.
[1] http://code.google.com/p/httplib2/
[2] http://wwwsearch.sourceforge.net/mechanize/
[3] http://code.google.com/p/multi-mechanize/
Hope that helps.
--
- Sylvain
http://www.defuze.org
http://twitter.com/lawouach
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20101103/cf4afe12/attachment.htm>
More information about the testing-in-python
mailing list