summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBertrand Bordage <bordage.bertrand@gmail.com>2016-10-23 18:06:58 (GMT)
committerBertrand Bordage <bordage.bertrand@gmail.com>2016-10-23 18:06:58 (GMT)
commit3dd30825757d1c83db7357e675475e2c1a691461 (patch)
tree7baee361abdf3f5d8936eb625941576d0af1d788
parent59653196884d9494bee0333a77031cfacdded523 (diff)
downloaddjango-cachalot-3dd30825757d1c83db7357e675475e2c1a691461.zip
django-cachalot-3dd30825757d1c83db7357e675475e2c1a691461.tar.gz
django-cachalot-3dd30825757d1c83db7357e675475e2c1a691461.tar.bz2
Creates a test for CachalotPanel.
-rw-r--r--cachalot/tests/__init__.py3
-rw-r--r--cachalot/tests/debug_toolbar.py30
-rw-r--r--cachalot/tests/postgres.py2
-rw-r--r--runtests_requirements.txt3
-rw-r--r--runtests_urls.py13
-rw-r--r--settings.py42
6 files changed, 89 insertions, 4 deletions
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('<body></body>')
+
+
+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/'