Creates a test for CachalotPanel.
This commit is contained in:
parent
5965319688
commit
3dd3082575
|
@ -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
|
||||
|
|
|
@ -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.
|
|
@ -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],
|
||||
|
|
|
@ -7,3 +7,6 @@ python-memcached
|
|||
pylibmc
|
||||
pytz
|
||||
Jinja2
|
||||
|
||||
django-debug-toolbar
|
||||
beautifulsoup4
|
||||
|
|
|
@ -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)),
|
||||
]
|
42
settings.py
42
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/'
|
||||
|
|
Loading…
Reference in New Issue