[TIP] Mock and Sunburnt

Thomas, Alexander athom09 at emory.edu
Thu Sep 8 12:16:37 PDT 2011

I am having a problem with the interaction of Mock and another library called sunburnt.

Here is the section of my code:

#These are the criteria that will go on every query - Also not the "|", this is what is causing the problem.
cm_query = solr.Q(solr.Q(model="value1") \
        | solr.Q(model="value2"))
#search_options are the user entered options I am then filtering by cm_query

The above works fine but when I try to test it with mock I get the error:
Traceback (most recent call last):
  File "/home/athom09/Projects/keep/keep/../keep/common/tests.py", line 216, in test_search
    response = self.client.get(search_url)
  File "/home/athom09/Projects/keep/keepEnv/lib/python2.6/site-packages/django/test/client.py", line 445, in get
    response = super(Client, self).get(path, data=data, **extra)
  File "/home/athom09/Projects/keep/keepEnv/lib/python2.6/site-packages/django/test/client.py", line 229, in get
    return self.request(**r)
  File "/home/athom09/Projects/keep/keepEnv/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/athom09/Projects/keep/keepEnv/lib/python2.6/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/home/athom09/Projects/keep/keep/../keep/common/views.py", line 79, in search
    | solr.Q(content_model=AudioObject.AUDIO_CONTENT_MODEL))
TypeError: unsupported operand type(s) for |: 'Mock' and 'Mock'

According to the the Sunburnt developer, the | operator  is an alias for  A.__or__(B).  Is there something special I need to do to mock this correctly preferably using the | operator?



This e-mail message (including any attachments) is for the sole use of
the intended recipient(s) and may contain confidential and privileged
information. If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, distribution
or copying of this message (including any attachments) is strictly

If you have received this message in error, please contact
the sender by reply e-mail message and destroy all copies of the
original message (including attachments).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20110908/d2c34a38/attachment.html>

More information about the testing-in-python mailing list