Thanks a lot, Alberto! That works just fine.
It's not a good practice indeed, but that's the best way, I could figure to do with user-specific stuff. For instance if we're dealing with mail, for get_incoming, get_sent, get_drafts etc I'll have to pass session['user_id'] from the controller to the model method, when It's obvious that this is the only value it'll ever be getting. Checking if the current user can delete a certain letter (if he's the author of it) should obviously be done inside the model, but where will I get the user_id to check? Passing it to the delete function looks just wrong to me. Giving the model access to the session looks far from being good MVC practice, but I couldn't figure a better way. If anyone have any suggestions - i'd love to hear any advice :) On Apr 30, 1:15 pm, Alberto Valverde <[EMAIL PROTECTED]> wrote: > Pavel Skvazh wrote: > > I've been searching throught the docs to figure it out but there's no > > clue. I've got a set up like Using SQLAlchemy with Pylons suggests > > and my model relies on session, where current user_id is stored. > > > Is there any way to access Pylons session in my model tests? > > Relying on the HTTP session (if you're not referring to this one please > stop reading now :) in the model is very bad coupling IMHO. As a > workaround you could try to mock a session with something like: > > class MyMockSession(dict): > def save(*args, **kw): > pass > etc, ... > > from pylons import session > session._push_object(MyMockSession(user_id="fooo")) > > You might want to place that in the setUp method and place the > followiing in the tearDown this: > > session._pop_object() > > Alberto --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---