I have been struggling for a while to get a test suite running for my Django-CMS sites, and had a breakthrough today which I hope can help others.
There were two problems.
I would get a string of errors like this:
FATAL ERROR - The following SQL query failed: SELECT kc.constraint_name, kc.column_name, c.constraint_type FROM information_schema.constraint_column_usage AS kc JOIN information_schema.table_constraints AS c ON kc.table_schema = c.table_schema AND kc.table_name = c.table_name AND kc.constraint_name = c.constraint_name WHERE kc.table_schema = %s AND kc.table_name = %s The error was: no such table: information_schema.constraint_column_usage
This is actually a South problem. You need to add some lines to your
import sys if 'test' in sys.argv: SOUTH_TESTS_MIGRATE = False
Thanks to this Stackoverflow post for that solution, though it does not mention the above error. That post also points out that using a sqlite database for tests is much faster.
The second problem was this:
TemplateSyntaxError: You must enable the 'sekizai.context_processors.sekizai' template context processor or use 'sekizai.context.SekizaiContext' to render your templates.
This was confusing because I was using sekizai correctly in my template.
This post pointed me in the right direction here. The problem was Django was raising an exception but I was never getting to see it – just this much less helpful message.
This Stackoverflow post explained how to enable logging of errors. I copied in the changes to
settings.py, wrapping them inside the
if 'test' statement.
Then when I ran
I got a much more useful error message: I had forgotten to set up a table that my template was assuming would exist. Easily fixed!
Hope that helps someone else.
My first, simple, test looks like this:
from django.test import TestCase from django.contrib.auth.models import User from cms.api import create_page, add_plugin import myapp.models def create_globals(): """ The templates assume this exists """ return myapp.models.GlobalSettings.objects.create() class FirstTest(TestCase): def test_template(self): """ Test the template can load """ create_globals() superuser = User.objects.create_superuser('admin', 'email@example.com', 'admin') template="test.html" page = create_page("home", template, "en", created_by=superuser, published=True) page = create_page("second_test", template, "en", created_by=superuser, published=True) response = self.client.get('/') response = self.client.get('/second_test/')
I have recently discovered this book by Harry Percival, on how to incorporate testing into your Django site. I highly recommend it.