[TIP] Testing django redirects/render
andrea.crotti.0 at gmail.com
Tue Apr 23 08:59:13 PDT 2013
I'm setting up a whole testing infrastructure for our project, that uses
bottle for the backend and django for the fronted.
We have a suite of unit tests for the backend and for django.
The nice thing about this is that I set up a git pre-commit hook so that
everyone runs always all the te
sts (almost 200) and it takes less than 2 seconds.
For django for eaxmple I test forms in a similar way:
without_ch = ideas_forms.NewIdeaForm(request=FakeRequest(),
rendered = without_ch.fields['challenge'].widget.render('x', 'y')
so I check the rendering of the widget, the validation and so on.
Then I also test all the "pure" functions that are not doing rendering and
Now I would also like to unit test the render and redirects, but I am a bit
in trouble because for example redirects try to do a reverse routing, which
then fails in the unit tests.
One way would be to mock redirect and just check that it gets called with
the right arguments which would already be good enough, but maybe there are
I don't really want to use the django client, because it's too slow and
they would not be unit tests anymore. In plus for integration tests I would
rather spend time with selenium, that at least really checks the whole flow.
What do you think?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python