Hi,

I'm attempting to use the python mock library with some unittest based 
tests for a web2py application. It feels like I'm going against the grain. 

General question: Is it generally a pain to use mock with web2py 
applications or am I missing some trick to get it working ?

Specifically, in models/db.py I have

from gluon.contrib.login_methods.ldap_auth import ldap_auth

in a unittest implementation I have

def mock_ldap_auth(*args,**kw):
    return True

mock_ldap_auth = mock.patch(
        'db.ldap_auth',
        side_effect=mock_ldap_auth)


I'm using web2py_utils and webtest to drive unittest.

class TestSomething(unittest.TestCase):
    # __init__ method which intialises webtest

    def setUp(self):
        p = mock_ldap_auth.start()
        self.addCleanup(p.stop)

The call to 'mock_ldap_auth.start()' produces this traceback::

Traceback (most recent call last):
  File "C:\Projects\web2py\applications\icss/tests\sign_infra.py", line 49, 
in setUp
    p = mock_ldap_auth.start()
  File "C:\Projects\pyenvs\icss\lib\site-packages\mock\mock.py", line 1500, 
in start
    result = self.__enter__()
  File "C:\Projects\pyenvs\icss\lib\site-packages\mock\mock.py", line 1353, 
in __enter__
    self.target = self.getter()
  File "C:\Projects\pyenvs\icss\lib\site-packages\mock\mock.py", line 1523, 
in <lambda>
    getter = lambda: _importer(target)
  File "C:\Projects\pyenvs\icss\lib\site-packages\mock\mock.py", line 1206, 
in _importer
    thing = __import__(import_path)
  File "C:\Projects\web2py\gluon\custom_import.py", line 89, in 
custom_importer
    raise ImportError, 'Cannot import module %s' % str(e)
ImportError: Cannot import module 'applications.icss.modules.db'

Note: My purpose in asking this question is to avoid ugly and unnecessary 
case specific work arounds.

Thanks,

Robin

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to