Using RequestFactory

Just as we used RequestFactory in the last chapter to test the index view, let's use it to write a test for the view that we need. Add the following new class to the bottom of solos/tests/

class SoloViewTestCase(TestCase):

    def setUp(self):
        self.factory = RequestFactory()

    def test_basic(self):
        Test that the solo view returns a 200 response, uses
        the correct template, and has the correct context
        request = self.factory.get('/solos/1/')

        response = SoloDetailView.as_view()(

        self.assertEqual(response.status_code, 200)
        with self\

This should look familiar, ...

Get Test-Driven Development with Django now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.