On Mar 26, 2010, at 9:03 AM, andres wrote:
> This works fine within the context of a WSGI app instance but outside
> the context of an app instance (e.g. testing environment), the config
> object is a bare-bones pylons config rather than the runtime
> configuration I expect. For example, if I create a simple library
> function to test for the presence of a runtime config key:
>
> # myapp/lib/util.py
> from pylons import config
>
> def has_config_key(key):
> return key in config
>
> then I see the following behavior when I run this test:
>
> # myapp/tests/functional/test_runtimeconfig.py
> from myapp.tests import TestController
> from myapp.lib.util import has_config_key
>
> class ConfigTest(TestController):
> def test_app(self):
> response =
> self.app.get(url(controller='proxy',action='util_has_config_key',key='sqlalchemy.ur'))
> self.assertEqual('True' in response.body, True)
Your key here is 'sqlalchemy.ur', was that supposed to be 'sqlalchemy.uri'?
When I make a function like this, and test for the value, it works fine on
1.0RC1.
> def test_func(self):
> haskey = has_config_key('sqlalchemy.url')
> self.assertEqual(haskey, False)
This isn't going to work because the config object is not setup outside the
bounds of a request, as none of the globals are. If you would like to look at
the config object in a unit test, outside the bounds of a request, you can get
to it as the config attribute off the app object like so (when running unit
tests, this will exist):
import pylons.test
assert 'something' in pylons.test.pylonsapp.config
Otherwise you'll want to use loadapp like Mike Orr referred to.
Cheers,
Ben
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.