Breaking out Django unit tests
Fri, 31 Oct 08, 06:27:26
filed in
Django
You can move models.py and views.py into seperate directories called models and views. I also make a directory to stick all my forms in called, excitingly enough, forms. But you can make a tests directory and put your tests in there. Grrr. A bit of Googling didn't get me too far, so a bit of reading of source got me this far.
The key is that Django will look to see if tests.py has a "suite" method, if so it will run it. This allows us to do what we'd like with the test runner.
So, make a directory called tests and put in it your unit tests, make a __init__.py and in that reference each of the modules you'd like to run tests on. Contents of my __init__.py:
import unittest
import browser
import site
__tests__ = [browser, site]
def suite():
suite = unittest.TestSuite()
tests = []
for test in __tests__:
tl = unittest.TestLoader().loadTestsFromModule(test)
tests += tl._tests
suite._tests = tests
return suite
My tests directory has a browser.py and site.py that contain unit tests. Adjust the imports and the __tests__ lists as you see fit for your instance. When I add a new file, I register it here.
Code swarm
Tue, 28 Oct 08, 14:41:44
filed in
Plone
Plone star Chris Calloway has been devoting time and lots of CPU time to generating code swarms for Plone and the Collective. It's been kinda fun to watch them and I confess look out for my own name. If you watch the Collective one, it's crazy with so many people. But I did spot an interesting one, bobbling around in the middle of the Collective for a while is troberts, that Toby Roberts of Enfold Systems to you and me. No-one is probably more surprised than Toby - a non-programmer and the Plone Foundation treasurer - to see himself in there. Go Toby!
Gibbering numbskulls
Tue, 28 Oct 08, 02:40:52
filed in
General
George Monbiot writes in the Guardian: How these gibbering numbskulls came to dominate Washington
Some choice quotes:
Perhaps the defining moment in the collapse of intelligent politics was Ronald Reagan's response to Jimmy Carter during the 1980 presidential debate. Carter - stumbling a little, using long words - carefully enumerated the benefits of national health insurance. Reagan smiled and said: "There you go again." His own health programme would have appalled most Americans, had he explained it as carefully as Carter had done...
On religion:
One theme is both familiar and clear: religion - in particular fundamentalist religion - makes you stupid. The US is the only rich country in which Christian fundamentalism is vast and growing.
On the media:
... perhaps the most potent reason intellectuals struggle in elections is that intellectualism has been equated with subversion. The brief flirtation of some thinkers with communism a long time ago has been used to create an impression in the public mind that all intellectuals are communists. Almost every day men such as Rush Limbaugh and Bill O'Reilly rage against the "liberal elites" destroying America.
Little fella
Mon, 27 Oct 08, 16:13:57
filed in
General
Going through our pictures from France, Danae snapped this one:
Making a table row clickable
Mon, 27 Oct 08, 16:05:14
filed in
clearwind
This one is quite old, but I just spent a bit of time fiddling with the listings page on Arecibo. I really hate that when I've got a table, I have just one link to view the item in the whole row, that's just unfriendly. So I did some googling and spent some doing exactly what I shouldn't of: fiddling with CSS and making it all into spans.
Today I remembered that tables in HTML are damn good at displaying tables and threw that out. Instead a quick jQuery can grab all the rows and make them link to the first link in the row:
$('table.listing tbody tr').bind("click", function() {
window.location = $(this).find("a").attr("href");
return false;
});
And remember to turn the cursor into a pointer so it looks more like a link:
cursor: pointer;
Elementary stuff, but i'll be able to find this code next time and the Arecibo user interface is just that bit nicer.
Bandwidth caps
Sun, 26 Oct 08, 15:49:28
filed in
England
Oh cry me a river, so Comcast is imposing a bandwidth cap of 250gb. Bleepin' heck. Come live in a third world country like the UK where you get 15gb a month. And that costs an arm and a leg.
Its survey found that 56% of broadband providers who advertised services as "unlimited" did impose usage caps and were prepared to cut people off if they used their service to excess.
Cite
Bad UI
Fri, 24 Oct 08, 03:53:27
filed in
General
This one's a cracker. Been doing some research on some things I've been wanting to do. As it turns out, everything has been done (surprise). But when I see how bad some of these things are, I get amazed. Of course bad doesn't mean its not popular (MySpace).
One interesting comparison was Final Fantasy XI and World of Warcraft. From starting up to getting into the game, the former is extremely stodgy, requiring something like 9 clicks as you get into something called PlayOnline, Square Enix's completely unused and ignored platform for playing games other than FFXI. Warcraft, login, select character, and you are in - fast and slick the usual Blizzard experience.
So today I took a quick look at trying to play Settlers of Catan online. After a frustrating sign up and Java client install, download I get this:
Thank god there's a dialog telling me to click on the mug to play a game. It's in the top left by the way. What are they thinking of.
The Boy in the Striped Pyjamas
Thu, 23 Oct 08, 16:02:49
filed in
England
Went to see the The Boy in the Striped Pyjamas tonight. I knew going in it was going to be a subject (the Holocaust) that I feel uncomfortable about. There's nothing like watching films about that subject to really start to hate humanity (and last night we watched Cry Freedom).
It was one of the, most moving films I've seen in a long time, would highly recommend it. At the credits it was dead quiet and hardly anyone moved. But I've no idea why the hell its rated as 12A, perhaps I'm being overly protective but I just can't see myself taking my 12 year old daughter there. Whilst things like sex and violence aren't present, the subject is quite complex. The boy behind me asked a few times, "what kind of camp is it?".
Debugging mod_python
Mon, 20 Oct 08, 14:14:17
filed in
Python
Today I had a small interesting project I didn't quite complete, but should do in the morning
its adding in a python authentication wrapper pulling from our LDAP server so that we can control our SVN and Trac access. We've already sort of got one, but it requires LDAP munging to move people around and instead we are moving that up to Python and so may as well give it a web interface in Django.
Some of the things I learned:
- mod_python has a very useful handler called
PythonAuthenHandler that allows you to just plugin a directive to get a peice of Python to handle authentication - documentation is online.
- There's a sample in the Django docs of using this handing directive.
- When it doesn't work you can get to a pdb in mod_python, called PythonEnablePdb, that is documented here.
- You will then need to start Apache using
-DONE_PROCESS and then you get a pdb and bob is your uncle.
Until you realise the LDAP data is dodgy. Tthere I was about to jump ship to mod_wsgi, but got the job done for now (almost)
2009 Calendar
Sun, 19 Oct 08, 13:07:55
filed in
General
Dear lazy web... just making some plans for speaking and other engagements in 2009. Does anyone have a calendar I can subscribe to off all Python, Django, Plone, JavaScript and Open Source techy events? Or maybe one of each that I can combine into one? Ta.
Bankers bonuses
Sat, 18 Oct 08, 02:05:46
filed in
General
Remind us again why they need bailing out?
At one point last week the Morgan Stanley $10.7bn pay pot for the year to date was greater than the entire stock market value of the business. In effect, staff, on receiving their remuneration, could club together and buy the bank.
http://www.guardian.co.uk/business/2008/oct/17/executivesalaries-banking
Moving from Django to Plone
Fri, 17 Oct 08, 13:32:30
filed in
Plone
Just found John DeRosa's blog: another Seattle person who's going for Plone. I single him out because he's going from Django to Plone and provides lots of insight. Since I've specifically gone the other way, there's some interesting things in there.
I swear blind I've chatted and worked with John in the past (anyone who has met me realises I have the people and face recognition skills of a goldfish) - after a glass of wine, I'll remember. Anyway it was surprising to read the blog posts and then figure out who it was. Some comments:
Inventing a word that’s vague, and confined to just your knowledge domain, is never betterish than using a realish word.
+10. He was talking about "folderish", but at the Plone conference in Naples I was complaining about the profusion of silly terminology in Plone. And yes "folderish" is used throughout my book, I followed the herd, what can I say? One of the few things I thought Moodle got right was that it didn't have portlets, viewlets, mambots (mambo) it had "HTML Blocks". Might not be 99% accurate but I got what it was first time.
Regarding buildout, XML and other configurations:
The problem with these other formats, aside from inherent syntactic problems, is the required mental context-switch when you move from one to the other. One moment your brain is in Python mode, and the next moment it must switch to XML mode. And some moments later, it has to switch to [insert idiosyncratic format here] mode
Lot's more on his site and one more to add to my RSS reader.
WebGUI compared to Plone
Thu, 16 Oct 08, 15:42:04
filed in
Plone
Donna Snow is implementing a WebGUI site and going to be blogging about it. I'm interested in this because Donna is a really nice person, but also because Donna is in interesting position in the Plone hierarchy.
Donna (and please correct me here if I'm wrong) runs a small consultancy producing web sites for customers. She doesn't have a huge army of technical programmers behind her. She focuses on finding a solution for a client mostly using existing tools that can be customised to her user. At the Planning sprint we she was placed in a category called "integrators".
This area was one of the reasons Plone became successful. Nothing raises the profile of a product like a small band of vocal integrators producing large numbers of excellent sites. This large number of small companies is a boon and contrasts strongly to say Alfresco.
A large number of competent and happy integrators is key to Plone, without them it will wither at either end as it slips into the domain of more and more technical obscurity know only to a few. They are one of the key bridges between the techies and customers.
But she's been feeling the pain with Plone 3 (she singles out viewlets).
As someone who works directly with clients in determining their requirements, there hasn’t been a single theme that we’ve done that didn’t require extensive changes to the viewlets (including different banners on inside sections and changes to drop downs in horizontal nav based on where you are located, etc etc). The fact that we have to turn off viewlets first, then add the new one and have to change at least 4 files to do that?? configure.zcml, viewlets.xml, viewlets.py and umm there was one more.
I've been feeling the pain with Plone 3. I took a step back at my Plone 3 product created by paster and the amount of stuff in there is absolutely mind boggling. From the sheer size of and number of files to the multiple concepts in there. Compared to Django, it is just shocking.
Anyway I'll be interested to see how that goes, what things she learns and hopefully the community will listen.
Why elections in Canada are better than the US
Tue, 14 Oct 08, 20:55:20
filed in
Canada
Passing (mostly) unknown to our neighbours to south, in the last month and a bit - Canada has called an election, done all nominations, campaigning and voted. As I write numbers are being counted by tomorrow we'll have a new prime minister (or maybe the old one again by the sound of it).
- No one mentions God. It might come by in passing, but that's about it. In fact in the UK when asked Nick Clegg gave an answer that would doom him in the US.
- No fixed terms, so no campaigning for years beforehand.
- Debates are forced in two languages, English and French. Although mono-lingual myself I do find it good that it forces leaders to know more than language. This isn't just campaign materials, the leaders have to get up on TV and argue in French. Of course for some this can be a disadvantage and for some - Stephen Harper's French is said to be weak - I think it creates for a broader outlook.
- No fixed terms. Oh wait did I say that already? Just get the damn US election over with and move on will you?
- More than two parties.
- We might actually get a Green MP elected this time. Maybe.
- No Sarah Palin. Actually she's kinda fun to watch and wonder who the hell would elect her.
By all means the system isn't perfect, lacking things like proportional representation. But to me the UK and Canada's systems of an unwritten constitution, Prime Minister's question time (oh wouldn't you love that in the US) make so much more sense.
Voter turnout: Canada around 64% source, US around 56% last election although trend is to show a drop below 50% source, UK over 60% source.
A wise man once said
Tue, 14 Oct 08, 20:40:03
filed in
General
That writing the software is the easy part. Selling and marketing it as an independent can be a lot harder. Well there's lots of quotes on that on the internet, just can't find the right one to match this sentiment.
But anyway this last week or so I'm finding that is true and I'm banging my head on the table for having the hubris to even think this shouldn't be the case for me. Just got to remember, these things take time and persistence is key.
Unless of course you are Apple, who keep me (and many others) glued to the edge of seat for every release and almost have made me despise my little curry stained ratty old MacBook. Watching a few people with Windows laptops on the train (I'm just about to take), will make me happier give me that slightly smug feeling once again.
Reminded of a quote
Fri, 10 Oct 08, 08:21:37
filed in
General
Listening to the news today, I was thinking of a quote from the great thinker Douglas Adams:
Magrathea is a myth, a fairy story, it's what parents tell their kids about at night if they want them to grow up to become economists
Will people be telling the story of 2008 in the future?
Fuzzy date and normalize
Wed, 08 Oct 08, 13:31:34
filed in
Ajax services
You can now get fuzzy date times such as 2 hours or 10 minutes (from Trac) in JSONP by hitting clearwind-labs. For example: http://clearwind-labs.appspot.com/fuzzydate?start=2008-10-06%2012:32:52.
Normalize is the Plone code for normalizing id's available as JSONP too: http://clearwind-labs.appspot.com/normalize?text=Österreich%20has%20GREAT%20beer
These are over at http://clearwind-labs.appspot.com/.
I could keep going on this theme for ages, must stop and get some useful stuff done instead.
Detecting browser strings
Sun, 05 Oct 08, 08:02:30
filed in
Ajax services
One thing that I needed to do in Arecibo was detect user agent strings. I finally found a library to do that. This weekend I spent a few minutes wrapping it and adding it in to my clearwind-labs site, running on Google App Engine. Given a user agent string it returns a JSON or JSONP data structure containing hopefully useful information.
Example: http://clearwind-labs.appspot.com/useragent.
|
About
Andy McKay works at Clearwind Consulting and can emailed at andy@clearwind.ca. If you are web developer, you need to try Arecibo.
Blogs
Months
-
All
-
February, 10
-
January, 10
-
December, 09
-
November, 09
-
October, 09
-
September, 09
-
August, 09
-
July, 09
-
June, 09
-
May, 09
-
April, 09
-
March, 09
-
February, 09
-
January, 09
-
December, 08
-
November, 08
-
October, 08
-
September, 08
-
August, 08
-
July, 08
-
June, 08
-
May, 08
-
April, 08
-
March, 08
-
February, 08
-
January, 08
-
December, 07
-
November, 07
-
October, 07
-
September, 07
-
August, 07
-
July, 07
-
June, 07
-
May, 07
-
April, 07
-
March, 07
-
February, 07
-
January, 07
-
December, 06
-
November, 06
-
October, 06
-
September, 06
-
August, 06
-
July, 06
-
June, 06
-
May, 06
Categories
|