February 7, 2009

Adventures in unit testing the Basecamp API

I’m work­ing on a little side project, that I might open source once the code is less rough, which involves using the Base­camp API.

My pack­age uses the Python wrap­per for the API and then does some naming con­ven­tion magic to divine the number of Sprints and Back­logs and gen­er­ally gives some other useful report­ing info.

There are no tests for the wrap­per, and I couldn’t sleep at night, let alone develop soft­ware, with­out tests.

I started off just using the API and living with the fact that my test suite made net­work calls to a dummy project I setup in Base­camp.

But this morn­ing I worked up a clever (I hope) solu­tion — I sub­classed the Python wrap­per object and hooked up some meth­ods that allow my Test­Case to record any net­work trans­ac­tions and seri­al­ize them down to a fix­ture file.

When a test is run again the seri­al­ized data is used, the net­work is untouched, and I am a happy camper.

Update: The code for the Test­Base­camp object has been posted to Gist

Update again: The entire Base­camp API project, dubbed Base­cam­pRe­port­ing has been posted to GitHub

The advan­tages were that:

It’s prob­a­bly not the ideal solu­tion, but so far it’s seemed to work for me.

Filed under: Programming,Python

Next:
Previous:

Related