Beispiel #1
0
def test_render_hooks():
    old_hooks, tg.hooks = tg.hooks, _TGGlobalHooksNamespace()

    calls = []
    def render_call_hook(*args, **kw):
        calls.append(1)

    base_config = TestConfig(folder='rendering', values={
        'use_sqlalchemy': False,
        'use_legacy_renderer': False,
        # this is specific to mako  to make sure inheritance works
        'use_dotted_templatenames': False,
        'use_toscawidgets': False,
        'use_toscawidgets2': False
    })

    milestones._reset_all()
    base_config.register_hook('before_render_call', render_call_hook)
    base_config.register_hook('after_render_call', render_call_hook)
    app = app_from_config(base_config, reset_milestones=False)
    app.get('/')

    try:
        assert len(calls) == 2
    finally:
        tg.hooks = old_hooks
Beispiel #2
0
def setup_noDB():
    global_config = {
        'debug': 'true',
        'error_email_from': 'paste@localhost',
        'smtp_server': 'localhost'
    }

    base_config = TestConfig(folder='config', values={'use_sqlalchemy': False})

    env_loader = base_config.make_load_environment()
    app_maker = base_config.setup_tg_wsgi_app(env_loader)
    app = TestApp(app_maker(global_config, full_stack=True))
    return app
Beispiel #3
0
def setup_noDB():
    global_config = {'debug': 'true', 
                     'error_email_from': 'paste@localhost', 
                     'smtp_server': 'localhost'}
    
    base_config = TestConfig(folder = 'config', 
                             values = {'use_sqlalchemy': False}
                             )
                             
    env_loader = base_config.make_load_environment()
    app_maker = base_config.setup_tg_wsgi_app(env_loader)
    app = TestApp(app_maker(global_config, full_stack=True))
    return app 
    def test_hooks_syswide(self):
        base_config = TestConfig(folder = 'dispatch',
                                 values = {'use_sqlalchemy': False,
                                           'use_toscawidgets': False,
                                           'use_toscawidgets2': False,
                                           'ignore_parameters': ["ignore", "ignore_me"]
                                 })

        def hook(*args, **kw):
            tg.tmpl_context.echo = 'WORKED'

        base_config.register_hook('before_call', hook)
        app = app_from_config(base_config, reset_milestones=False)

        ans = app.get('/echo')
        assert 'WORKED' in ans
Beispiel #5
0
def setup_noDB():
    base_config = TestConfig(folder='config',
                             values={
                                 'use_sqlalchemy': False,
                                 'pylons.tmpl_context_attach_args': False
                             })
    return app_from_config(base_config)
Beispiel #6
0
def setup_noDB():
    base_config = TestConfig(folder='dispatch',
                             values={
                                 'use_sqlalchemy': False,
                                 'ignore_parameters': ["ignore", "ignore_me"]
                             })
    return app_from_config(base_config)
Beispiel #7
0
def test_jinja_custom_filters():
    # Simple test filter to get a md5 hash of a string
    def codify(value):
        try:
            from hashlib import md5
        except ImportError:
            from md5 import md5
        string_hash = md5(value)
        return string_hash.hexdigest()

    base_config = TestConfig(folder = 'rendering',
                             values = {'use_sqlalchemy': False,
                                       'pylons.helpers': Bunch(),
                                       'use_legacy_renderer': False,
                                       # this is specific to mako
                                       # to make sure inheritance works
                                       'use_dotted_templatenames': False,
                                       'pylons.tmpl_context_attach_args': False,
                                       'renderers':['jinja'],
                                       'jinja_filters': {'codify': codify}
                                       }
                             )
    app = app_from_config(base_config)
    resp = app.get('/jinja_filters')
    assert '8bb23e0b574ecb147536efacc864891b' in resp, resp
