-
-
Save dexterous/1039856 to your computer and use it in GitHub Desktop.
Hooks for lettuce to run a test pylons app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''Hooks for lettuce to run a test pylons app''' | |
from lettuce import * | |
from paste.fixture import TestApp | |
import pylons.test | |
from paste.deploy.loadwsgi import loadapp | |
from paste.script.appinstall import SetupCommand | |
from routes.util import URLGenerator | |
from os import getcwd | |
@before.each_scenario | |
def start_test_server(scenario): | |
'''Start a test instance of the app | |
Adds the following to world: | |
- app: The WSGI application defined in test.ini | |
- url: A routes url generator for the app | |
''' | |
if not hasattr(world, 'app'): | |
if not pylons.test.pylonsapp: | |
# setup-app looks here for an app before loading it, we need to | |
# use the same app otherwise we won't be using the same in | |
# memory database | |
pylons.test.pylonsapp = loadapp('config:test.ini', relative_to=getcwd(), global_conf={}) | |
SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']]) | |
config = pylons.test.pylonsapp.config | |
world.app = TestApp(pylons.test.pylonsapp) | |
world.url = URLGenerator(config['routes.map'], {}) | |
@after.each_scenario | |
def stop_test_server(scenario): | |
if hasattr(world, 'app'): | |
if pylons.test.pylonsapp == world.app: | |
pylons.test.pylonsapp = None | |
del world.app | |
del world.url | |
if hasattr(world, 'response'): | |
del world.response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment