Python Client Libraries
Three really useful looking Python modules: ClientForm, ClientTable and ClientCookie. ClientForm looks like it provides similar functionality to the form handling part of the WWW::Mechanize perl module, discussed previously. It essentially provides a very simple interface for loading an HTML page, parsing out the form information then filling in the form and submitting it back to the server. The author recommends it for automated testing (I’ve always had trouble figuring out how to link unit testing in to web applications) but I’m sure it could be useful for screen scraping tools as well. ClientTable is an early beta of a powerful looking table parser, and ClientCookie sits on top of the standard urllib library and transparently persists cookies in between requests.
Gina - 5th September 2003 20:54 - #
Simon Willison - 5th September 2003 21:00 - #
I haven't got on to testing web interfaces yet but being as all of the web apps we create are loosely coupled to xhtml interface then it's a simple matter of testing the core separately from the interface.
In order to test databases, I developed a python shelve cacheing system whilst creating my celko/adjacency tree class. have a look at
the blog entry for unit testing databasesTim Parkin - 6th September 2003 17:59 - #
Richard Jones - 6th September 2003 23:44 - #
Paulo Eduardo Neves - 8th September 2003 21:18 - #
Richard Jones - 9th September 2003 08:03 - #
Well, here's how I've been doing it (and this probably isn't the best way):
I've developed a class which will be instantiated within a Zope template, and (obviously) accesses parameters on the current http request. (Zope makes it easy and accesses cookies, form posts and query string params the same exact way.) So I write a setRequest method for my class. This way, within the Zope template, the object is instantiated and the request object is set to the current http request (available through Zope). Then the object's methods do what they're supposed to do.
When I write my unit test, I instantiate a request object (a simple dumb wrapper I wrote in only a few minutes) and set all the parameters my web object would expect (or not expect), and then call setRequest(dumbFakeRequest) on the object I'm testing. Then I write my test methods from there.
It's worked so far.
Gina - 12th September 2003 23:15 - #
Richard Jones:
Hah, you're falling behind, Richard <wink>. Actually, httpunit doesn't implement an interpreter (of course!), it just reuses Mozilla's Rhino JS interpreter. I think HTTPClient is also worth a mention, as are Mozilla, Konqueror and MSIE (all accessible from Python).
I've just written some JavaScript support for Python. I used Mozilla's other JS implementation, spidermonkey. Sort-of works, but still very early days, though.
Of course, Python already does cookies, redirections, META refresh, HTML DOM etc. No nice unified browser-like API yet, though. I'm working on it...
John - 26th September 2003 18:46 - #
Michael Hayes - 30th September 2003 22:52 - #
John - 6th January 2004 18:42 - #
stephen - 28th January 2004 02:14 - #