Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''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
Advertisement
Add Comment
Please, Sign In to add comment