The Django test client lets a test interact with a Django application without opening a browser. It sends GET and POST requests through URL routing, renders templates, and returns a response containing the status code, rendered content, and template context. JavaScript does not run, so this is a fast way to test server-side behavior rather than full browser interaction. section 8.2
Testing the credits view
A minimal test uses Django's TestCase and its client object: from django.test import TestCase class TestHome(TestCase): def test_credits(self): response = self.client.get("/credits/") self.assertEqual(200, response.status_code) The call travels through the URL router to the view. The assertion then checks that the view returned HTTP 200. Run it with `python manage.py test`; Django creates the test database, runs the test, and destroys that database afterward. section 8.2
Use the client to exercise more realistic request paths:
- Call `client.post()` with a dictionary of form data, including file handles for upload tests. section 8.10
- Call `client.login()` after creating a test user to visit authentication-protected pages. section 8.10
- Check negative cases such as a 404 response, not only successful status codes. section 8.10
