Best way to tell if we're in a test

2011-04-29 Thread Jody McIntyre
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.



Re: Best way to tell if we're in a test

2011-04-29 Thread Jody McIntyre
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  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 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.



Re: what is the recommended way to display currency?

2011-06-06 Thread Jody McIntyre
Check out BabelDjango: http://babel.edgewall.org/wiki/BabelDjango

We've been using it to display currencies and it works pretty well for our
needs (which includes two currency formats, Canadian English ($1,123.45) and
Canadian French (1 123,45$).)

Cheers,
Jody

On Sun, Jun 5, 2011 at 4:39 PM, snfctech  wrote:

> I thought this should be obvious but am having a hard time finding it
> in the docs.  There are a couple snippets that suggest using a custom
> currency filter:
>
> http://www.djangosnippets.org/snippets/552/
> http://djangosnippets.org/snippets/1825/
>
> But both use locale.setlocale, which is apparently not thread safe.
>
> So am I stuck with decimal formatting and hard-coding a currency
> symbol somewhere?
>
> Thanks.
>
> --
> 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.