Guest User

Untitled

a guest
Apr 29th, 2012
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. '''Hooks for lettuce to run a test pylons app'''
  2.  
  3. from lettuce import *
  4. from paste.fixture import TestApp
  5.  
  6. import pylons.test
  7.  
  8. from paste.deploy.loadwsgi import loadapp
  9. from paste.script.appinstall import SetupCommand
  10.  
  11. from routes.util import URLGenerator
  12.  
  13. from os import getcwd
  14.  
  15. @before.each_scenario
  16. def start_test_server(scenario):
  17. '''Start a test instance of the app
  18.  
  19. Adds the following to world:
  20. - app: The WSGI application defined in test.ini
  21. - url: A routes url generator for the app
  22. '''
  23.  
  24. if not hasattr(world, 'app'):
  25. if not pylons.test.pylonsapp:
  26. # setup-app looks here for an app before loading it, we need to
  27. # use the same app otherwise we won't be using the same in
  28. # memory database
  29. pylons.test.pylonsapp = loadapp('config:test.ini', relative_to=getcwd(), global_conf={})
  30. SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']])
  31. config = pylons.test.pylonsapp.config
  32. world.app = TestApp(pylons.test.pylonsapp)
  33. world.url = URLGenerator(config['routes.map'], {})
  34.  
  35. @after.each_scenario
  36. def stop_test_server(scenario):
  37. if hasattr(world, 'app'):
  38. if pylons.test.pylonsapp == world.app:
  39. pylons.test.pylonsapp = None
  40. del world.app
  41. del world.url
  42. if hasattr(world, 'response'):
  43. del world.response
Advertisement
Add Comment
Please, Sign In to add comment