Beispiel #8
0
def test_render_hooks():
    old_hooks, tg.hooks = tg.hooks, _TGGlobalHooksNamespace()

    calls = []

    def render_call_hook(*args, **kw):
        calls.append(1)

    base_config = TestConfig(
        folder='rendering',
        values={
            'use_sqlalchemy': False,
            'use_legacy_renderer': False,
            # this is specific to mako  to make sure inheritance works
            'use_dotted_templatenames': False,
            'use_toscawidgets': False,
            'use_toscawidgets2': False
        })

    milestones._reset_all()
    tg.hooks.register('before_render_call', render_call_hook)
    tg.hooks.register('after_render_call', render_call_hook)
    app = app_from_config(base_config, reset_milestones=False)
    app.get('/')

    try:
        assert len(calls) == 2
    finally:
        tg.hooks = old_hooks
Beispiel #9
0
def test_template_override_wts():
    #    app = setup_noDB()
    base_config = TestConfig(
        folder='rendering',
        values={
            'use_sqlalchemy': False,
            'use_legacy_renderer': False,
            # this is specific to mako
            # to make sure inheritance works
            'use_dotted_templatenames': True,
            'renderers': ['genshi'],
            'use_toscawidgets': False,
            'use_toscawidgets2': False
        })
    app = app_from_config(base_config)
    r = app.get('/template_override_wts',
                status=301)  # ensure with_trailing_slash
    r = app.get('/template_override_wts/')
    assert "Not overridden" in r, r
    r = app.get('/template_override_wts/', params=dict(override=True))
    assert "This is overridden." in r, r
    # now invoke the controller again without override,
    # it should yield the old result
    r = app.get('/template_override_wts/')
    assert "Not overridden" in r, r
Beispiel #10
0
def setup_noDB(genshi_doctype=None, genshi_method=None, genshi_encoding=None, extra=None,
               extra_init=None):
    base_config = TestConfig(folder='rendering', values={
        'use_sqlalchemy': False,
       'use_legacy_renderer': False,
       # this is specific to mako  to make sure inheritance works
       'use_dotted_templatenames': False,
       'use_toscawidgets': False,
       'use_toscawidgets2': False
    })

    deployment_config = {}
    # remove previous option value to avoid using the old one
    tg.config.pop('templating.genshi.doctype', None)
    if genshi_doctype:
        deployment_config['templating.genshi.doctype'] = genshi_doctype
    tg.config.pop('templating.genshi.method', None)
    if genshi_method:
        deployment_config['templating.genshi.method'] = genshi_method
    tg.config.pop('templating.genshi.encoding', None)
    if genshi_encoding:
        deployment_config['templating.genshi.encoding'] = genshi_encoding

    deployment_config.update(extra or {})

    if extra_init is not None:
        extra_init(base_config)

    return app_from_config(base_config, deployment_config)
Beispiel #11
0
def test_jinja_custom_filters():
    # Simple test filter to get a md5 hash of a string
    def codify(value):
        try:
            from hashlib import md5
        except ImportError:
            from md5 import md5
        string_hash = md5(value.encode('ascii'))
        return string_hash.hexdigest()

    base_config = TestConfig(folder = 'rendering',
                             values = {'use_sqlalchemy': False,
                                       'use_legacy_renderer': False,
                                       # this is specific to mako
                                       # to make sure inheritance works
                                       'use_dotted_templatenames': False,
                                       'renderers':['jinja'],
                                       'jinja_filters': {'codify': codify},
                                       'use_toscawidgets': False,
                                       'use_toscawidgets2': False
                                       }
                             )
    app = app_from_config(base_config)

    try:
        resp = app.get('/jinja_filters')
    finally:
        # Remove filters so we don't mess with other test units
        tg.config.pop('jinja_filters')

    assert '8bb23e0b574ecb147536efacc864891b' in resp, resp
Beispiel #12
0
def test_jinja_extensions():
    base_config = TestConfig(
        folder='rendering',
        values={
            'use_sqlalchemy':
            False,
            'use_legacy_renderer':
            False,
            # this is specific to mako
            # to make sure inheritance works
            'use_dotted_templatenames':
            False,
            'renderers': ['jinja'],
            'jinja_extensions': [
                'jinja2.ext.do', 'jinja2.ext.i18n', 'jinja2.ext.with_',
                'jinja2.ext.autoescape'
            ],
            'use_toscawidgets':
            False,
            'use_toscawidgets2':
            False
        })
    app = app_from_config(base_config)
    resp = app.get('/jinja_extensions')
    assert "<b>Autoescape Off</b>" in resp, resp
    assert "&lt;b&gt;Test Autoescape On&lt;/b&gt;" in resp, resp
Beispiel #13
0
def setup_noDB():
    base_config = TestConfig(folder='rendering',
                             values={
                                 'use_sqlalchemy': False,
                                 'use_toscawidgets': False,
                                 'use_toscawidgets2': False
                             })
    return app_from_config(base_config)
    def test_hooks_syswide(self):
        base_config = TestConfig(folder='dispatch',
                                 values={
                                     'use_sqlalchemy': False,
                                     'use_toscawidgets': False,
                                     'use_toscawidgets2': False,
                                     'ignore_parameters':
                                     ["ignore", "ignore_me"]
                                 })

        def hook(*args, **kw):
            tg.tmpl_context.echo = 'WORKED'

        base_config.register_hook('before_call', hook)
        app = app_from_config(base_config, reset_milestones=False)

        ans = app.get('/echo')
        assert 'WORKED' in ans
Beispiel #15
0
def test_render_hooks():
    calls = []
    def render_call_hook(*args, **kw):
        calls.append(1)

    base_config = TestConfig(folder='rendering', values={
        'use_sqlalchemy': False,
        'use_legacy_renderer': False,
        # this is specific to mako  to make sure inheritance works
        'use_dotted_templatenames': False,
        'use_toscawidgets': False,
        'use_toscawidgets2': False
    })
    base_config.register_hook('before_render_call', render_call_hook)
    base_config.register_hook('after_render_call', render_call_hook)
    app = app_from_config(base_config)
    app.get('/')

    assert len(calls) == 2
    def test_hooks_syswide(self):
        base_config = TestConfig(
            folder="dispatch",
            values={
                "use_sqlalchemy": False,
                "use_toscawidgets": False,
                "use_toscawidgets2": False,
                "ignore_parameters": ["ignore", "ignore_me"],
            },
        )

        def hook(*args, **kw):
            tg.tmpl_context.echo = "WORKED"

        base_config.register_hook("before_call", hook)
        app = app_from_config(base_config)

        ans = app.get("/echo")
        assert "WORKED" in ans
    def setup(self):
        base_config = TestConfig(folder='dispatch',
                                 values={
                                     'use_sqlalchemy': False,
                                     'use_toscawidgets': False,
                                     'use_toscawidgets2': False,
                                     'ignore_parameters':
                                     ["ignore", "ignore_me"]
                                 })

        self.app = app_from_config(base_config)
Beispiel #18
0
 def setUp(self):
     base_config = TestConfig(folder='rendering', values={
         'use_sqlalchemy': False,
         'use_legacy_renderer': False,
         # this is specific to mako  to make sure inheritance works
         'use_dotted_templatenames': False,
         'use_toscawidgets': False,
         'use_toscawidgets2': False,
         'cache_dir': '.'
     })
     self.app = app_from_config(base_config)
Beispiel #19
0
def setup_noDB():
    base_config = TestConfig(folder = 'rendering',
                     values = {'use_sqlalchemy': False,
                               'pylons.helpers': Bunch(),
                               # we want to test the new renderer functions
                               'use_legacy_renderer': False,
                               # in this test we want dotted names support
                               'use_dotted_templatenames': True,
                               }
                             )
    return app_from_config(base_config)
