diff options
Diffstat (limited to 'tests/context_processors')
| -rw-r--r-- | tests/context_processors/models.py | 5 | ||||
| -rw-r--r-- | tests/context_processors/templates/context_processors/debug.html | 15 | ||||
| -rw-r--r-- | tests/context_processors/tests.py | 30 | ||||
| -rw-r--r-- | tests/context_processors/urls.py | 1 | ||||
| -rw-r--r-- | tests/context_processors/views.py | 13 |
5 files changed, 63 insertions, 1 deletions
diff --git a/tests/context_processors/models.py b/tests/context_processors/models.py new file mode 100644 index 0000000000..cc1c8f766b --- /dev/null +++ b/tests/context_processors/models.py @@ -0,0 +1,5 @@ +from django.db import models + + +class DebugObject(models.Model): + pass diff --git a/tests/context_processors/templates/context_processors/debug.html b/tests/context_processors/templates/context_processors/debug.html new file mode 100644 index 0000000000..671ab81372 --- /dev/null +++ b/tests/context_processors/templates/context_processors/debug.html @@ -0,0 +1,15 @@ +{% if debug == True %} + +Have debug + +First query list: {{ sql_queries|length }} + +{% for obj in debug_objects.all %}{{ obj }}{% endfor %} + +Second query list: {{ sql_queries|length }} + +{% for obj in debug_objects.all %}{{ obj }}{% endfor %} + +Third query list: {{ sql_queries|length }} + +{% endif %} diff --git a/tests/context_processors/tests.py b/tests/context_processors/tests.py index 98342f28c2..44f36a4267 100644 --- a/tests/context_processors/tests.py +++ b/tests/context_processors/tests.py @@ -33,3 +33,33 @@ class RequestContextProcessorTests(TestCase): self.assertContains(response, url) response = self.client.post(url, {'path': '/blah/'}) self.assertContains(response, url) + + +@override_settings(ROOT_URLCONF='context_processors.urls', DEBUG=True, INTERNAL_IPS=('127.0.0.1',)) +class DebugContextProcessorTests(TestCase): + """ + Tests for the ``django.core.context_processors.debug`` processor. + """ + + def test_debug(self): + url = '/debug/' + # We should have the debug flag in the template. + response = self.client.get(url) + self.assertContains(response, 'Have debug') + + # And now we should not + with override_settings(DEBUG=False): + response = self.client.get(url) + self.assertNotContains(response, 'Have debug') + + def test_sql_queries(self): + """ + Test whether sql_queries represents the actual amount + of queries executed. (#23364) + """ + url = '/debug/' + response = self.client.get(url) + self.assertContains(response, 'First query list: 0') + self.assertContains(response, 'Second query list: 1') + # Check we have not actually memoized connection.queries + self.assertContains(response, 'Third query list: 2') diff --git a/tests/context_processors/urls.py b/tests/context_processors/urls.py index a7c0d1b4b0..f68720d581 100644 --- a/tests/context_processors/urls.py +++ b/tests/context_processors/urls.py @@ -5,4 +5,5 @@ from . import views urlpatterns = [ url(r'^request_attrs/$', views.request_processor), + url(r'^debug/$', views.debug_processor), ] diff --git a/tests/context_processors/views.py b/tests/context_processors/views.py index 66e7132c05..7a00edab0a 100644 --- a/tests/context_processors/views.py +++ b/tests/context_processors/views.py @@ -2,7 +2,18 @@ from django.core import context_processors from django.shortcuts import render_to_response from django.template.context import RequestContext +from .models import DebugObject + def request_processor(request): - return render_to_response('context_processors/request_attrs.html', + return render_to_response( + 'context_processors/request_attrs.html', RequestContext(request, {}, processors=[context_processors.request])) + + +def debug_processor(request): + return render_to_response( + 'context_processors/debug.html', + RequestContext(request, { + 'debug_objects': DebugObject.objects, + }, processors=[context_processors.debug])) |
