[twill] Access to the WSGI environment with wsgi_intercept

Ken Kuhlman ken at redlagoon.net
Fri Jan 4 12:46:29 PST 2008

On Jan 3, 2008 11:08 PM, Titus Brown <titus at caltech.edu> wrote:

> On Thu, Jan 03, 2008 at 03:54:35PM -0600, Ken Kuhlman wrote:
> -> I've been trying to do a better job of testing my (turbogears) web apps
> -> lately, and am trying to decide if I should be using twill or
> paste.fixture.
> -> I like a lot of things about twill, but one of the key strengths of
> paste
> -> (IMHO) is that it's "in process" testing feature includes the ability
> to
> -> dump the wsgi environment (unlike wsgi_intercept, which otherwise is a
> very
> -> nice hack).   Access to the environ is very handy [1] when you're doing
> -> work & trying to seperate what the controller's doing from what the
> rendered
> -> result looks like.
> -> Anyway, code speaks louder than words, so I've included an example of
> what
> -> I'd like to see, and a patch to twill to make it work.   I'd be
> interested
> -> to know if you all think I'm on the right track or if I'm all wet.  I'm
> a
> -> twill & wsgi n00b, so my apologies if I've missed anything obvious.
> Hey Ken!  Good idea, and one that I think can be generalized nicely...
> which is why I want to think about it a bit more before committing to
> any one direction.  We should include Kumar, too, because he's taken
> over wsgi_intercept - Kumar, are you on this list?
> First, I don't want to include a default command that deals with WSGI,
> because most people probably won't know what it is or use it.  We could
> still create an extension module, but there are some other questions...

Cool.. I figured this would be a first attempt.   Extension module it is.

> For example, you may want to have multiple WSGI apps in play, in which
> case your global environ hack would cause problems.  (This is why
> _wsgi_intercept, which contains the apps, is the only global one.)
> And why not use middleware instead of a solid hook?  Something like
> this:
> --
> # install 'simple_app' with an environment printer under 'foo_name'
> app_fn = lambda: twill.wsgi.env_printer('foo_name', simple_app)
> twill.add_wsgi_intercept('localhost', 8001, lambda: app_fn)
> --

I was thinking that the global hack would only impact multiple
wsgi_intercept calls, which would be less of a problem.  I believe you when
you say it's more than that, though, and I agree that doing it as middleware
is less hackish.

I'll need to play around with it a bit though, because right now the double
lambdas around app_fn are over my head.   Should the middleware be added to
wsgi_intercept so that other potential users can use it?

> Then we could have twill_wsgi functions, e.g.
> --
> val = twill_wsgi.print_environ('foo_name', 'env_variable_to_print')
> --
> or twill script,
> >> extend_with twill_wsgi
> >> print_environ foo_name env_variable_to_print
> thoughts?

Yeah, that looks solid.   I'll play around with it this weekend and see what
I can come up with.


Thanks for the reply!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.idyll.org/pipermail/twill/attachments/20080104/12a2ce1d/attachment.htm 

More information about the twill mailing list