aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAymeric Augustin2013-11-16 20:32:46 +0100
committerAymeric Augustin2013-11-16 20:32:46 +0100
commit13266d8c561498879f6519b8f03039d90a0a36cd (patch)
tree94241f429faeaddc20a4b3a281ff1be86f9fe1f7
parentac79628d31040a5500b4d10534ee09174523b763 (diff)
downloaddjango-debug-toolbar-13266d8c561498879f6519b8f03039d90a0a36cd.tar.bz2
Add Selenim test.
-rw-r--r--Makefile4
-rw-r--r--docs/contributing.rst13
-rw-r--r--requirements_dev.txt1
-rw-r--r--tests/settings.py2
-rw-r--r--tests/test_integration.py37
-rw-r--r--tox.ini1
6 files changed, 56 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index c52bd2e..a7d4baf 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,10 @@ test:
DJANGO_SETTINGS_MODULE=tests.settings PYTHONPATH=. \
django-admin.py test tests
+test_selenium:
+ DJANGO_SELENIUM_TESTS=true DJANGO_SETTINGS_MODULE=tests.settings PYTHONPATH=. \
+ django-admin.py test tests
+
coverage:
coverage erase
DJANGO_SETTINGS_MODULE=tests.settings PYTHONPATH=. \
diff --git a/docs/contributing.rst b/docs/contributing.rst
index 8c8a49b..e489998 100644
--- a/docs/contributing.rst
+++ b/docs/contributing.rst
@@ -46,8 +46,19 @@ Python::
This is strongly recommended before committing changes to Python code.
+The test suite includes frontend tests written with Selenium. Since they're
+annoyingly slow, they're disabled by default. You can run them as follows::
+
+ $ make test_selenium
+
+or by setting the ``DJANGO_SELENIUM_TESTS`` environment variable::
+
+ $ DJANGO_SELENIUM_TESTS=true make test
+ $ DJANGO_SELENIUM_TESTS=true make coverage
+ $ DJANGO_SELENIUM_TESTS=true tox
+
At this time, there isn't an easy way to test against databases other than
-SQLite. The JaveScript code isn't tested either.
+SQLite.
Style
-----
diff --git a/requirements_dev.txt b/requirements_dev.txt
index e33a4a5..8d7af92 100644
--- a/requirements_dev.txt
+++ b/requirements_dev.txt
@@ -11,6 +11,7 @@ sqlparse
coverage
flake8
+selenium
tox
# Documentation
diff --git a/tests/settings.py b/tests/settings.py
index 4805cee..24e0cd4 100644
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -24,6 +24,8 @@ INSTALLED_APPS = [
'tests',
]
+MEDIA_URL = '/media/' # Avoids https://code.djangoproject.com/ticket/21451
+
MIDDLEWARE_CLASSES = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
diff --git a/tests/test_integration.py b/tests/test_integration.py
index 19cb77a..9a3fbcc 100644
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -2,10 +2,19 @@
from __future__ import unicode_literals
+import os
from xml.etree import ElementTree as ET
-from django.test import TestCase, RequestFactory
+try:
+ from selenium import webdriver
+ from selenium.common.exceptions import NoSuchElementException
+ from selenium.webdriver.support.wait import WebDriverWait
+except ImportError:
+ webdriver = None
+
+from django.test import LiveServerTestCase, RequestFactory, TestCase
from django.test.utils import override_settings
+from django.utils.unittest import skipIf, skipUnless
from debug_toolbar.middleware import DebugToolbarMiddleware, show_toolbar
@@ -92,3 +101,29 @@ class DebugToolbarIntegrationTestCase(TestCase):
def test_xml_validation(self):
response = self.client.get('/regular/XML/')
ET.fromstring(response.content) # shouldn't raise ParseError
+
+
+@skipIf(webdriver is None, "selenium isn't installed")
+@skipUnless('DJANGO_SELENIUM_TESTS' in os.environ, "selenium tests not requested")
+@override_settings(DEBUG=True)
+class DebugToolbarLiveTestCase(LiveServerTestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ super(DebugToolbarLiveTestCase, cls).setUpClass()
+ cls.selenium = webdriver.Firefox()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.selenium.quit()
+ super(DebugToolbarLiveTestCase, cls).tearDownClass()
+
+ def test_basic(self):
+ self.selenium.get(self.live_server_url + '/regular/basic/')
+ version_button = self.selenium.find_element_by_class_name('VersionDebugPanel')
+ version_panel = self.selenium.find_element_by_id('VersionDebugPanel')
+ with self.assertRaises(NoSuchElementException):
+ version_panel.find_element_by_tag_name('table')
+ version_button.click() # load contents of the version panel
+ WebDriverWait(self.selenium, timeout=10).until(
+ lambda selenium: version_panel.find_element_by_tag_name('table'))
diff --git a/tox.ini b/tox.ini
index b7fb6f0..3ed353a 100644
--- a/tox.ini
+++ b/tox.ini
@@ -15,6 +15,7 @@ envlist =
[testenv]
commands = make test
deps =
+ selenium
sqlparse
whitelist_externals = make