1 """Pylons application test package
3 This package assumes the Pylons environment is already loaded, such as
4 when this script is imported from the `nosetests --with-pylons=test.ini`
7 This module initializes the application via ``websetup`` (`paster
8 setup-app`) and provides the base testing objects.
10 from unittest
import TestCase
12 from paste
.deploy
import loadapp
13 from paste
.script
.appinstall
import SetupCommand
14 from pylons
import config
, url
15 from routes
.util
import URLGenerator
16 from webtest
import TestApp
20 from floof
.model
import *
21 from floof
.model
import meta
22 from floof
import model
as model
23 from sqlalchemy
import engine_from_config
25 __all__
= ['environ', 'url', 'TestController', 'TestModel']
28 # Invoke websetup with the current config file
29 # SetupCommand('setup-app').run([config['__file__']])
31 # additional imports ...
33 from paste
.deploy
import appconfig
34 from floof
.config
.environment
import load_environment
36 here_dir
= os
.path
.dirname(__file__
)
37 conf_dir
= os
.path
.dirname(os
.path
.dirname(here_dir
))
39 test_file
= os
.path
.join(conf_dir
, 'test.ini')
40 conf
= appconfig('config:' + test_file
)
41 load_environment(conf
.global_conf
, conf
.local_conf
)
44 engine
= elixir
.metadata
.bind
48 """Setup for the entire test suite."""
49 setup_all(create_tables
=True)
53 """Teardown for the entire test suite."""
58 class TestModel(TestCase
):
66 class TestController(TestCase
):
69 """Setup for a controller test class.
74 """Teardown for a controller test class.
78 def __init__(self
, *args
, **kwargs
):
79 if pylons
.test
.pylonsapp
:
80 wsgiapp
= pylons
.test
.pylonsapp
82 wsgiapp
= loadapp('config:%s' % config
['__file__'])
83 self
.app
= TestApp(wsgiapp
)
84 url
._push_object(URLGenerator(config
['routes.map'], environ
))
85 TestCase
.__init__(self
, *args
, **kwargs
)