On Sat, Feb 7, 2009 at 8:17 PM, Ludvig Ericson <ludvig.eric...@gmail.com> wrote: > > Hi, > I realize this topic is in a gray zone between django-users and > django-developers, but I thought it'd be more fitting to post it here. > > I needed to inject things into the session, and I'm not using regular > sessions. > I have my own session framework*, but the testing framework is rather > tightly > coupled with the built-in Django sessions. > > All I want to do with it - for now - is to have a simple dict as the > session of > the testing client. > > Normally, I'd just subclass django.test.TestCase, and change the part > I need to > change - simple programming! But this is more or less impossible with > TestCase, > because the part that sets up the client object is TestCase.__call__, > which also > contains other logics. > > So for me to be able to override the class used for the client object, > I would > have to *copy* the __call__ method from the actual .py file, paste and > rewrite. > IMHO that's a pretty strong indication that modularization isn't at > its best. > :-) > > I'm not sure how to modularize this either. A first step would be > moving the > line `self.client = Client()` from __call__ to _pre_setup. That way, > one could > subclass and upcall, then replace. That's virtually impossible > currently.
First off - it isn't impossible to do what you are describing with the existing setup. There is no reason you couldn't override _pre_setup() in your subclass and either re-instantiate self.client, or modify the self.client instance that has already been created. This isn't necessarily clean, but it would work. This area could certainly be cleaned up, though. Moving the instantiation of Client into _pre_setup() would be one approach. Another would be to parameterize the class that is instantiated when the client is created - i.e., rather than always instantiating django.test.client.Client, we provide a customization hook that lets subclasses provide their own Client class. Patches welcome. :-) Yours, Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---