On Fri, Jun 27, 2008 at 6:33 AM, Marin <[EMAIL PROTECTED]> wrote: > > I have this controller: > > class HeplController(BaseController): > > def index(self): > del session['user'] > session.save() > return 'OK' > > And I want to test if it works correctly with this test: > > class TestHeplController(TestController): > > def test_index(self): > #session['user'] = 'foo' ---> does not work > response = self.app.get(url_for(controller='hepl')) > assert 'user' not in response.session > > How can I put something in the session object before I call > self.app.get(...)?
You're trying to use the session from outside the context of a Web request. At that point in the code, in a sense, Pylons isn't even fired up. Here are two approaches that might work: * Use one action to put something into the session and then another to make use of the session. It's a work flow. * If I remember correctly, there's a way to shove stuff into the environ that will be passed to the request. Shove in a callback named "setup_session_for_tests" that gets called by the parent class of the controller. You can also mess around with the environ after the request. There's a key called "paste testing variables" or something like that. Happy Hacking! -jj -- It's a walled garden, but the flowers sure are lovely! http://jjinux.blogspot.com/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
