[TIP] Capture HTTP traffic
C. Titus Brown
ctb at msu.edu
Wed Nov 3 06:05:13 PDT 2010
On Wed, Nov 03, 2010 at 11:10:21AM +0100, Alex 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.
Hi Alex,
you could write a simple HTTP server of your own, and run it in another
thread. That doesn't help if you need to call remote URLs, though.
You could also develop a simple proxy server and funnel things through
that, recording the data that's passed through. The 'scotch' toolkit is a stab
at doing that,
http://darcs.idyll.org/~t/projects/scotch/doc/
and it used to work OK but I haven't played with it in years.
cheers,
--titus
--
C. Titus Brown, ctb at msu.edu
More information about the testing-in-python
mailing list