Skip to content

Instantly share code, notes, and snippets.

@didip
Created June 8, 2009 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save didip/125670 to your computer and use it in GitHub Desktop.
Save didip/125670 to your computer and use it in GitHub Desktop.
My Default tests/__init__.py
from unittest import TestCase
from paste.deploy import loadapp
from paste.script.appinstall import SetupCommand
from pylons import config, url
from routes.util import URLGenerator
from webtest import TestApp
import pylons.test
import sys, os.path
ROOT_PATH = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..'))
TEST_INI = os.path.join(ROOT_PATH, 'test.ini')
sys.path.append(ROOT_PATH)
from project.config.environment import load_sql_engine
__all__ = ['environ', 'url', 'TestController', 'TestModel']
# Invoke websetup with the current config file
SetupCommand('setup-app').run([config.get('__file__', TEST_INI)])
environ = {}
class TestController(TestCase):
def __init__(self, *args, **kwargs):
if pylons.test.pylonsapp:
wsgiapp = pylons.test.pylonsapp
else:
wsgiapp = loadapp('config:%s' % config['__file__'])
self.app = TestApp(wsgiapp)
url._push_object(URLGenerator(config['routes.map'], environ))
TestCase.__init__(self, *args, **kwargs)
class TestModel(TestCase):
def __init__(self, *args, **kwargs):
self.engine = load_sql_engine(config)
TestCase.__init__(self, *args, **kwargs)
def clear_db(self):
from project.model import meta
meta.metadata.drop_all(bind=self.engine, checkfirst=True)
meta.metadata.create_all(bind=self.engine)
meta.tokyo.clear()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment