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
= engine_from_config(config
, 'sqlalchemy.')
45 model
.init_model(engine
)
46 metadata
= elixir
.metadata
47 Session
= elixir
.session
= meta
.Session
49 class Individual(Entity
):
50 """Table 'Individual'.
52 >>> me = Individual('Groucho')
54 # 'name' field is converted to lowercase
58 name
= Field(String(20), unique
=True)
59 favorite_color
= Field(String(20))
61 def __init__(self
, name
, favorite_color
=None):
62 self
.name
= str(name
).lower()
63 self
.favorite_color
= favorite_color
73 class TestModel(TestCase
):
81 class TestController(TestCase
):
83 def __init__(self
, *args
, **kwargs
):
84 if pylons
.test
.pylonsapp
:
85 wsgiapp
= pylons
.test
.pylonsapp
87 wsgiapp
= loadapp('config:%s' % config
['__file__'])
88 self
.app
= TestApp(wsgiapp
)
89 url
._push_object(URLGenerator(config
['routes.map'], environ
))
90 TestCase
.__init__(self
, *args
, **kwargs
)