Beispiel #1
0
def setup_test_environment():
    """Our own setup that hijacks Jinja template rendering."""
    global IS_SETUP
    if IS_SETUP:
        return
    IS_SETUP = True

    if HAS_JINJA2:
        old_render = jinja2.Template.render

        def instrumented_render(self, *args, **kwargs):
            context = dict(*args, **kwargs)
            test.signals.template_rendered.send(sender=self, template=self, context=context)
            return old_render(self, *args, **kwargs)

        jinja2.Template.render = instrumented_render

    try:
        from celery.app import current_app

        current_app().conf.CELERY_ALWAYS_EAGER = True
    except ImportError:
        pass

    try:
        import async_signals

        async_signals.stop_the_machine()
        settings.ASYNC_SIGNALS = False
    except ImportError:
        pass
Beispiel #2
0
def setup_test_environment():
    """Our own setup that hijacks Jinja template rendering."""
    global IS_SETUP
    if IS_SETUP:
        return
    IS_SETUP = True

    # Import here so it's not required to install test-utils.
    import jinja2
    old_render = jinja2.Template.render

    def instrumented_render(self, *args, **kwargs):
        context = dict(*args, **kwargs)
        test.signals.template_rendered.send(sender=self, template=self,
                                            context=context)
        return old_render(self, *args, **kwargs)

    jinja2.Template.render = instrumented_render

    try:
        from celery import conf
        conf.ALWAYS_EAGER = True
    except ImportError:
        pass

    try:
        import async_signals
        async_signals.stop_the_machine()
        settings.ASYNC_SIGNALS = False
    except ImportError:
        pass
Beispiel #3
0
def setup_test_environment():
    """Our own setup that hijacks Jinja template rendering."""
    global IS_SETUP
    if IS_SETUP:
        return
    IS_SETUP = True

    if HAS_JINJA2:
        old_render = jinja2.Template.render

        def instrumented_render(self, *args, **kwargs):
            context = dict(*args, **kwargs)
            test.signals.template_rendered.send(sender=self,
                                                template=self,
                                                context=context)
            return old_render(self, *args, **kwargs)

        jinja2.Template.render = instrumented_render

    try:
        from celery.app import current_app
        current_app().conf.CELERY_ALWAYS_EAGER = True
    except ImportError:
        pass

    try:
        import async_signals
        async_signals.stop_the_machine()
        settings.ASYNC_SIGNALS = False
    except ImportError:
        pass