示例#1
0
def bugs(app):
    '''
    Add an analysis and some bugs
    '''
    from shipit_uplift.models import (
        BugAnalysis, BugResult, Contributor, BugContributor
    )

    # Add 2 analysis
    analysis = []
    for i in ('Dev', 'Release'):
        a = BugAnalysis(name=i)
        a.version = 1  # dummy version
        app.db.session.add(a)
        analysis.append(a)

    # Add bugs with real payload
    paths = glob.glob(os.path.join(FIXTURES_DIR, 'bug_*.json'))
    sorted(paths)
    bugs = []
    for path in paths:
        payload = json.load(open(path))
        bug = BugResult(bugzilla_id=payload['bug']['id'])
        bug.payload = pickle.dumps(payload, 2)
        analysis[0].bugs.append(bug)
        app.db.session.add(bug)
        bugs.append(bug)

        # Add creator & link to bug
        user = payload['analysis']['users']['creator']
        contrib = Contributor(bugzilla_id=user['id'])
        contrib.name = user.get('real_name', user['name'])
        contrib.email = user['email']
        contrib.avatar_url = 'gravatar_url_here'
        contrib.karma = 1
        contrib.comment_private = 'hidden comment'
        contrib.comment_public = 'Top Contributor'
        link = BugContributor(bug=bug, contributor=contrib, roles='creator')
        app.db.session.add(contrib)
        app.db.session.add(link)

    app.db.session.commit()

    return bugs
示例#2
0
def list_analysis():
    '''
    List all available analysis
    '''
    all_analysis = BugAnalysis.with_bugs().all()
    logger.info('Fetched all analysis from db', all_analysis=all_analysis)
    return [
        serialize_analysis(analysis, nb, False)
        for analysis, nb in all_analysis
    ]
示例#3
0
def test_analysis_query_strings():
    '''
    Check Bugzilla parameters building
    '''
    from shipit_uplift.models import BugAnalysis

    assert_query_strings(
        BugAnalysis(name='aurora', version=52).build_parameters(),
        'o5=substring&j9=OR&o2=substring&f12=CP&o4=substring&known_name=approval-mozilla-aurora&f10=requestees.login_name&f1=OP&o3=substring&f0=OP&f8=OP&v3=approval-mozilla-aurora%3F&query_based_on=approval-mozilla-aurora&f9=OP&f4=flagtypes.name&query_format=advanced&o10=substring&j1=OR&f3=flagtypes.name&f2=flagtypes.name&f11=CP&f5=flagtypes.name&f6=CP&f7=CP'  # noqa
    )
    assert_query_strings(
        BugAnalysis(name='beta', version=51).build_parameters(),
        'o5=substring&f10=requestees.login_name&f1=OP&j9=OR&o3=substring&f0=OP&f8=OP&v3=approval-mozilla-beta%3F&query_based_on=approval-mozilla-beta&o2=substring&f9=OP&f4=flagtypes.name&query_format=advanced&o10=substring&f12=CP&j1=OR&f3=flagtypes.name&f2=flagtypes.name&o4=substring&f11=CP&f5=flagtypes.name&f6=CP&f7=CP&known_name=approval-mozilla-beta'  # noqa
    )
    assert_query_strings(
        BugAnalysis(name='release', version=50).build_parameters(),
        'o5=substring&j9=OR&o2=substring&f12=CP&o4=substring&known_name=approval-mozilla-release&f10=requestees.login_name&f1=OP&o3=substring&f0=OP&f8=OP&v3=approval-mozilla-release%3F&query_based_on=approval-mozilla-release&f9=OP&f4=flagtypes.name&query_format=advanced&o10=substring&j1=OR&f3=flagtypes.name&f2=flagtypes.name&f11=CP&f5=flagtypes.name&f6=CP&f7=CP'  # noqa
    )
    assert_query_strings(
        BugAnalysis(name='esr', version=45).build_parameters(),
        'o5=substring&f10=requestees.login_name&f1=OP&j9=OR&o3=substring&f0=OP&f8=OP&v3=approval-mozilla-esr45%3F&query_based_on=approval-esr45&o2=substring&f9=OP&f4=flagtypes.name&query_format=advanced&o10=substring&f12=CP&j1=OR&f3=flagtypes.name&f2=flagtypes.name&o4=substring&f11=CP&f5=flagtypes.name&f6=CP&f7=CP&known_name=approval-esr45'  # noqa
    )
示例#4
0
def get_analysis(analysis_id):
    '''
    Fetch an analysis and all its bugs
    '''

    # Get bug analysis
    try:
        analysis, bugs_nb = BugAnalysis.with_bugs() \
            .join(BugResult, isouter=True) \
            .filter(BugAnalysis.id == analysis_id) \
            .one()
    except NoResultFound:
        abort(404)

    logger.info('Fetched analysis from db', analysis=analysis)

    # Build JSON output
    return serialize_analysis(analysis, bugs_nb)
示例#5
0
def update_analysis(analysis_id):
    '''
    Update an analysis, from a bot
    Used to update version numbers from bot
    '''

    # Get bug analysis
    try:
        analysis, bugs_nb = BugAnalysis.with_bugs() \
            .filter(BugAnalysis.id == analysis_id) \
            .one()
    except NoResultFound:
        abort(404)

    # Update version
    if 'version' in request.json:
        analysis.version = int(request.json['version'])

    # Save changes in db
    db.session.add(analysis)
    db.session.commit()

    # Build JSON output
    return serialize_analysis(analysis, bugs_nb)