This is fine as a general principle, but here we're dealing with middleware
that affects every other application.  It's not a good idea to require other
applications to change all their tests to mock out functionality in a module
they've just added, plus that would be a lot of work.  You'd have to use it
every time you run self.client.login() or post to the login URL in a test
case.  That's probably why django-digest and django-bcrypt disable
themselves under test (by default) and why I'd like to do it for security
questions.
Cheers,
Jody

On Fri, Apr 29, 2011 at 2:03 PM, Chris Czub <chris.c...@gmail.com> wrote:

> I think you might be taking the wrong approach. Rather than having your
> application code checking whether or not it's in a test, have your testing
> code disable/mock certain behaviors that you don't want exercised(like have
> it always return that the user answered the security question correctly or
> something).
>
> Python's dynamic nature makes it easy to monkey patch things like this.
> Look at the Mock class: http://python-mock.sourceforge.net/
>
>
> On Fri, Apr 29, 2011 at 12:53 PM, Jody McIntyre <jo...@trustcentric.com>wrote:
>
>> What's the best way to tell (from regular code) if we're in a test?  I
>> have added extra authentication steps (security questions) that would be
>> difficult to deal with in tests where you just want to run
>> self.client.login() or post to the login URL.  I've noticed that several
>> third party modules, such as django-digest and django-bcrypt, also disable
>> parts of their functionality during testing like this:
>>
>> from django.core import mail
>>
>> if hasattr(mail, 'outbox'):
>>     # we are under a test
>> else:
>>     # not under a test
>>
>> This works, but it's an undocumented side effect so I'm worried it might
>> change in a future version.  What's the correct way to tell if we're in a
>> test?
>>
>> Thanks,
>> Jody
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to