def test_cast_to_server_uses_server_params(self): """Test kombu rpc.cast""" ctxt = rpc_common.CommonRpcContext(user='******', project='fake_project') server_params = {'username': '******', 'password': '******', 'hostname': 'fake_hostname', 'port': 31337, 'virtual_host': 'fake_virtual_host'} class MyConnection(impl_kombu.Connection): def __init__(myself, *args, **kwargs): super(MyConnection, myself).__init__(*args, **kwargs) self.assertEqual( myself.params_list, [{'hostname': server_params['hostname'], 'userid': server_params['username'], 'password': server_params['password'], 'port': server_params['port'], 'virtual_host': server_params['virtual_host'], 'transport': 'memory'}]) def topic_send(_context, topic, msg): pass MyConnection.pool = rpc_amqp.Pool(FLAGS, MyConnection) self.stubs.Set(impl_kombu, 'Connection', MyConnection) impl_kombu.cast_to_server(FLAGS, ctxt, server_params, 'fake_topic', {'msg': 'fake'})
def test_cast_interface_uses_default_options(self): """Test kombu rpc.cast""" ctxt = rpc_common.CommonRpcContext(user='******', project='fake_project') class MyConnection(impl_kombu.Connection): def __init__(myself, *args, **kwargs): super(MyConnection, myself).__init__(*args, **kwargs) self.assertEqual( myself.params_list, [{'hostname': FLAGS.rabbit_host, 'userid': FLAGS.rabbit_userid, 'password': FLAGS.rabbit_password, 'port': FLAGS.rabbit_port, 'virtual_host': FLAGS.rabbit_virtual_host, 'transport': 'memory'}]) def topic_send(_context, topic, msg): pass MyConnection.pool = rpc_amqp.Pool(FLAGS, MyConnection) self.stubs.Set(impl_kombu, 'Connection', MyConnection) impl_kombu.cast(FLAGS, ctxt, 'fake_topic', {'msg': 'fake'})
def _setup_to_server_tests(self, server_params): class MyConnection(impl_qpid.Connection): def __init__(myself, *args, **kwargs): super(MyConnection, myself).__init__(*args, **kwargs) self.assertEqual(myself.connection.username, server_params['username']) self.assertEqual(myself.connection.password, server_params['password']) self.assertEqual( myself.broker, server_params['hostname'] + ':' + str(server_params['port'])) MyConnection.pool = rpc_amqp.Pool(FLAGS, MyConnection) self.stubs.Set(impl_qpid, 'Connection', MyConnection)