diff --git a/cachalot/tests/__init__.py b/cachalot/tests/__init__.py index 2f311e0..0f6501f 100644 --- a/cachalot/tests/__init__.py +++ b/cachalot/tests/__init__.py @@ -6,4 +6,5 @@ from .multi_db import MultiDatabaseTestCase from .settings import SettingsTestCase from .api import APITestCase, CommandTestCase from .signals import SignalsTestCase -from .postgres import PostgresReadTest +from .postgres import PostgresReadTestCase +from .debug_toolbar import DebugToolbarTestCase diff --git a/cachalot/tests/debug_toolbar.py b/cachalot/tests/debug_toolbar.py new file mode 100644 index 0000000..3467f67 --- /dev/null +++ b/cachalot/tests/debug_toolbar.py @@ -0,0 +1,30 @@ +from uuid import UUID +from bs4 import BeautifulSoup +from django.test import LiveServerTestCase, override_settings + + +@override_settings(DEBUG=True) +class DebugToolbarTestCase(LiveServerTestCase): + def test_rendering(self): + # + # Rendering toolbar + # + response = self.client.get('/') + self.assertEqual(response.status_code, 200) + soup = BeautifulSoup(response.content.decode('utf-8'), 'html.parser') + toolbar = soup.find(id='djDebug') + self.assertIsNotNone(toolbar) + store_id = toolbar.attrs['data-store-id'] + # Checks that store_id is a valid UUID. + UUID(store_id) + render_panel_url = toolbar.attrs['data-render-panel-url'] + panel_id = soup.find(title='Cachalot')['class'][0] + panel_url = ('%s?store_id=%s&panel_id=%s' + % (render_panel_url, store_id, panel_id)) + + # + # Rendering panel + # + panel_response = self.client.get(panel_url) + self.assertEqual(panel_response.status_code, 200) + # TODO: Check that the displayed data is correct. diff --git a/cachalot/tests/postgres.py b/cachalot/tests/postgres.py index d011ae3..5e6dbf6 100644 --- a/cachalot/tests/postgres.py +++ b/cachalot/tests/postgres.py @@ -31,7 +31,7 @@ if DJANGO_GTE_1_9: 'Caching psycopg2 objects is not working with file-based cache ' 'and Python 2.7 (see https://code.djangoproject.com/ticket/25501).') @override_settings(USE_TZ=True) -class PostgresReadTest(TransactionTestCase): +class PostgresReadTestCase(TransactionTestCase): def setUp(self): self.obj1 = PostgresModel( int_array=[1, 2, 3], diff --git a/runtests_requirements.txt b/runtests_requirements.txt index 87cc79e..4454cdc 100644 --- a/runtests_requirements.txt +++ b/runtests_requirements.txt @@ -7,3 +7,6 @@ python-memcached pylibmc pytz Jinja2 + +django-debug-toolbar +beautifulsoup4 diff --git a/runtests_urls.py b/runtests_urls.py new file mode 100644 index 0000000..572098c --- /dev/null +++ b/runtests_urls.py @@ -0,0 +1,13 @@ +import debug_toolbar +from django.conf.urls import url, include +from django.http import HttpResponse + + +def empty_page(request): + return HttpResponse('') + + +urlpatterns = [ + url(r'^$', empty_page), + url(r'^__debug__/', include(debug_toolbar.urls)), +] diff --git a/settings.py b/settings.py index 1db1a21..92322dd 100644 --- a/settings.py +++ b/settings.py @@ -118,8 +118,8 @@ TEMPLATES = [ ] -MIDDLEWARE_CLASSES = () -PASSWORD_HASHERS = ('django.contrib.auth.hashers.MD5PasswordHasher',) +MIDDLEWARE_CLASSES = [] +PASSWORD_HASHERS = ['django.contrib.auth.hashers.MD5PasswordHasher'] SECRET_KEY = 'it’s not important in tests but we have to set it' @@ -129,3 +129,41 @@ TIME_ZONE = 'UTC' CACHALOT_ENABLED = True + +# +# Settings for django-debug-toolbar +# + +INSTALLED_APPS += [ + 'django.contrib.staticfiles', + 'debug_toolbar', +] + +DEBUG_TOOLBAR_PANELS = [ + 'debug_toolbar.panels.versions.VersionsPanel', + 'debug_toolbar.panels.timer.TimerPanel', + 'debug_toolbar.panels.settings.SettingsPanel', + 'debug_toolbar.panels.headers.HeadersPanel', + 'debug_toolbar.panels.request.RequestPanel', + 'debug_toolbar.panels.sql.SQLPanel', + 'debug_toolbar.panels.staticfiles.StaticFilesPanel', + 'debug_toolbar.panels.templates.TemplatesPanel', + 'debug_toolbar.panels.cache.CachePanel', + 'debug_toolbar.panels.signals.SignalsPanel', + 'debug_toolbar.panels.logging.LoggingPanel', + 'debug_toolbar.panels.redirects.RedirectsPanel', + 'cachalot.panels.CachalotPanel', +] + +DEBUG_TOOLBAR_CONFIG = { + # Django’s test client sets wsgi.multiprocess to True inappropriately. + 'RENDER_PANELS': False, +} + +MIDDLEWARE_CLASSES += [ + 'debug_toolbar.middleware.DebugToolbarMiddleware', +] + +INTERNAL_IPS = ['127.0.0.1'] +ROOT_URLCONF = 'runtests_urls' +STATIC_URL = '/static/'