Browse files

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

extra : convert_revision : svn%3A77541ad4-5f01-0410-9ede-a1b63cd9a898/trunk%405526
  • Loading branch information...
mramm committed Oct 8, 2008
1 parent ab871c3 commit 84d307d220c4b4a0bb335fff5c56247cbe16a489
Showing with 13 additions and 85 deletions.
  1. +1 −1 tg/
  2. +5 −0 tg/
  3. +0 −73 tg/templates/
  4. +3 −8 tg/tests/
  5. +0 −2 tg/
  6. +4 −1 tg/
@@ -58,7 +58,7 @@ def __getattr__(self, key):
return self.config_proxy.current_conf()[key]
except KeyError:
- get_partial_dict(key, self.config_proxy.current_conf())
+ return get_partial_dict(key, self.config_proxy.current_conf())
def __setattr__(self, key, value):
self.config_proxy.current_conf()[key] = value
@@ -330,6 +330,11 @@ def _w(*args, **kwargs):
def postpone_commits(func, *args, **kwargs):
+ """Turns sqlalchemy commits into flushes in the decorated method
+ This has the end-result of postponing the commit to the normal TG2
+ transaction boundry. """
#TODO: Test and document this.
s = config.get('DBSession', None)
assert hasattr(s, 'commit')
@@ -1,73 +0,0 @@
-Place to hold TurboGears built-in templates
-With 'paster quickstart' or 'paster create' command you can create a new
-TurboGears project which you can use as a basis for your own project.
-Let's take the command 'paster quickstart helloworld' for example.
-The generated directory structure is as follows::
- - helloworld/
- - helloworld/
- - development.ini
- - setup.cfg
- -
- - test.ini
-The file is used to create a re-distributable Python
-package of your project called an egg. Eggs can be thought of as
-similar to .jar files in Java.
-The setup.cfg file contains extra information about your project.
-The sub 'helloworld' directory within the root 'helloworld' directory
-is where all your application specific code and files are placed.
-The sub directory looks like this::
- - helloworld/
- - config/
- - controllers/
- - lib/
- - model/
- - public/
- - templates/
- - tests/
- -
- -
-The config directory contains the configuration options for your web application.
-The controllers directory is where your application controllers are written.
-Controllers are the core of your application where the decision is made on what
-data to load, and how to view it.
-The lib directory is where you can put code that is used between different
-controllers, third party code, or any other code that doesn't fit in well elsewhere.
-The models directory is for your model objects, if you're using an ORM this is
-where the classes for them should go.
-Objects defined in models/ will be loaded and present as model.
-YourObject inside your controllers. The database configuration string can be set
-in your development.ini file.
-The public directory is where you put all your HTML, images, Javascript, CSS and
-other static files. It is similar to the htdocs directory in Apache.
-The templates directory is where templates are stored. Templates contain a mixture of
-plain text and Python code and are used for creating HTML and other documents in a way
-that is easy for designers to tweak without them needing to see all the code that
-goes on behind the scenes.
-TurboGears 2 uses Genshi templates by default but also supports Mako, Cheetah, Kid and
-others through a system called Buffet. See how to change template languages.
-The tests directory is where you can put controller and other tests. The controller
-testing functionality uses Nose and paste.fixture.
-The file is present so that the helloworld directory can be used as a Python
-module within the egg.
-The should contain any code that should be executed when an end user of your
-application runs the paster setup-app command described in Application Setup.
-If you're looking for where to put that should be run before your application is,
-this is the place.
@@ -14,21 +14,15 @@
from paste import httpexceptions
from tg import tmpl_context
+from tg.util import Bunch
+from tg.configuration import AppConfig
from pylons.util import ContextObj, PylonsContext
from pylons.controllers.util import Request, Response
from tg.controllers import TGController
from pylons.testutil import ControllerWrap, SetupCacheGlobal
-#import pylons.tests
from beaker.middleware import CacheMiddleware
-# TODO:
-# We need infrastructure to test the whole WSGI stack for internal tests.
-# eg: currently we have no way to test integration except from
-# quickstarted app's tests.
-# We also need this to test the configuration system, since that is part
-# of the tg egg.
data_dir = os.path.dirname(os.path.abspath(__file__))
session_dir = os.path.join(data_dir, 'session')
@@ -117,3 +111,4 @@ def post_response(self, **kargs):
url = kargs.pop('_url', '/')
return, extra_environ=self.environ, params=kargs)
@@ -81,8 +81,6 @@ def __getattr__(self, name):
return self[name]
except KeyError:
return get_partial_dict(name, self)
- #if both getitem, and partial-dict matches fail we're done
- raise AttributeError(name)
__setattr__ = dict.__setitem__
@@ -29,9 +29,12 @@ def find_controller(self, controller):
controller_path.replace('/', '.') +
'.' + controller.replace('/', '.'))
+ if self.config.get('in_testing'):
+ full_module_name = 'tg.tests.test_stack.controllers.root'
# Hide the traceback here if the import fails (bad syntax and such)
__traceback_hide__ = 'before_and_this'
module_name = controller.split('/')[-1]
class_name = class_name_from_module_name(module_name) + 'Controller'

0 comments on commit 84d307d

Please sign in to comment.