Beispiel #20
0
def make_app():
    base_config = TestConfig(folder = 'rendering',
                             values = {'use_sqlalchemy': False,
                                       'use_legacy_renderer': False,
                                       # this is specific to mako
                                       # to make sure inheritance works
                                       'use_dotted_templatenames': False,
                                       'use_toscawidgets': False,
                                       'use_toscawidgets2': False
                                       }
                             )
    return app_from_config(base_config)
Beispiel #21
0
def setup_noDB(html_flash=False):
    config = {'use_sqlalchemy': False,
              'use_toscawidgets': False,
              'use_toscawidgets2': False,
              'ignore_parameters': ["ignore", "ignore_me"]}

    if html_flash:
        config['flash.allow_html'] = True

    base_config = TestConfig(folder='dispatch',
                             values=config)
    return app_from_config(base_config)
Beispiel #22
0
def make_app():
    base_config = TestConfig(
        folder='rendering',
        values={
            'use_sqlalchemy': False,
            'pylons.helpers': Bunch(),
            'use_legacy_renderer': False,
            # this is specific to mako
            # to make sure inheritance works
            'use_dotted_templatenames': False,
            'pylons.tmpl_context_attach_args': False
        })
    return app_from_config(base_config)
def setup_noDB(prefer_tw2=False):

    base_config = TestConfig(
        folder='rendering',
        values={
            'use_sqlalchemy': False,
            # we want to test the new renderer functions
            'use_legacy_renderer': False,
            # in this test we want dotted names support
            'use_dotted_templatenames': False,
            'templating.genshi.method': 'xhtml',
            'prefer_toscawidgets2': prefer_tw2
        })
    return app_from_config(base_config)
Beispiel #24
0
    def test_use_default_renderer(self):
        base_config = TestConfig(folder='dispatch',
                                 values={
                                     'use_sqlalchemy': False,
                                     'use_toscawidgets': False,
                                     'use_toscawidgets2': False,
                                     'ignore_parameters':
                                     ["ignore", "ignore_me"]
                                 })

        app = app_from_config(base_config)

        exposition = tg.expose('nonexisting')
        assert exposition.engine == tg.config['default_renderer']
        assert exposition.template == 'nonexisting'
    def test_expose_without_function_does_nothing(self):
        base_config = TestConfig(folder='dispatch',
                                 values={
                                     'use_sqlalchemy': False,
                                     'use_toscawidgets': False,
                                     'use_toscawidgets2': False,
                                     'ignore_parameters':
                                     ["ignore", "ignore_me"]
                                 })

        app = app_from_config(base_config)

        exposition = tg.expose('nonexisting')
        exposition._apply()

        assert exposition._func is None
        assert exposition.engine is None
Beispiel #26
0
def setup_noDB(extra_init=None):
    base_config = TestConfig(
        folder='rendering',
        values={
            'use_sqlalchemy': False,
            # we want to test the new renderer functions
            'use_legacy_renderer': False,
            # in this test we want dotted names support
            'use_dotted_templatenames': True,
            'use_toscawidgets': False,
            'use_toscawidgets2': False
        })

    if extra_init is not None:
        extra_init(base_config)

    return app_from_config(base_config)
Beispiel #27
0
    def test_unregisterd_renderers_detection(self):
        #If no renderers are available we should just issue a warning
        #and avoid crashing. Simply bypass rendering availability check.
        base_config = TestConfig(folder='dispatch',
                                 values={
                                     'use_sqlalchemy': False,
                                     'use_toscawidgets': False,
                                     'use_toscawidgets2': False,
                                     'ignore_parameters':
                                     ["ignore", "ignore_me"]
                                 })
        app = app_from_config(base_config)

        old_renderers = tg.config['renderers']
        tg.config['renderers'] = []

        @tg.expose('mako:nonexisting')
        def func(*args, **kw):
            pass

        tg.config['renderers'] = old_renderers
