class SomePageTest(TestCase):

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

def test_some_page_requires_session_middleware(self):
    request = self.factory.get('somepage.html')
middleware = SessionMiddleware()
middleware.process_request(request)
request.session.save()
response = SomeView.as_view()(request)
self.assertEqual(response.status_code, 200)
Протестируйте представления Django, требующие входа в систему, с помощью RequestFactory.