Changeset 5740

Show
Ignore:
Timestamp:
11/20/08 19:42:28 (2 months ago)
Author:
mramm
Message:

Added rendering tests, and some code to isolate the full stack config from the rest of the tests.

Added flash and flash_status to the tg namespace in all templates

Added the url function to all templates so we can easily use it to make links that still work when you mount an app outside the root of a site.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tg/render.py

    r5634 r5740  
    109109        ipeek=ipeek,  
    110110        cycle=cycle,  
     111        flash=tg.get_flash(), 
     112        flash_status=tg.get_status(), 
    111113        quote_plus=quote_plus,  
    112114        checker=checker, 
     
    119121        request = tg.request 
    120122        ) 
     123     
     124    helpers = config.get('pylons.h') or config.get('pylons.helpers') 
    121125         
    122     helpers = config.get('pylons.h') or config.get('pylons.helpers') 
    123      
    124126    root_vars = Bunch( 
    125127        c=tmpl_context, 
     
    128130        request = request, 
    129131        h = helpers, 
     132        url = tg.url, 
    130133        helpers = helpers, 
    131134        tg=tg_vars 
    132135        ) 
     136    #Allow users to provide a callable that defines extra vars to be  
     137    #added to the template namespace 
     138    variable_provider = config.get('variable_provider', None) 
     139    if variable_provider: 
     140        root_vars.update(variable_provider()) 
    133141    return root_vars 
    134      
    135 def genshi_template_loader(): 
    136     pass 
     142 
    137143 
    138144def render(template_vars, template_engine=None, template_name=None, **kwargs): 
  • trunk/tg/tests/base.py

    r5671 r5740  
    1717from tg import tmpl_context 
    1818from tg.util import Bunch 
    19 from tg.configuration import AppConfig 
    2019from pylons.util import ContextObj, PylonsContext 
    2120from pylons.controllers.util import Request, Response 
     
    114113        return self.app.post(url, extra_environ=self.environ, params=kargs) 
    115114 
    116 class TestConfig(AppConfig): 
    117  
    118     def __init__(self, folder, values=None): 
    119         AppConfig.__init__(self) 
    120         #First we setup some base values that we know will work 
    121         self.renderers = ['genshi']  
    122         self.render_functions = tg.util.Bunch() 
    123         self.package = tg.test_stack 
    124         self.default_renderer = 'genshi' 
    125         self.globals = self 
    126         self.helpers = {} 
    127         self.auth_backend = None 
    128         self.auto_reload_templates = False 
    129         self.use_legacy_renderer = True 
    130         self.serve_static = False 
    131          
    132  
    133         #Then we overide those values with what was passed in 
    134         for key, value in values.items(): 
    135             setattr(self, key, value) 
    136  
    137          
    138         root = "." 
    139         test_base_path = os.path.join(root,'tg', 'test_stack',) 
    140         test_config_path = os.path.join(test_base_path, folder) 
    141         print test_config_path 
    142         self.paths=tg.util.Bunch( 
    143                     root=test_base_path, 
    144                     controllers=os.path.join(test_config_path, 'controllers'), 
    145                     static_files=os.path.join(test_config_path, 'public'), 
    146                     templates=[os.path.join(test_config_path, 'templates')] 
    147                     ) 
    148  
    149     def setup_helpers_and_globals(self): 
    150         tg.config['pylons.app_globals'] = self.globals 
    151         tg.config['pylons.h'] = self.helpers 
  • trunk/tg/test_stack/__init__.py

    r5671 r5740  
     1import os 
     2import tg 
     3from tg.configuration import AppConfig 
    14 
     5class TestConfig(AppConfig): 
    26 
     7    def __init__(self, folder, values=None): 
     8        AppConfig.__init__(self) 
     9        #First we setup some base values that we know will work 
     10        self.renderers = ['genshi']  
     11        self.render_functions = tg.util.Bunch() 
     12        self.package = tg.test_stack 
     13        self.default_renderer = 'genshi' 
     14        self.globals = self 
     15        self.helpers = {} 
     16        self.auth_backend = None 
     17        self.auto_reload_templates = False 
     18        self.use_legacy_renderer = True 
     19        self.serve_static = False 
     20         
    321 
     22        #Then we overide those values with what was passed in 
     23        for key, value in values.items(): 
     24            setattr(self, key, value) 
     25 
     26         
     27        root = "." 
     28        test_base_path = os.path.join(root,'tg', 'test_stack',) 
     29        test_config_path = os.path.join(test_base_path, folder) 
     30        print test_config_path 
     31        self.paths=tg.util.Bunch( 
     32                    root=test_base_path, 
     33                    controllers=os.path.join(test_config_path, 'controllers'), 
     34                    static_files=os.path.join(test_config_path, 'public'), 
     35                    templates=[os.path.join(test_config_path, 'templates')] 
     36                    ) 
     37 
     38    def setup_helpers_and_globals(self): 
     39        tg.config['pylons.app_globals'] = self.globals 
     40        tg.config['pylons.h'] = self.helpers 
     41 
     42def teardown(): 
     43    global_config = {'debug': 'true',  
     44                     'error_email_from': 'paste@localhost',  
     45                     'smtp_server': 'localhost'} 
     46 
     47    base_config = TestConfig(folder = 'rendering',  
     48                             values = {'use_sqlalchemy': False, 
     49                                       'pylons.helpers': tg.util.Bunch(), 
     50                                       'use_legacy_renderer': True, 
     51                                       } 
     52                             ) 
     53    env_loader = base_config.make_load_environment() 
     54    app_maker = base_config.setup_tg_wsgi_app(env_loader) 
     55    app = app_maker(global_config, full_stack=True) 
     56 
  • trunk/tg/test_stack/test_config.py

    r5671 r5740  
    11import os 
    2 from tg.tests.base import TestConfig 
     2from tg.test_stack import TestConfig 
    33from paste.fixture import TestApp 
    44