In case there are others following this topic, I have the test system
working.  I ended up putting a couple of functions in the contrib
folder of my django installation under the mako_django folder.  The
functions emulate the behavior of the instrumented_test_render and
run_tests functions from django.test.utils an django.test.simple
respectively.  This is pretty much the simplest scheme I could come up
with, and I'm sure a different implementation would provide more
features.  However, it does allow you to access the template and
context members of the result when using the django test client.

Russ -- Thanks for your help.  After browsing around in the code, I
think the process for adding at least this much test functionality for
an external template system was relatively painless.  I would welcome
any comments (or corrections) regarding this solution if you have
them.  As far as improvements, I think all that's really needed is a
little howto (to which I would be happy to contribute).  It seemed
easy enough at least in this case that adding special support might be
overkill.


If anyone wants to try it, what I did was to put the following code in
django/contrib/mako_django/__init__.py:

# ******* __init__.py ********
# mako_django unit test integration.  In order to install, I recommend
# placing this file in a folder called "mako_django" in the contrib
# section of your django install.  This might be a stupid
# recommendation, so if it seems that way or someone else says so,
# assume they're right.

#**** This is ALPHA code (at best) so use with caution. ******

# Written by Erik Lee

# You have my permission to do anything you want with this code

from django.test.utils import setup_test_environment,
teardown_test_environment
from django.test.simple import run_tests
from mako.template import Template
from django.template.context import Context
from django.test import signals

def instrumented_test_render(self,**context):
    """
    This function calls the template's render function with the given
    rendering context, and then sends the template_rendered signal
    with the context and the template being rendered in order to
    integrate more fully with django's unit test system.  It seems to
    behave properly on my system.
    """
    self.pretest_render(**context)
    signals.template_rendered.send(sender=self, template=self,
context=Context(context))



def run_mako_tests(test_labels, verbosity, interactive):
    """
    This function simply hijacks the mako template renderer's render
    function with a simple wrapper (instrumented_test_render) that
    will trigger the template_rendered signal after rendering the
    template.  After the tests are run (using the default test runner
    provided in the django distribution, it restores the rendering
    function to its original state.  During the tests, the original
    function can be accessed through the name "pretest_render"
    """
    Template.pretest_render = Template.render
    Template.render = instrumented_test_render
    result = run_tests(test_labels, verbosity, interactive)
    Template.render = Template.pretest_render
    return result

# **** end __init__.py *****

Erik


--snip--
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to