darkness

Saturday, 05 February 2005

Web applications in Python and how to test them

darkness @ 11:38:51

I’m going to be starting up some Python development for a “web application” I guess. I wanted to do test-driven development but realized I had never done this with a web application before. Here’s a collection of tools, one or more of which I suspect will help me in the future.

  • Puffin - Looks abandoned, and its XML looks kind of verbose (i.e., stop coding in XML, as I read in one web log). There’s an article on testing with Puffin at IBM developerWorks.
  • There are two testing frameworks called WebUnit. The first WebUnit seems to have been considered superseded by the second WebUnit (also called mechanicalcat WebUnit, I guess). Both of these seem to have had their last release in 2002. That’s not a major problem, really; I just hope they work OK in Python 2.3/2.4.
  • A promising approach might be writing some custom scripts probably using unittest and using the stuff at http://wwwsearch.sourceforge.net/. There they have lots of stuff for scraping HTML, keeping track of cookies, submitting forms, etc.
  • Python Browser Poseur looks geared towards testing, with its own shell where you can interactively develop a test, and then save that test script to a file. (Also see MaxQ below.)
  • In a weird sort of way there’s PyXPCOM which can use XPCOM to interact with, say, Mozilla. I’ve heard it theorized that you could use this to automate tests in Mozilla.

If you’re not a hard-core Python zealot, you might consider some Java tools I found:

  • MaxQ looks pretty cool. To make a test, you start up its browser proxy and configure your browser to use it. Then you test your application. MaxQ takes note of the exchange between browser and server, and when you’re done MaxQ saves that. Later you can play back that conversation in an automated way. There are two concerns I have with this for TDD:

    1. You need a semi-working web application to test this. You can’t test before you write code.
    2. This seems prone to breakage when you change things in the HTML, maybe form field names, etc. This problem is probably true to some extent for most tools. (See my notes below.)

    Still, this could be a cool tool. Now that I think about it, I’m pretty sure its recorded test output is actually Python (Jython).

  • Canoo WebTest seems to be pretty popular. It looks like it uses XML to write tests, similar to Puffin, but its syntax does look better.
  • jWebUnit - I think you’re writing tests right in Java here, but this product seems pretty highly regarded.

The problems with these Java tools, from my perspective, are chiefly integration with build environment, and increased complexity of the build environment. If I were to use jWebUnit the work I’d end up doing would probably amount to one Java project for testing, and then the actual project in Python. I’d need the JDK, whatever libraries jWebUnit requires in addition to jWebUnit itself, and I’d probably be using a different editor (IntelliJ IDEA) from the Emacs that I usually edit my Python in. The same applies for Canoo WebTest.

I don’t really like the concept of using form field names. I’d prefer to say “the field next to the ‘Password:’ label” to refer to a form field. Of course, I understand this might not be a simple task, but the user doesn’t see field names, so why should you test with them?

I’m actually going to be using Twisted as the framework for this application. Twisted has some testing utilities of its own, though I see nothing that helps you, say, scrape some HTML and submit forms, keep track of cookies, etc. It’s documentation seems a bit sketchy. You can check out a “Networking with Twisted” presentation, apparently from OSCON 2003, which has a section on testing with Twisted.

A few alternatives to Twisted I might end up with:

I didn’t look hard at most of these, except Quixote which seems reasonably popular. The developers of Quixote have also made a unit testing framework for Quixote called Sancho (not Sanchez; get your mind out of the gutter). There’s always Zope of course, but as long as it’s just me writing this, I don’t really care for the complexity and bother of writing lots of dynamic content with Zope.

Friday, 04 February 2005

Goodbye Mozilla, hello Firefox

darkness @ 23:37:37

Mozilla randomly stopped working for me tonight. I went to a web page and it locked up. I figured it was the lock up I get when I visit a Java page and Mozilla has to load the Java plug-in. After five minutes I decided something worse had happened. killall mozilla-bin then restart. Go to, say, Penny Arcade. Lock up, no page display, spinner is dead. Repeat several times. Play with profiles. Disable Privoxy proxy settings. No luck.

So I crammed Firefox on top of my disgusting installation which was once known as “FC2,” before I let some third party repositories run amok by accident. I installed the Firefox 1.0 RPM from FC3 updates with little other problems: compat-libstdc++, gcc, and a few other usual suspects. I was surprised.

Firefox seems to be working well. I anticipate having the same focus problems I had with Mozilla, but I haven’t confirmed them yet. (Of course, I’ve only been running with Firefox for about 10 minutes.)

Some extensions I like in Firefox:

  • Session Saver 2 automatically saves all the tabs you have open upon crashing. I find this magical, but it has worked for me - and saved me time - in Windows. I hope to see the same effects in Linux. (Note that I don’t think the site this extension is distributed from sends the right MIME type for XPI files. I had to save to disk then run firefox whatever.xpi to get Firefox to prompt me to install it.)
  • Tab Mix is some conglomeration of other tab-related extensions. I have found it to work well and offer many useful features. Among them: a close button when you mouse over a tab, dragging tabs to rearrange them, stacked tab bar when you’ve got a bunch of tabs open, progress bar on the tab, and best of all: force new windows to open in tabs (which I’ve grown very attached to in Konqueror).
  • Adblock, which I’ve been using instead of Privoxy on Windows, and hope to continue that trend now on Linux. I use Filterset.G.

Powered by WordPress