On Monday, 29 April 2013 13:03:47 UTC-7, Jonathan Vanasco wrote:
> I have a convenience class for my commandline scripts:
>
> from pyramid.paster import bootstrap
> class IntegratedApi():
> env = None
> bootstrapped = None
>
> def __init__(self):
> self.env = bootstrap('../../../web-pylons/app/production.ini')
>
> def finish(self):
> self.env['closer']()
>
> is there a better way to generate new 'requests' under the commandline
> environment ?
>
> each call to `bootstrap()` seems to generate an overhead of about 1.3s on
> my dev machine ( .9 on production ).
>
> i need to somehow make new 'requests' more on par with the normal overhead
> ( which is so small its virtually non-existant ).
>
My case is slightly different, but should be applicable for a command line
app too. When running in development mode I create some test data at
application startup time as a convenience. I wrap the app with WebTest, the
equivalent for you would be something like:
app = pyramid.paster.get_app('path/to/config.ini')
from webtest import TestApp
environ = {
'HTTP_ACCEPT': 'application/json',
'REMOTE_USER': 'TEST',
}
testapp = TestApp(app, environ)
(I have remote user authentication policy configured as part of
pramid_multiauth for this purpose.)
You can then make requests like:
item = {'foo': 'bar'}
testapp.post_json(collection_url, item, status=201)
Laurence
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.