def get_user_redmine_id(project_name, name):
    """Get the redmine id for the user assigned to this alert.
    The assigned user is defined in the UserEventNotification associated with the alert_alarm definition
    (class SystemEventDefinition).
    """
    redmine_id = None
    try:
        if name is None:
            message = 'User name is None; unable to get redmine id for user assigned to alert or alarm.'
            current_app.logger.info('[get_user_redmine_id] %s ' % message)
            return redmine_id
        list_redmine_users = get_redmine_users_by_project(project_name)
        if len(list_redmine_users) == 0:
            message = 'No redmine user for this project (%s)' % project_name
            current_app.logger.info('[get_user_redmine_id] %s ' % message)
            raise Exception(message)
        redmine_users = list_redmine_users['users']
        for user_tuple in redmine_users:
            if str(user_tuple[0]) == name:
                redmine_id = user_tuple[1]
                break
        return redmine_id
    except Exception as err:
        current_app.logger.info('[get_user_redmine_id] %s ' % err.message)
        return redmine_id
    def test_get_redmine_users_by_project(self):
        '''
        project = 'no_such_project'
        result = get_redmine_users_by_project(project)
        self.assertEquals(result, [])

        result = get_redmine_users_by_project(PROJECT)
        self.assertEquals(result, [])

        result = get_redmine_users_by_project(None)
        self.assertEquals(result, [])

        project = 'C2 Testing'
        result = get_redmine_users_by_project(project)
        self.assertTrue(len(result) != 0)
        '''
        project = 'ocean-observatory'
        result = get_redmine_users_by_project(project)
        self.assertTrue(result != [])
        self.assertTrue(len(result) != 0)
    def test_get_redmine_users_by_project(self):

        '''
        project = 'no_such_project'
        result = get_redmine_users_by_project(project)
        self.assertEquals(result, [])

        result = get_redmine_users_by_project(PROJECT)
        self.assertEquals(result, [])

        result = get_redmine_users_by_project(None)
        self.assertEquals(result, [])

        project = 'C2 Testing'
        result = get_redmine_users_by_project(project)
        self.assertTrue(len(result) != 0)
        '''
        project = 'ocean-observatory'
        result = get_redmine_users_by_project(project)
        self.assertTrue(result != [])
        self.assertTrue(len(result) != 0)
Example #4
0
def get_user_redmine_id(project_name, name):
    """Get the redmine id for the user assigned to this alert.
    The assigned user is defined in the UserEventNotification associated with the alert_alarm definition
    (class SystemEventDefinition).
    """
    redmine_id = None
    try:
        if name is None:
            message = 'User name is None; unable to get redmine id for user assigned to alert or alarm.'
            current_app.logger.exception('[get_user_redmine_id] %s ' % message)
            return redmine_id
        list_redmine_users = get_redmine_users_by_project(project_name)
        if len(list_redmine_users) == 0:
            message = 'No redmine user for this project (%s)' % project_name
            raise Exception(message)
        redmine_users = list_redmine_users['users']
        for user_tuple in redmine_users:
            if str(user_tuple[0]) == name:
                redmine_id = user_tuple[1]
                break
        return redmine_id
    except Exception as err:
        current_app.logger.exception('[get_user_redmine_id] %s ' % err.message)
        return redmine_id