View integration tests use the same django.test.TestCase
class that a unit test does. An integration test will tell us if our project can route the request to the view and return the correct response. An integration test request will have to go through all the middleware and URL routing that a project is configured with. To help us write integration tests, Django provides TestCase.client
.
TestCase.client
is a utility offered by TestCase
to let us send HTTP requests to our project (it can't send external HTTP requests). Django processes these requests normally. client
also offers us convenience methods such as client.login()
, a way of starting an authenticated session. A TestCase
class also resets its client
between each test.
Let's write an integration test for QuestionDetailView
in django/qanda/tests.py
:
from django.test import TestCase from qanda.factories import QuestionFactory from user.factories import UserFactory QUESTION_CREATED_STRFTIME = '%Y-%m-%d...