2011-01-21 01:01:40 +00:00
|
|
|
"""
|
|
|
|
|
Testing utilities.
|
|
|
|
|
"""
|
|
|
|
|
|
2011-06-28 17:57:58 +00:00
|
|
|
from __future__ import with_statement
|
2011-07-05 05:12:58 +00:00
|
|
|
|
2011-01-30 01:50:49 +00:00
|
|
|
from django.template import Template, Context, RequestContext
|
2011-07-04 12:07:56 +00:00
|
|
|
from django.test.testcases import TestCase
|
2011-06-29 06:10:02 +00:00
|
|
|
|
2015-09-08 20:35:06 +00:00
|
|
|
|
2011-06-29 17:46:27 +00:00
|
|
|
def run_tests():
|
2011-01-21 01:01:40 +00:00
|
|
|
"""
|
|
|
|
|
Use the Django test runner to run the tests.
|
2011-09-17 18:26:19 +00:00
|
|
|
|
|
|
|
|
Sets the return code to the number of failed tests.
|
2011-01-21 01:01:40 +00:00
|
|
|
"""
|
2011-09-17 18:26:19 +00:00
|
|
|
import sys
|
2014-09-05 19:26:08 +00:00
|
|
|
import django
|
|
|
|
|
try:
|
|
|
|
|
django.setup()
|
|
|
|
|
except AttributeError:
|
|
|
|
|
pass
|
|
|
|
|
try:
|
|
|
|
|
from django.test.runner import DiscoverRunner as TestRunner
|
|
|
|
|
except ImportError:
|
|
|
|
|
from django.test.simple import DjangoTestSuiteRunner as TestRunner
|
|
|
|
|
runner = TestRunner()
|
2011-09-17 18:26:19 +00:00
|
|
|
sys.exit(runner.run_tests(["analytical"]))
|
2011-01-30 01:50:49 +00:00
|
|
|
|
|
|
|
|
|
2011-01-30 09:06:01 +00:00
|
|
|
class TagTestCase(TestCase):
|
|
|
|
|
"""
|
|
|
|
|
Tests for a template tag.
|
|
|
|
|
|
2011-07-04 12:07:56 +00:00
|
|
|
Adds support methods for testing template tags.
|
2011-01-30 09:06:01 +00:00
|
|
|
"""
|
|
|
|
|
|
2011-01-30 01:50:49 +00:00
|
|
|
def render_tag(self, library, tag, vars=None, request=None):
|
|
|
|
|
if vars is None:
|
|
|
|
|
vars = {}
|
|
|
|
|
t = Template("{%% load %s %%}{%% %s %%}" % (library, tag))
|
|
|
|
|
if request is not None:
|
|
|
|
|
context = RequestContext(request, vars)
|
|
|
|
|
else:
|
|
|
|
|
context = Context(vars)
|
|
|
|
|
return t.render(context)
|
2012-02-27 00:15:33 +00:00
|
|
|
|
|
|
|
|
def render_template(self, template, vars=None, request=None):
|
|
|
|
|
if vars is None:
|
|
|
|
|
vars = {}
|
|
|
|
|
t = Template(template)
|
|
|
|
|
if request is not None:
|
|
|
|
|
context = RequestContext(request, vars)
|
|
|
|
|
else:
|
|
|
|
|
context = Context(vars)
|
|
|
|
|
return t.render(context)
|