django-analytical/analytical/tests/utils.py

57 lines
1.4 KiB
Python
Raw Normal View History

2011-01-21 01:01:40 +00:00
"""
Testing utilities.
"""
from __future__ import with_statement
from django.template import Template, Context, RequestContext
from django.test.testcases import TestCase
def run_tests():
2011-01-21 01:01:40 +00:00
"""
Use the Django test runner to run the tests.
Sets the return code to the number of failed tests.
2011-01-21 01:01:40 +00:00
"""
import sys
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()
sys.exit(runner.run_tests(["analytical"]))
2011-01-30 09:06:01 +00:00
class TagTestCase(TestCase):
"""
Tests for a template tag.
Adds support methods for testing template tags.
2011-01-30 09:06:01 +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)