def assertPaginationNumQueries(self, num_queries, template, queryset=None):
        """Assert the expected *num_queries* are actually executed.

        The given *queryset* is paginated using *template*. If the *queryset*
        is not given, a default queryset containing 47 model instances is used.
        In the *template*, the queryset must be referenced as ``objects``.

        Return the resulting list of objects for the current page.
        """
        if queryset is None:
            queryset = make_model_instances(47)
        request = self.request()
        with self.assertNumQueries(num_queries):
            _, context = self.render(request, template, objects=queryset)
            objects = list(context['objects'])
        return objects
    def assertPaginationNumQueries(self, num_queries, template, queryset=None):
        """Assert the expected *num_queries* are actually executed.

        The given *queryset* is paginated using *template*. If the *queryset*
        is not given, a default queryset containing 47 model instances is used.
        In the *template*, the queryset must be referenced as ``objects``.

        Return the resulting list of objects for the current page.
        """
        if queryset is None:
            queryset = make_model_instances(47)
        request = self.request()
        with self.assertNumQueries(num_queries):
            _, context = self.render(request, template, objects=queryset)
            objects = list(context['objects'])
        return objects
Beispiel #3
0
 def test_model_ajax(self):
     # Ensure the model view switches templates when the request is Ajax.
     queryset = make_model_instances(30)
     view = self.make_view(model=TestModel)
     response = view(self.ajax_request)
     self.check_response(response, self.model_page_template, queryset)
Beispiel #4
0
 def test_model(self):
     # Ensure the view correctly uses the model to generate the template.
     queryset = make_model_instances(30)
     view = self.make_view(model=TestModel)
     response = view(self.request)
     self.check_response(response, self.model_template_name, queryset)
Beispiel #5
0
 def test_queryset(self):
     # Ensure the view correctly adds the queryset to context.
     queryset = make_model_instances(30)
     view = self.make_view(queryset=queryset)
     response = view(self.request)
     self.check_response(response, self.model_template_name, queryset)
 def test_model_ajax(self):
     # Ensure the model view switches templates when the request is Ajax.
     queryset = make_model_instances(30)
     view = self.make_view(model=TestModel)
     response = view(self.ajax_request)
     self.check_response(response, self.model_page_template, queryset)
 def test_model(self):
     # Ensure the view correctly uses the model to generate the template.
     queryset = make_model_instances(30)
     view = self.make_view(model=TestModel)
     response = view(self.request)
     self.check_response(response, self.model_template_name, queryset)
 def test_queryset(self):
     # Ensure the view correctly adds the queryset to context.
     queryset = make_model_instances(30)
     view = self.make_view(queryset=queryset)
     response = view(self.request)
     self.check_response(response, self.model_template_name, queryset)