Ticket #15730: requestfactory-with-cbvs.patch

File requestfactory-with-cbvs.patch, 939 bytes (added by bryanveloso, 4 years ago)
  • docs/topics/testing.txt

    diff --git docs/topics/testing.txt docs/topics/testing.txt
    index 4176857..43fa240 100644
    The following is a simple unit test using the request factory:: 
    10681068    from django.utils import unittest
    10691069    from django.test.client import RequestFactory
    10701070
     1071    from .views import my_view
     1072
    10711073    class SimpleTest(unittest.TestCase):
    10721074        def setUp(self):
    10731075            # Every test needs access to the request factory.
    The following is a simple unit test using the request factory:: 
    10811083            response = my_view(request)
    10821084            self.assertEqual(response.status_code, 200)
    10831085
     1086The above example uses a functional-based view. If you are using
     1087:doc:`class-based generic views </topics/class-based-views>`, the ``response``
     1088line would be written as follows::
     1089
     1090        response = MyClassBasedView.as_view()(request)
     1091
    10841092TestCase
    10851093--------
    10861094
Back to Top