[TIP] Testing django redirects/render

andrea crotti 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:

    def test_new_invalid_form_shows_challenges_dropdown(self):
        without_ch = ideas_forms.NewIdeaForm(request=FakeRequest(),
data={'title': 'title'})
        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
other ways?

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...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20130423/a4643a46/attachment.htm>

More information about the testing-in-python mailing list