O'Reilly logo

Test-Driven Development with Django by Kevin Harvey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

RequestFactory versus TestClient

You may have noticed something funny about the last test: we made a request using the RequestFactory instance, passing it a path that does not exist in urls.py yet. Why did we have to do that?

Recall that a Django view is simply any function that accepts a request and returns a response. RequestFactory creates a bare-bones WSGIRequest for the first argument of a view without actually going through the Django framework (URL routing, middleware, and so on). We provide the first argument (path as a keyword) simply because you can't have a WSGIRequest without a path. The actual argument is irrelevant, unless you're using it in the course of your view logic (meaning both /solos/1/ and /solos/foo/ would have let the test ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required