def download_testcase(id):
    t = db_session.query(Testcase).filter(Testcase.id == id).first()
    if not t:
        return abort(404)
    if not t.is_public:
        return abort(401)
    text = utils.testcase_to_text(json.loads(t.content))
    return Response(text, content_type='text/plain; charset=utf-8')
Exemple #2
0
def add_testcase():
    if len(sys.argv) not in [3, 4]:
        print('usage: ./maintenance.py add_testcase <path_to_testcase> [-y]')
        sys.exit(1)
    with codecs.open(sys.argv[2], 'r', 'utf-8') as f:
        content = f.read()
    t = utils.parse_testcase(content)
    if len(sys.argv) == 4:
        assert sys.argv[3] == '-y'
    else:
        print(utils.testcase_to_text(t))
        confirm = raw_input('Confirm (y/n)? ')
        assert confirm.strip() == 'y'
    testcase = Testcase(enabled=True,
                        phase=t['phase'],
                        is_public=t['is_public'],
                        comment=t['comment'],
                        timeout=t.get('timeout', None),
                        cnt_run=0,
                        cnt_hack=0,
                        content=json.dumps(t))
    db_session.add(testcase)
    db_session.commit()

    tphase = utils.phase_to_index(testcase.phase)
    for compiler in db_session.query(Compiler):
        version = db_session.query(Version).filter(Version.id == compiler.latest_version_id).first()
        if not version:
            continue
        vphase = utils.phase_to_index(version.phase)
        if vphase > tphase or (vphase == tphase and version.status != 'pending'):
            r = TestRun(version_id=version.id,
                        testcase_id=testcase.id,
                        phase=testcase.phase,
                        status='pending',
                        created_at=datetime.utcnow())
            db_session.add(r)
            version.phase = testcase.phase
            version.status = 'running'
    db_session.commit()
    print('done!', sys.argv[2])