def setUp(self): # throw up some instance vars that the tests can use self.appid = 'bazapp' self.login_ip = 'publicip1' self.load_balancer_ip = 'privateip1' self.app_port = 1234 self.password = '******' self.jid = self.appid + '@' + self.login_ip # mock out all calls to the logging library flexmock(logging) logging.should_receive('basicConfig').and_return() logging.should_receive('info').with_args(str).and_return() # and mock out all calls to try to make stderr write to the logger fake_open = flexmock(sys.modules['__builtin__']) fake_open.should_call('open') # set the fall-through fake_open.should_receive('open').with_args( '/var/log/appscale/[email protected]', 'a') # finally, pretend that the file on the local filesystem that contains the # port number exists fake_port_file = flexmock(name="fake_port_file") fake_port_file.should_receive('read').and_return(str(self.app_port)) fake_open.should_receive('open').with_args('/etc/appscale/port-{0}.txt' \ .format('{}_default_v1'.format(self.appid))).and_return(fake_port_file)
def insert_logging_mock(log_level): ''' Mock the isEnabledFor from Python logging. ''' logging = flexmock(module.logging.Logger) logging.should_receive('isEnabledFor').replace_with(lambda level: level >= log_level) logging.should_receive('getEffectiveLevel').replace_with(lambda: log_level)
def setUp(self): # throw up some instance vars that the tests can use self.appid = "bazapp" self.login_ip = "publicip1" self.app_port = 1234 self.password = "******" self.jid = self.appid + "@" + self.login_ip # mock out all calls to the logging library flexmock(logging) logging.should_receive("basicConfig").and_return() logging.should_receive("info").with_args(str).and_return() # and mock out all calls to try to make stderr write to the logger fake_open = flexmock(sys.modules["__builtin__"]) fake_open.should_call("open") # set the fall-through fake_open.should_receive("open").with_args("/var/log/appscale/[email protected]", "a") # finally, pretend that the file on the local filesystem that contains the # port number exists fake_port_file = flexmock(name="fake_port_file") fake_port_file.should_receive("read").and_return(str(self.app_port)) fake_open.should_receive("open").with_args("/etc/appscale/port-{0}.txt".format(self.appid)).and_return( fake_port_file )
def insert_logging_mock(log_level): ''' Mock the isEnabledFor from Python logging. ''' logging = flexmock(module.logging.Logger) logging.should_receive('isEnabledFor').replace_with( lambda level: level >= log_level) logging.should_receive('getEffectiveLevel').replace_with(lambda: log_level)
def test_send_xmpp_message(self): # mock out logging flexmock(logging) logging.should_receive('info').and_return() # set up a fake xmpp message fake_xmpp_message = flexmock(name='xmpp_message') # and slip in our mocked message flexmock(xmpppy) flexmock(xmpppy.protocol) xmpppy.protocol.should_receive('Message').with_args(frm=self.my_jid, to=re.compile('one|two'), body=self.message, typ=self.message_type) \ .and_return(fake_xmpp_message) # set up a fake xmpp client fake_xmpp_client = flexmock(name='xmpp') fake_xmpp_client.should_receive('connect').with_args(secure=False) \ .and_return() fake_xmpp_client.should_receive('auth').with_args( self.appid, self.uasecret, resource='').and_return() fake_xmpp_client.should_receive('send').with_args( fake_xmpp_message).and_return() # and slip in our mocked xmpp client in lieu of the real one xmpppy.should_receive('Client').with_args(self.domain, debug=[]) \ .and_return(fake_xmpp_client) xmpp = xmpp_service_real.XmppService(log=logging.info, service_name='xmpp', domain=self.domain, uaserver='public-ip', uasecret=self.uasecret) # Set up a mocked XMPPRequest, that contains the message we want to send and # who we want to send it to. fake_request = flexmock(name='xmpp_message_request') fake_request.should_receive('jid_list').and_return(['one', 'two']) fake_request.should_receive('body').and_return(self.message) fake_request.should_receive('type').and_return(self.message_type) # _Dynamic_SendMessage will put a NO_ERROR message in the response if the # xmpp message was sent successfully, so just make sure the method returned # and that the mocked response has that status. fake_response = flexmock(name='xmpp_message_response') fake_response.should_receive('add_status') \ .with_args(xmpp_service_pb.XmppMessageResponse.NO_ERROR).and_return() self.assertEquals( None, xmpp._Dynamic_SendMessage(fake_request, fake_response))
def test_send_xmpp_message(self): # mock out logging flexmock(logging) logging.should_receive('info').and_return() # set up a fake xmpp message fake_xmpp_message = flexmock(name='xmpp_message') # and slip in our mocked message flexmock(xmpppy) flexmock(xmpppy.protocol) xmpppy.protocol.should_receive('Message').with_args(frm=self.my_jid, to=re.compile('one|two'), body=self.message, typ=self.message_type) \ .and_return(fake_xmpp_message) # set up a fake xmpp client fake_xmpp_client = flexmock(name='xmpp') fake_xmpp_client.should_receive('connect').with_args( (self.ejabberd_ip, self.xmpp_port), secure=False) fake_xmpp_client.should_receive('auth').with_args(self.appid, self.uasecret, resource='').and_return() fake_xmpp_client.should_receive('send').with_args( fake_xmpp_message).and_return() # and slip in our mocked xmpp client in lieu of the real one xmpppy.should_receive('Client').with_args(self.domain, debug=[]) \ .and_return(fake_xmpp_client) xmpp = xmpp_service_real.XmppService( self.ejabberd_ip, log=logging.info, service_name='xmpp', domain=self.domain, uaserver='public-ip', uasecret=self.uasecret) # Set up a mocked XMPPRequest, that contains the message we want to send and # who we want to send it to. fake_request = flexmock(name='xmpp_message_request') fake_request.should_receive('jid_list').and_return(['one', 'two']) fake_request.should_receive('body').and_return(self.message) fake_request.should_receive('type').and_return(self.message_type) # _Dynamic_SendMessage will put a NO_ERROR message in the response if the # xmpp message was sent successfully, so just make sure the method returned # and that the mocked response has that status. fake_response = flexmock(name='xmpp_message_response') fake_response.should_receive('add_status') \ .with_args(xmpp_service_pb.XmppMessageResponse.NO_ERROR).and_return() self.assertEquals(None, xmpp._Dynamic_SendMessage(fake_request, fake_response))
def test_send_channel_message(self): # mock out logging flexmock(logging) logging.should_receive('info').and_return() # set up a fake xmpp message fake_xmpp_message = flexmock(name='xmpp_message') # and slip in our mocked message flexmock(xmpppy) flexmock(xmpppy.protocol) xmpppy.protocol.should_receive('Message').with_args( frm=self.my_jid, to=re.compile('channel.*key@domain'), body=self.message, typ=self.message_type).and_return(fake_xmpp_message) # set up a fake xmpp client fake_xmpp_client = flexmock(name='xmpp') fake_xmpp_client.should_receive('connect').with_args(secure=False) \ .and_return() fake_xmpp_client.should_receive('auth').with_args( self.appid, self.uasecret, resource='').and_return() fake_xmpp_client.should_receive('send').with_args( fake_xmpp_message).and_return() # and slip in our mocked xmpp client in lieu of the real one xmpppy.should_receive('Client').with_args(self.domain, debug=[]) \ .and_return(fake_xmpp_client) xmpp = xmpp_service_real.XmppService(log=logging.info, service_name='xmpp', domain=self.domain, uaserver='public-ip', uasecret=self.uasecret) # Set up a mocked XMPPRequest, that contains the message we want to send and # who we want to send it to. fake_request = flexmock(name='xmpp_message_request') fake_request.should_receive('message').and_return(self.message) fake_request.should_receive('application_key').and_return('key') # Unlike _Dynamic_SendMessage, the channel version doesn't set the NO_ERROR # status, and it doesn't actually return anything, so just make sure that # no exceptions were thrown. self.assertEquals(None, xmpp._Dynamic_SendChannelMessage(fake_request, None))
def setUp(self): # throw up some instance vars that the tests can use self.appid = 'bazapp' self.login_ip = 'publicip1' self.password = '******' self.jid = self.appid + '@' + self.login_ip # mock out all calls to the logging library flexmock(logging) logging.should_receive('basicConfig').and_return() logging.should_receive('info').with_args(str).and_return() # and mock out all calls to try to make stderr write to the logger fake_open = flexmock(sys.modules['__builtin__']) fake_open.should_call('open') # set the fall-through fake_open.should_receive('open').with_args( '/var/log/appscale/[email protected]', 'a')
def setUp(self): # throw up some instance vars that the tests can use self.appid = "bazapp" self.login_ip = "publicip1" self.app_port = 1234 self.password = "******" self.jid = self.appid + "@" + self.login_ip # mock out all calls to the logging library flexmock(logging) logging.should_receive("basicConfig").and_return() logging.should_receive("info").with_args(str).and_return() # and mock out all calls to try to make stderr write to the logger fake_open = flexmock(sys.modules["__builtin__"]) fake_open.should_call("open") # set the fall-through fake_open.should_receive("open").with_args("/var/log/appscale/[email protected]", "a")
def setUp(self): # throw up some instance vars that the tests can use self.appid = 'bazapp' self.login_ip = 'publicip1' self.app_port = 1234 self.password = '******' self.jid = self.appid + '@' + self.login_ip # mock out all calls to the logging library flexmock(logging) logging.should_receive('basicConfig').and_return() logging.should_receive('info').with_args(str).and_return() # and mock out all calls to try to make stderr write to the logger fake_open = flexmock(sys.modules['__builtin__']) fake_open.should_call('open') # set the fall-through fake_open.should_receive('open').with_args( '/var/log/appscale/[email protected]', 'a')
def test_send_channel_message(self): # mock out logging flexmock(logging) logging.should_receive('info').and_return() # set up a fake xmpp message fake_xmpp_message = flexmock(name='xmpp_message') # and slip in our mocked message flexmock(xmpppy) flexmock(xmpppy.protocol) xmpppy.protocol.should_receive('Message').with_args(frm=self.my_jid, to=re.compile('channel.*key@domain'), body=self.message, typ=self.message_type).and_return(fake_xmpp_message) # set up a fake xmpp client fake_xmpp_client = flexmock(name='xmpp') fake_xmpp_client.should_receive('connect').with_args( (self.ejabberd_ip, self.xmpp_port), secure=False) fake_xmpp_client.should_receive('auth').with_args(self.appid, self.uasecret, resource='').and_return() fake_xmpp_client.should_receive('send').with_args( fake_xmpp_message).and_return() # and slip in our mocked xmpp client in lieu of the real one xmpppy.should_receive('Client').with_args(self.domain, debug=[]) \ .and_return(fake_xmpp_client) xmpp = xmpp_service_real.XmppService( self.ejabberd_ip, log=logging.info, service_name='xmpp', domain=self.domain, uaserver='public-ip', uasecret=self.uasecret) # Set up a mocked XMPPRequest, that contains the message we want to send and # who we want to send it to. fake_request = flexmock(name='xmpp_message_request') fake_request.should_receive('message').and_return(self.message) fake_request.should_receive('application_key').and_return('key') # Unlike _Dynamic_SendMessage, the channel version doesn't set the NO_ERROR # status, and it doesn't actually return anything, so just make sure that # no exceptions were thrown. self.assertEquals(None, xmpp._Dynamic_SendChannelMessage(fake_request, None))
try: import to_bgp except ImportError: from schema_transformer import to_bgp try: import config_db except ImportError: from schema_transformer import config_db from gevent import sleep flexmock(ICKombuClient) ICKombuClient.should_receive('_reinit_control') flexmock(logging) logging.should_receive('basicConfig') flexmock(issu_contrail_config) issu_contrail_config.should_receive('issu_info_pre').and_return([ (None, 'config_db_uuid', { 'obj_uuid_table': {}, 'obj_fq_name_table': {}, 'obj_shared_table': {} }), (None, 'to_bgp_keyspace', { 'route_target_table': {}, 'service_chain_table': {}, 'service_chain_ip_address_table': {}, 'service_chain_uuid_table': {} }), (None, 'useragent', { 'useragent_keyval_table': {}
try: import to_bgp except ImportError: from schema_transformer import to_bgp try: import config_db except ImportError: from schema_transformer import config_db from gevent import sleep flexmock(ICKombuClient) ICKombuClient.should_receive('_act_on_api') flexmock(logging) logging.should_receive('basicConfig') flexmock(issu_contrail_config) issu_contrail_config.should_receive('issu_info_pre').and_return([ (None, 'config_db_uuid', { 'obj_uuid_table': {}, 'obj_fq_name_table': {}, 'obj_shared_table': {}}), (None, 'to_bgp_keyspace', { 'route_target_table': {}, 'service_chain_table': {}, 'service_chain_ip_address_table': {}, 'service_chain_uuid_table': {}}), (None, 'useragent', {'useragent_keyval_table': {}}), (None, 'svc_monitor_keyspace', { 'pool_table': {}, 'service_instance_table': {}})]) issu_contrail_config.should_receive('issu_info_post').and_return([
def insert_logging_mock(log_level): """ Mocks the isEnabledFor from python logging. """ logging = flexmock(module.logging.Logger) logging.should_receive('isEnabledFor').replace_with(lambda lvl : lvl >= log_level) logging.should_receive('getEffectiveLevel').replace_with(lambda: log_level)