Coder’s Eye

A site about one of the three passions in my life.

Coder’s Eye header image 2

Trackbacks on Banjo

November 11th, 2007 · 4 Comments

Working on Banjo Blog, nearly the only thing remaining before my initial release is a trackback/pingback system.

Oddly enough, there isn’t any django trackback app in the wild, at least not any I could find. So, I looked around and found only half-written stuff, hacky garbage and tblib, which is too old, not Django aware, and GPL. Banjo is BSD and it is going to stay that way, thank you.

So, I wrote my own.

I think it is pretty slick, and I’m planning to package it as a separate app so that all the other Django blogs on the block can have a decent trackback library without reinventing the wheel.

What I probably won’t do is port my tests to work standalone. It turns out that testing this kind of stuff is not so simple in Django. That’s because the HTTP server isn’t “really” running when you are running tests. The Test Client can pull information, true, but it does it by some kind of magic. Try using urllib.urlopen and you can’t get at the page.

That’s too bad, because for trackback autodiscovery, I really need to be able to urlopen the page.

After lamenting for a moment, I sat down to make the tests work. I did it in a straightforward way. I just make a separate settings file which imports the master settings file, and then overrides the database to be in-memory Sqlite. Then I start a test server in the background with ./manage.py testserver &

Put that in a script, and kill the test server after the tests are done. It is a bit kludgy for now, and it certainly won’t work on Windows (but who cares, really?Developing on Windows is an exercise in masochism), but it works and it allows me to test sending and receiving real trackbacks and pingbacks.

Technorati Tags: , , , ,

Tags: Banjo · Django · Python

Bookmark this article

del.icio.us:Trackbacks on Banjo digg:Trackbacks on Banjo spurl:Trackbacks on Banjo wists:Trackbacks on Banjo simpy:Trackbacks on Banjo newsvine:Trackbacks on Banjo blinklist:Trackbacks on Banjo furl:Trackbacks on Banjo reddit:Trackbacks on Banjo fark:Trackbacks on Banjo blogmarks:Trackbacks on Banjo Y!:Trackbacks on Banjo smarking:Trackbacks on Banjo magnolia:Trackbacks on Banjo segnalo:Trackbacks on Banjo gifttagging:Trackbacks on Banjo

4 responses so far ↓

  • 1 Malcolm Tredinnick // Nov 11, 2007 at 2:02 am

    A reasonably standard alternative for testing things like this is to write your own urlopen() mock and then do urllib.urlopen=my_version early in your code. urllib is only imported once, so the changes stick.

    You can hard-code it to be a hash-based function — for a given input string, return this hard-coded string back — in the simplest cases. I’ve often had to use this for unittesting socket-based distributed systems. Python’s designed to make it easy, too.

  • 2 Bruce // Nov 11, 2007 at 10:07 am

    Thanks Malcolm. I hadn’t thought of using a “monkey patch” in this case.

    I wonder if there is a way to monkey-patch the XMLRPC services to be available so that I can test actually performing the trackback against the test server.

  • 3 Neal McBurnett // Dec 1, 2007 at 3:44 pm

    See also the trackback code in the djog project at http://dev.oebfare.com/projects/djog/

  • 4 Kent Johnson // Dec 6, 2007 at 12:45 pm

    We just released a free (BSD license) blogging app for Django. It includes trackbacks, ping and comments with moderation and honeypot spam prevention. See today’s post for details: http://blog.blogcosm.com/2007/12/06/developers-we-just-released-blogmaker-free-blogging-app-django/

Leave a Comment