On Thu, Jun 17, 2010 at 3:58 PM, codysoyland <codysoyl...@gmail.com> wrote:
> I've written about using __new__ to generate HttpResponse objects in
> the past (see 
> http://codysoyland.com/2010/feb/3/thread-safe-object-oriented-views-django/
> and the relevant discussion thread), and this approach solves the
> thread-safety and boilerplate-reduction concerns. However, when
> implementing this, the one problem I've been fighting is testing. In
> order to test methods on a view built this way is to instantiate it
> using object.__new__ and explicitly calling __init__ before you can
> start to test view methods, and this may not be clear to somebody who
> is writing their first class-based view tests.
>
> Increasingly, I've been warming up to the idea of django treating
> class-based views a little bit more special: If the view is a subclass
> of BaseView, call it's to_response method instead of treating it as a
> callable.

You have a strong point here. We could at least provide a
new_instance(request, *args, **kwargs) classmethod for unit tests
which automates the __new__ and __init__ calls. Anyway, I'm not sure
which is worth more:

* relatively easy for unit tests (new_instance())
* enforced thread-safety
* no special code in Django's URL routing

vs

* no-brainer for unit tests
* no enforced thread-safety (you can mistakenly create a global view instance)
* special code in Django's URL routing

Bye,
Waldemar Kornewald

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@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.

Reply via email to