Re: Unit Testing: temporarily altering django settings

2011-02-21 Thread Phlip
On Feb 21, 12:47 pm, Cody Django  wrote:

> Thanks -- I didn't know about mock objects, and this is good to know.
> But this doesn't feel like this is the solution I'm looking for.  It's
> a large project, and your proposal would require extensive patching.

Does your project access the CAPTCHA settings in many different
places??

Either way, I think you still don't grok mocks.

But try Mikhail's suggestion first - just reach into the settings and
change them, before the call to client.get().

-- 
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: Unit Testing: temporarily altering django settings

2011-02-21 Thread Mikhail Korobov
Why doesn't setattr work? Just make sure you're setting the proper
option because apps often cache options at e.g. their 'config.py' file
in order to provide default values:

# captha_app/config.py
from django.conf import settings
CAPTCHA = getattr(settings, 'CAPTCHA', True)

So you'll have to change captcha_app.config.CAPTCHA, not the
settings.CAPTCHA in this case.

On 22 фев, 01:47, Cody Django  wrote:
> Thanks -- I didn't know about mock objects, and this is good to know.
> But this doesn't feel like this is the solution I'm looking for.  It's
> a large project, and your proposal would require extensive patching.
>
> Is the solution to create a new testrunner that sets a different
> environment (with different settings) for each app?  Is there another
> way to fool a testcase into thinking that an app has not been
> installed?
>
> Thanks again,
>
> Cody
>
> On Feb 17, 2:00 pm, Phlip  wrote:
>
>
>
>
>
>
>
> > On Feb 17, 12:03 pm, Cody Django  wrote:
>
> > > For example, I have a captcha that is used in parts of a site that
> > > affects form logic.
> > > The django settings has a variable CAPTCHA = True, which acts as a
> > > switch.
>
> > > I'd like to change this setting in the setup for each TestCase.
>
> > You should use a mock object, to fake a-priori things like stochastic
> > user input.
>
> > Python's mock library has a 'patch.object' feature which mocks a
> > method on a class, even before objects of that class are instantiated.
>
> > In most of your setUp calls, patch the captcha handler to trivially
> > pass it, without real user input.
>
> > To test the captcha, mock it to pass or fail.
>
> > --
> >   Phlip
> >  http://c2.com/cgi/wiki?ZeekLand

-- 
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: Unit Testing: temporarily altering django settings

2011-02-21 Thread Cody Django
Thanks -- I didn't know about mock objects, and this is good to know.
But this doesn't feel like this is the solution I'm looking for.  It's
a large project, and your proposal would require extensive patching.

Is the solution to create a new testrunner that sets a different
environment (with different settings) for each app?  Is there another
way to fool a testcase into thinking that an app has not been
installed?

Thanks again,

Cody



On Feb 17, 2:00 pm, Phlip  wrote:
> On Feb 17, 12:03 pm, Cody Django  wrote:
>
> > For example, I have a captcha that is used in parts of a site that
> > affects form logic.
> > The django settings has a variable CAPTCHA = True, which acts as a
> > switch.
>
> > I'd like to change this setting in the setup for each TestCase.
>
> You should use a mock object, to fake a-priori things like stochastic
> user input.
>
> Python's mock library has a 'patch.object' feature which mocks a
> method on a class, even before objects of that class are instantiated.
>
> In most of your setUp calls, patch the captcha handler to trivially
> pass it, without real user input.
>
> To test the captcha, mock it to pass or fail.
>
> --
>   Phlip
>  http://c2.com/cgi/wiki?ZeekLand

-- 
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: Unit Testing: temporarily altering django settings

2011-02-17 Thread Phlip
On Feb 17, 12:03 pm, Cody Django  wrote:

> For example, I have a captcha that is used in parts of a site that
> affects form logic.
> The django settings has a variable CAPTCHA = True, which acts as a
> switch.
>
> I'd like to change this setting in the setup for each TestCase.

You should use a mock object, to fake a-priori things like stochastic
user input.

Python's mock library has a 'patch.object' feature which mocks a
method on a class, even before objects of that class are instantiated.

In most of your setUp calls, patch the captcha handler to trivially
pass it, without real user input.

To test the captcha, mock it to pass or fail.

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand

-- 
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.