¡@

Home 

OpenStack Study: cast_as_call.py

OpenStack Index

**** CubicPower OpenStack Study ****

def mock_cast_as_call(obj=None):

    """Use this to mock `cast` as calls.

    :param obj: Either an instance of RPCClient

    or an instance of _Context.

    """

    orig_prepare = obj.prepare

    def prepare(*args, **kwargs):

        cctxt = orig_prepare(*args, **kwargs)

        mock_cast_as_call(obj=cctxt)  # woo, recurse!

        return cctxt

    prepare_patch = mock.patch.object(obj, 'prepare').start()

    prepare_patch.side_effect = prepare

    cast_patch = mock.patch.object(obj, 'cast').start()

    cast_patch.side_effect = obj.call