def __init__(self): self.publish_service = PublishService() with open("resources/dis_config.yml", 'r') as ymlfile: cfg = yaml.load(ymlfile) PROJ_ENV = cfg['proj_env'] self.publish_wait_timeout = cfg[PROJ_ENV]['publish_wait_timeout'] logger.debug('Publish wait timeout - %d', self.publish_wait_timeout)
class DISService(object): def __init__(self): self.publish_service = PublishService() with open("resources/dis_config.yml", 'r') as ymlfile: cfg = yaml.load(ymlfile) PROJ_ENV = cfg['proj_env'] self.publish_wait_timeout = cfg[PROJ_ENV]['publish_wait_timeout'] logger.debug('Publish wait timeout - %d', self.publish_wait_timeout) def dispatch(self, banter_message): send_status = False if banter_message: send_status = self.publish_service.publish_message(banter_message) if not send_status: time.sleep(self.publish_wait_timeout) send_status = self.publish_service.publish_message(banter_message) return send_status
def test_publish_message_with_null_publish_instance(self, mock_publish_message): mock_publish_message.return_value = False publishService = PublishService() assert publishService.publish_message(self.banterMessage) == False
def test_publish_message(self, mock_get_instance): mock_get_instance.return_value = PpsPubService() publishService = PublishService() assert publishService.publish_message(self.banterMessage) == True
def test_get_instance_with_other_string(self): publishService = PublishService() assert publishService.get_instance('localpubsub') is None
def test_get_instance_with_Pypubsub_string(self): publishService = PublishService() assert publishService.get_instance('Pypubsub') is None
def test_get_instance_with_pypubsub_string(self): publishService = PublishService() assert isinstance(publishService.get_instance('pypubsub'), PpsPubService)
def test_get_instance_with_null_string(self): publishService = PublishService() assert publishService.get_instance('') is None