<s> """<STR_LIT>""" <EOL> import mock <EOL> from oslo_config import cfg <EOL> from nova . console import rpcapi as console_rpcapi <EOL> from nova import context <EOL> from nova import test <EOL> CONF = cfg . CONF <EOL> class ConsoleRpcAPITestCase ( test . NoDBTestCase ) : <EOL> def _test_console_api ( self , method , rpc_method , ** kwargs ) : <EOL> ctxt = context . RequestContext ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> rpcapi = console_rpcapi . ConsoleAPI ( ) <EOL> self . assertIsNotNone ( rpcapi . client ) <EOL> self . assertEqual ( rpcapi . client . target . topic , CONF . console_topic ) <EOL> orig_prepare = rpcapi . client . prepare <EOL> with test . nested ( <EOL> mock . patch . object ( rpcapi . client , rpc_method ) , <EOL> mock . patch . object ( rpcapi . client , '<STR_LIT>' ) , <EOL> mock . patch . object ( rpcapi . client , '<STR_LIT>' ) , <EOL> ) as ( <EOL> rpc_mock , prepare_mock , csv_mock <EOL> ) : <EOL> prepare_mock . return_value = rpcapi . client <EOL> rpc_mock . return_value = '<STR_LIT:foo>' if rpc_method == '<STR_LIT>' else None <EOL> csv_mock . side_effect = ( <EOL> lambda v : orig_prepare ( ) . can_send_version ( ) ) <EOL> retval = getattr ( rpcapi , method ) ( ctxt , ** kwargs ) <EOL> self . assertEqual ( retval , rpc_mock . return_value ) <EOL> prepare_mock . assert_called_once_with ( ) <EOL> rpc_mock . assert_called_once_with ( ctxt , method , ** kwargs ) <EOL> def test_add_console ( self ) : <EOL> self . _test_console_api ( '<STR_LIT>' , instance_id = '<STR_LIT:i>' , <EOL> rpc_method = '<STR_LIT>' ) <EOL> def test_remove_console ( self ) : <EOL> self . _test_console_api ( '<STR_LIT>' , console_id = '<STR_LIT:i>' , <EOL> rpc_method = '<STR_LIT>' ) </s>
