views:

41

answers:

2

I haven't used Django's and Python's built in testing capabilities yet, but I want to finally start... And one of the most obvious things that I'd like to keep in check during the entire development process is that all my pages validate in all possible scenarios.

What's the best way to do this?

+3  A: 

Good question. I haven’t done this myself, so hopefully there will be some better answers, but you might want to look into HTML validation middleware:

“in all possible scenarios” might be too much to ask for, depending on your app. For example if you make the next Facebook, and are thus accepting huge amounts of user data every day, something will come in at some point that breaks the validity of a page on your site.

As validation errors don’t tend to destroy functionality, it might be an acceptable approach to check with some limited test data, then react to errors as they come up. I believe this is known as stupidity-driven testing.

Paul D. Waite
Thanks :) I'll look into it. I've seen the snippet link before but the rest is new to me (and I love the stupidity-driven testing concept :D). Yeah, I suppose "all possible scenarios" is asking for too much - just using flatpages can introduce plenty of invalid HTML into a site. However, I'm still curious whether there are any solutions in the manage.py test app_name vein and how the practicality of that vs the middleware approach compares. Love your answer though :)
Monika Sulik
Sure, fold it into your testing process. Not sure if anyone’s done the hard work, but I guess you need a way to go through your `urls.py` and generate as many possible URLs for the site as you can. Then you can use [the built-in Django test client](http://docs.djangoproject.com/en/dev/topics/testing/#module-django.test.client) to fetch all those urls, and [something else to validate them](http://stackoverflow.com/questions/35538/validate-xhtml-in-python).
Paul D. Waite
Thanks, I think your two answers are all I need :) Now it's up to me to try out what works best for me and in what situations :)
Monika Sulik
Best of luck — if you come up with something good, publish it and become famous!
Paul D. Waite
+1  A: 

Alternatively, a roll-your-own approach to validating pages on your site during your usual unit testing process would look something like this:

  1. Go through your urls.py and generate as many possible URLs for the site as you can
  2. Use the built-in Django test client to fetch each of those urls
  3. Validate them somehow (See perhaps http://stackoverflow.com/questions/35538/validate-xhtml-in-python)

Not sure if anyone’s done any of the work on this is a reusable way.

Paul D. Waite