← Back to team overview

canonical-django team mailing list archive

Re: Django testing best practices

 

On Mon, 14 Jun 2010 10:35:39 +0100, Nick Moffitt <nick@xxxxxxxxxxxxx> wrote:
> This is a difficult problem, and one I've run into a few times.  The
> general permissiveness of sqlite3 (and the lack of reimplementation of
> the various constraints within the ORM) has led to situations where I've
> deployed a fixture to staging only to find it won't work with the limits
> I put on my models.  I have, in some cases, re-implemented length
> constraints in my views.  

I'm glad I'm not the only one to have seen this.

> > As we add more behaviour to models we will be testing that, and it was
> > agreed that this was where most of the logic should be pushed too, so
> > views are as simple as possible.
> 
> I have this feeling that models ought to have more methods than we
> typically give them.  Often when we refactor some complicated query
> logic out of a view function, we leave it in our views.py; but perhaps
> we ought to be moving more testable representation logic into our
> models.

I agree, that's what we said that we would push towards.

> > Django has facilities for testing that a view rendered using a
> > particular template, and the paramaters that were passed to a template,
> > and we agreed that it would be worthwhile trying to take advantage of
> > that.
> 
> The Django test client is superb, and I love it to bits.

I agree that it's good, but there needs to be better assertion
capabilities associated with it.

> > If there are lots of ideas then I will collate them in to a wiki page
> > that we can maintain we learn more.
> 
> I would love a good wiki resource for this, maybe even out on a public
> wiki somewhere.

Yeah, even pushing things in to the docs where it talks about testing
would be good.

Thanks,

James



References