Beispiel #28
0
def test_template_override():
#    app = setup_noDB()
    base_config = TestConfig(folder = 'rendering',
                             values = {'use_sqlalchemy': False,
                                       'pylons.helpers': Bunch(),
                                       'use_legacy_renderer': False,
                                       # this is specific to mako
                                       # to make sure inheritance works
                                       'use_dotted_templatenames': True,
                                       'pylons.tmpl_context_attach_args': False,
                                       'renderers':['genshi']
                                       }
                             )
    app = app_from_config(base_config)
    r =app.get('/template_override')
    assert "Not overridden" in r, r
    r = app.get('/template_override', params=dict(override=True))
    assert "This is overridden." in r, r
    # now invoke the controller again without override,
    # it should yield the old result
    r = app.get('/template_override')
    assert "Not overridden" in r, r
Beispiel #29
0
def setup_noDB(genshi_doctype=None, genshi_method=None, genshi_encoding=None):
    base_config = TestConfig(folder='rendering', values={
        'use_sqlalchemy': False,
       'pylons.helpers': Bunch(),
       'use_legacy_renderer': False,
       # this is specific to mako  to make sure inheritance works
       'use_dotted_templatenames': False,
       'pylons.tmpl_context_attach_args': False
    })

    deployment_config = {}
    # remove previous option value to avoid using the old one
    tg.config.pop('templating.genshi.doctype', None)
    if genshi_doctype:
        deployment_config['templating.genshi.doctype'] = genshi_doctype
    tg.config.pop('templating.genshi.method', None)
    if genshi_method:
        deployment_config['templating.genshi.method'] = genshi_method
    tg.config.pop('templating.genshi.encoding', None)
    if genshi_encoding:
        deployment_config['templating.genshi.encoding'] = genshi_encoding

    return app_from_config(base_config, deployment_config)
Beispiel #30
0
def test_template_override_content_type():
    base_config = TestConfig(folder = 'rendering',
                             values = {'use_sqlalchemy': False,
                                       'use_legacy_renderer': False,
                                       # this is specific to mako
                                       # to make sure inheritance works
                                       'use_dotted_templatenames': True,
                                       'renderers':['mako', 'genshi'],
                                       'use_toscawidgets': False,
                                       'use_toscawidgets2': False
                                       }
                             )
    app = app_from_config(base_config)
    r =app.get('/template_override_content_type')
    assert r.content_type == 'text/javascript'
    assert "Not overridden" in r, r
    r = app.get('/template_override_content_type', params=dict(override=True))
    assert r.content_type == 'text/javascript'
    assert "This is overridden." in r, r
    # now invoke the controller again without override,
    # it should yield the old result
    r = app.get('/template_override_content_type')
    assert "Not overridden" in r, r
    def test_expose_idempotent(self):
        base_config = TestConfig(folder='dispatch',
                                 values={
                                     'use_sqlalchemy': False,
                                     'use_toscawidgets': False,
                                     'use_toscawidgets2': False,
                                     'ignore_parameters':
                                     ["ignore", "ignore_me"]
                                 })

        app = app_from_config(base_config)

        exposition = tg.expose('nonexisting')

        @exposition
        @exposition
        def func(*args, **kw):
            pass

        milestones.renderers_ready.reach()

        deco = Decoration.get_decoration(func)
        assert len(deco.engines) == 1, deco.engines
Beispiel #32
0
def test_render_hooks():
    calls = []

    def render_call_hook(*args, **kw):
        calls.append(1)

    base_config = TestConfig(
        folder='rendering',
        values={
            'use_sqlalchemy': False,
            'use_legacy_renderer': False,
            # this is specific to mako  to make sure inheritance works
            'use_dotted_templatenames': False,
            'use_toscawidgets': False,
            'use_toscawidgets2': False
        })
    base_config.register_hook('before_render_call', render_call_hook)
    base_config.register_hook('after_render_call', render_call_hook)
    app = app_from_config(base_config)
    app.get('/')

    assert len(calls) == 2