12 messages in com.googlegroups.pylons-discussRe: Testing with the session object
FromSent OnAttachments
Marin27 Jun 2008 06:33 
Shannon -jj Behrens28 Jun 2008 04:17 
Marin28 Jun 2008 05:06 
Jonathan Vanasco28 Jun 2008 07:19 
Mike Orr28 Jun 2008 10:53 
Wichert Akkerman28 Jun 2008 11:00 
Marin29 Jun 2008 03:09 
Marin29 Jun 2008 03:20 
Wichert Akkerman29 Jun 2008 08:16 
Marin30 Jun 2008 04:34 
Marin30 Jun 2008 05:23 
Jonathan Vanasco07 Jul 2008 12:25 
Subject:Re: Testing with the session object
From:Mike Orr (slug@gmail.com)
Date:06/28/2008 10:53:10 AM
List:com.googlegroups.pylons-discuss

On Sat, Jun 28, 2008 at 7:19 AM, Jonathan Vanasco <jona@findmeon.com> wrote:

On Jun 28, 7:18 am, "Shannon -jj Behrens" <jji@gmail.com> wrote:

* Use one action to put something into the session and then another to make use of the session. It's a work flow.

I've always thought that Pylons should have something that does that.

Well, JJ is right in a way. The session is supposed to hold state between web requests. So it makes sense that you'd set it up via web requests. Just like an application that requires login; you have to do the login request at the beginning of each test.

But I can also see the point of giving Pylons some premade session data, like a test with premade database data. In Mechanize you can precreate a CookieJar and seed it with cookies, and pass that to your fake browser object. You can also save the cookie jar to a file and reuse it later.

You can probably do something similar with Pylons. Give it a premade Beaker instance stuffed with a session, and seed the test "browser" with the same session ID. It may need a couple API changes somewhere to make it more convenient. For my screen scraper experiments I have a custom subclass of Mechanize that makes it easier to build a stuffed cookie jar. Perhaps the Beaker middleware could be taught to look for a premade Beaker instance somewhere before creating one. I'm just not sure where that "somewhere" would be.

If self.app.get() is the same as paste.fixture.TestApp.get(), there's an 'extra_environ' arg to pass variables to the (CGI?|WSGI?) environment. If you stuffed something there (a Beaker instance?) and the Beaker middleware found it in the environment, perhaps it could just use it.