django-analytical/analytical/tests/utils.py
David Smith 74ddb4f0e0 Updated supported versions of Python and Django
Dropped Python2.7/3.5 and Django 1.11 from test matrix

Removed Py2 code and updated for Py3 features

Replaced assertRaisesRegexp with AsserRaisesRegex

Updated setup.py for currently supported versions

Removed _timestamp
2020-11-30 22:35:33 +00:00

34 lines
922 B
Python

"""
Testing utilities.
"""
from django.template import Template, Context, RequestContext
from django.test.testcases import TestCase
class TagTestCase(TestCase):
"""
Tests for a template tag.
Adds support methods for testing template tags.
"""
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)
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)