Changeset 5526

Show
Ignore:
Timestamp:
10/08/08 15:40:06 (3 months ago)
Author:
mramm
Message:

Fix config bug, clean up config, and add some basic full-stack tests.

Files:

Legend:

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

    r5523 r5526  
    5959                return self.config_proxy.current_conf()[key] 
    6060            except KeyError: 
    61                 get_partial_dict(key, self.config_proxy.current_conf()) 
     61                return get_partial_dict(key, self.config_proxy.current_conf()) 
    6262 
    6363    def __setattr__(self, key, value): 
  • trunk/tg/decorators.py

    r5415 r5526  
    331331@decorator 
    332332def postpone_commits(func, *args, **kwargs): 
     333    """Turns sqlalchemy commits into flushes in the decorated method 
     334     
     335    This has the end-result of postponing the commit to the normal TG2  
     336    transaction boundry. """ 
     337     
    333338    #TODO: Test and document this. 
    334339    s = config.get('DBSession', None) 
  • trunk/tg/templates/__init__.py

    r5099 r5526  
    1 """ 
    2 Place to hold TurboGears built-in templates 
    3  
    4 With 'paster quickstart' or 'paster create' command you can create a new 
    5 TurboGears project which you can use as a basis for your own project. 
    6 Let's take the command 'paster quickstart helloworld' for example. 
    7 The generated directory structure is as follows:: 
    8  
    9     - helloworld/ 
    10         - helloworld/ 
    11         - development.ini 
    12         - setup.cfg 
    13         - setup.py 
    14         - test.ini 
    15  
    16  
    17 The setup.py file is used to create a re-distributable Python 
    18 package of your project called an egg. Eggs can be thought of as 
    19 similar to .jar files in Java. 
    20 The setup.cfg file contains extra information about your project. 
    21  
    22 The sub 'helloworld' directory within the root 'helloworld' directory 
    23 is where all your application specific code and files are placed. 
    24 The sub directory looks like this:: 
    25  
    26     - helloworld/ 
    27         - config/ 
    28         - controllers/ 
    29         - lib/ 
    30         - model/ 
    31         - public/ 
    32         - templates/ 
    33         - tests/ 
    34         - __init__.py 
    35         - websetup.py 
    36  
    37 The config directory contains the configuration options for your web application. 
    38  
    39 The controllers directory is where your application controllers are written. 
    40 Controllers are the core of your application where the decision is made on what 
    41 data to load, and how to view it. 
    42  
    43 The lib directory is where you can put code that is used between different 
    44 controllers, third party code, or any other code that doesn't fit in well elsewhere. 
    45  
    46 The models directory is for your model objects, if you're using an ORM this is 
    47 where the classes for them should go. 
    48 Objects defined in models/__init__.py will be loaded and present as model. 
    49 YourObject inside your controllers. The database configuration string can be set 
    50 in your development.ini file. 
    51  
    52 The public directory is where you put all your HTML, images, Javascript, CSS and 
    53 other static files. It is similar to the htdocs directory in Apache. 
    54  
    55 The templates directory is where templates are stored. Templates contain a mixture of 
    56 plain text and Python code and are used for creating HTML and other documents in a way 
    57 that is easy for designers to tweak without them needing to see all the code that 
    58 goes on behind the scenes. 
    59 TurboGears 2 uses Genshi templates by default but also supports Mako, Cheetah, Kid and 
    60 others through a system called Buffet. See how to change template languages. 
    61  
    62 The tests directory is where you can put controller and other tests. The controller 
    63 testing functionality uses Nose and paste.fixture. 
    64  
    65 The __init__.py file is present so that the helloworld directory can be used as a Python 
    66 module within the egg. 
    67  
    68 The websetup.py should contain any code that should be executed when an end user of your 
    69 application runs the paster setup-app command described in Application Setup. 
    70 If you're looking for where to put that should be run before your application is, 
    71 this is the place. 
    72  
    73 """ 
  • trunk/tg/tests/base.py

    r5126 r5526  
    1515 
    1616from tg import tmpl_context 
     17from tg.util import Bunch 
     18from tg.configuration import AppConfig 
    1719from pylons.util import ContextObj, PylonsContext 
    1820from pylons.controllers.util import Request, Response 
    1921from tg.controllers import TGController 
    2022from pylons.testutil import ControllerWrap, SetupCacheGlobal 
    21 #import pylons.tests 
    2223 
    2324from beaker.middleware import CacheMiddleware 
    24  
    25 # TODO: 
    26 #     We need infrastructure to test the whole WSGI stack for internal tests. 
    27 #     eg: currently we have no way to test repoze.tm integration except from 
    28 #     quickstarted app's tests. 
    29 #     We also need this to test the configuration system, since that is part  
    30 #     of the tg egg.  
    3125 
    3226 
     
    118112        self.environ['pylons.routes_dict'].update(kargs) 
    119113        return self.app.post(url, extra_environ=self.environ, params=kargs) 
     114     
  • trunk/tg/util.py

    r5368 r5526  
    8282        except KeyError: 
    8383            return get_partial_dict(name, self) 
    84             #if both getitem, and partial-dict matches fail we're done 
    85             raise AttributeError(name) 
    8684 
    8785    __setattr__ = dict.__setitem__ 
  • trunk/tg/wsgiapp.py

    r5151 r5526  
    3030                            '.' + controller.replace('/', '.')) 
    3131 
     32        if self.config.get('in_testing'): 
     33            full_module_name = 'tg.tests.test_stack.controllers.root' 
     34             
    3235        # Hide the traceback here if the import fails (bad syntax and such) 
    3336        __traceback_hide__ = 'before_and_this' 
    34  
     37         
    3538        __import__(full_module_name) 
    3639        module_name = controller.split('/')[-1]