def mock_auth(auth_function_path):
 from ckan.authz import clear_auth_functions_cache
 def decorator(func):
  def wrapper(*args, **kwargs):
   try:
    with mock.patch(auth_function_path) as mocked_auth:
     clear_auth_functions_cache()
     new_args = (args + tuple([mocked_auth]))
     return_value = func(*new_args, **kwargs)
   finally:
    clear_auth_functions_cache()
   return return_value
  return nose.tools.make_decorator(func)(wrapper)
 return decorator

def mock_auth ( auth_function_path ) : from ckan . authz import clear_auth_functions_cache def decorator ( func ) : def wrapper ( * args , ** kwargs ) : try : with mock . patch ( auth_function_path ) as mocked_auth : clear_auth_functions_cache ( ) new_args = ( args + tuple ( [ mocked_auth ] ) ) return_value = func ( * new_args , ** kwargs ) finally : clear_auth_functions_cache ( ) return return_value return nose . tools . make_decorator ( func ) ( wrapper ) return decorator
decorator to easily mock a ckan auth method in the context of a test function it adds a mock object for the provided auth_function_path as a parameter to the test function .