Example #1
0
def find_history(result):
    assert isinstance(result, Result)
    estimated_runtime = 1
    history = []

    # other results with the same Test, Testplan, Environment, Release
    try:
        query = {"testcase__testcaseId": result.testcase.testcaseId,
                 "recorded__lt":result.recorded}
        if hasattr(result, 'config') and result.config is not None:
            query['config__configId'] = result.config.configId
        else:
            query['config__exists'] = False
        if os.environ.get('HISTORY_IGNORE_RELEASE', 'false').lower() == 'true':
            pass
        elif hasattr(result, 'release') and result.release is not None:
            query['release__releaseId'] = result.release.releaseId
        else:
            query['release__exists'] = False
        if hasattr(result.testrun, 'testplanId') and result.testrun.testplanId is not None:
            query['testrun__testplanId'] = result.testrun.testplanId
        else:
            query['testrun__testplanId__exists'] = False

        for hresult in Result.objects(**query).fields(id=1, status=1, recorded=1, build=1, started=1, finished=1).order_by('-recorded').limit(10):
            if hresult.started and hresult.finished:
                hist_length = int(math.ceil((hresult.finished - hresult.started).total_seconds()))
                if hist_length > estimated_runtime:
                    estimated_runtime = hist_length
            history.append(create_result_reference(hresult))
    except:
        logger = logging.getLogger('slickqaweb.api.result.find_history')
        logger.error("Error in finding history", exc_info=sys.exc_info())
    return history, estimated_runtime
Example #2
0
def find_history(result):
    assert isinstance(result, Result)
    history = []

    # other results with the same Test, Testplan, Environment, Release
    try:
        query = {"testcase__testcaseId": result.testcase.testcaseId,
                 "recorded__lt":result.recorded}
        if hasattr(result, 'config') and result.config is not None:
            query['config__configId'] = result.config.configId
        else:
            query['config__exists'] = False
        if hasattr(result, 'release') and result.release is not None:
            query['release__releaseId'] = result.release.releaseId
        else:
            query['release__exists'] = False
        if hasattr(result.testrun, 'testplanId') and result.testrun.testplanId is not None:
            query['testrun__testplanId'] = result.testrun.testplanId
        else:
            query['testrun__testplanId__exists'] = False

        for hresult in Result.objects(**query).order_by('-recorded').limit(10):
            history.append(create_result_reference(hresult))
    except:
        logger = logging.getLogger('slickqaweb.api.result.find_history')
        logger.error("Error in finding history", exc_info=sys.exc_info())
    return history
Example #3
0
def apply_triage_notes(result, testcase=None):
    """This function checks to see if a result should have triage notes, and adds them if need be.
    If the result's status is a non-final result, then it will be ignored.

    You can optionally pass in a testcase (if you have already looked one up), if you do not, it will be looked up.

    :param result: The result to check
    :type result: slickqa.model.result.Result
    :param testcase: A testcase that has been looked up from the database.
    :type testcase: slickqa.model.testcase.Testcase
    :returns: Nothing
    """
    # if the test isn't finished yet just return
    if result.status in NON_FINAL_STATUS:
        return

    # if the test is finished, but they didn't pass in the testcase, find it
    if testcase is None:
        testcase = find_testcase_by_reference(result.testcase)

    # if we still don't know the testcase we can't apply any triage notes
    if testcase is None:
        return

    assert isinstance(testcase, Testcase)

    # if there are no active notes on the testcase, move on
    if is_not_provided(testcase, 'activeNotes'):
        return

    # go through each active triage note, check to see if it matches
    notes_to_remove = []
    for activeNote in testcase.activeNotes:
        assert isinstance(activeNote, RecurringNote)
        # check to see if the environment matches
        if is_provided(activeNote, 'environment'):
            if is_not_provided(result, 'config') or is_not_provided(result.config, 'configId') or \
               activeNote.environment.configId != result.config.configId:
                continue

        # check to see if the release matches
        if is_provided(activeNote, 'release'):
            if is_not_provided(result, 'release') or is_not_provided(result.release, 'releaseId') or \
               activeNote.release.releaseId != result.release.releaseId:
                continue

        # at this point it matches
        if result.status == 'PASS':
            # update the note to be inactive
            notes_to_remove.append(activeNote)
        else:
            # apply the triage note
            if is_not_provided(result, 'log'):
                result.log = []
            logentry = LogEntry()
            logentry.entryTime = datetime.datetime.now()
            logentry.level = 'WARN'
            logentry.loggerName = 'slick.note'
            logentry.message = activeNote.message
            if is_provided(activeNote, 'url'):
                logentry.exceptionMessage = activeNote.url
            result.log.append(logentry)

    # move any notes that are no longer active (because the test passed) to the inactiveNotes section
    if len(notes_to_remove) > 0:
        # if we are modifying the testcase we need to generate an event
        update_event = events.UpdateEvent(before=testcase)
        for note in notes_to_remove:
            # remove from activeNotes and put in inactiveNotes
            testcase.activeNotes.remove(note)
            if is_not_provided(testcase, 'inactiveNotes'):
                testcase.inactiveNotes = []
            testcase.inactiveNotes.append(note)
            # set the inactivatedBy field to this result
            note.inactivatedBy = create_result_reference(result)
        update_event.after(testcase)
        testcase.save()