Exemplo n.º 1
0
    def __init__(self, test, update_current_test_value = True):
        if type(test) == int :
            from testing_runtime import tests_config
            test = tests_config.all_tests()[test]

        self._test = test
        self._update_current_test_value = update_current_test_value
Exemplo n.º 2
0
def verify_test(test_id=None,code=None) :
    errors = []
    present = False
    try :
        #remember locals
        b = locals().keys()

        #execute test code
        exec code

        #checkout wich name appeared in locals
        all_tests = tests_config.all_tests()
        a = locals().keys()
        for x in a :
            if not x in b :
                test = locals()[x]
                if inspect.isclass(test) and issubclass(test, utils.Test) :
                    present = True

                    if issubclass(test, utils.SubTest) :
                        if test.__parent_test__ is None :
                            errors.append( u"Не указан аттрибут __parent_test__ у подтеста" )
                        else :
                            parent_here = False
                            for x in all_tests :
                                if utils.test_name(all_tests[x]) == test.__parent_test__ :
                                    parent_here = True
                            if not parent_here :
                                errors.append( u'Нету теста страницы с id="{0}"'.format(test.__parent_test__) )

                        if  not test.__parent_test__ is None :
                            all_tests = tests_config.all_tests()
                            class_name = utils.test_name(test)
                            for x in all_tests :
                                if not (test_id == x) and (utils.test_name(all_tests[x]) == class_name) :
                                    errors.append( u'Уже есть тест "{0}"'.format(utils.test_name(test)) )

    except :
        errors.append( u'exec теста рыгнул exception: {0}'.format(traceback.format_exc().decode('utf-8')) )

    if not present :
        errors.append( u'В коде не обнаружен класс теста' )

    return errors
Exemplo n.º 3
0
def gather_tests_info( selected_tests = [] ) :
    tests_config._fetch_tests()

    tests = []

    all_tests = tests_config.all_tests()
    for i in all_tests :
        pagetest = all_tests[i]()
        if isinstance(pagetest, utils.PageTest) :
            test = {}
            test[ 'id' ] = i
            test[ 'name' ] = utils.test_name(pagetest)
            test[ 'url' ] = pagetest.url
            test[ 'doc' ] = pagetest.__doc__
            test[ 'checked' ] = i in selected_tests
            test[ 'subtests' ] = []
            whose = tests_config.test_id_to_whose( i )
            test[ 'whose' ] = whose if not whose is None else "-"
            test[ 'status' ] = tests_config.test_id_to_status( i )
            tags = db.session.query( StoredTest ).get( i ).tags
            test[ 'tags' ] = map( lambda tag : tag.value, tags )
            for j in all_tests :
                subtest = all_tests[j]()
                if isinstance(subtest, utils.SubTest) and\
                   subtest.__parent_test__ == utils.test_name(pagetest) :
                    stest = {}
                    stest[ 'id' ] = j
                    stest[ 'name' ] = utils.test_name(subtest)
                    stest[ 'doc' ] = subtest.__doc__
                    stest[ 'checked' ] = j in selected_tests
                    whose = tests_config.test_id_to_whose( j )
                    stest[ 'whose' ] = whose if not whose is None else "-"
                    stest[ 'status' ] = tests_config.test_id_to_status( j )
                    test[ 'subtests' ].append( stest )
                    tags = db.session.query( StoredTest ).get( j ).tags
                    stest[ 'tags' ] = map( lambda tag : tag.value, tags )
            tests.append( test )
        elif isinstance(pagetest, utils.MainTest) :
            test = {}
            test[ 'id' ] = i
            test[ 'name' ] = utils.test_name(pagetest)
            test[ 'url' ] = ""
            test[ 'doc' ] = pagetest.__doc__
            test[ 'checked' ] = i in selected_tests
            test[ 'subtests' ] = []
            whose = tests_config.test_id_to_whose( i )
            test[ 'whose' ] = whose if not whose is None else "-"
            test[ 'status' ] = tests_config.test_id_to_status( i )
            tags = db.session.query( StoredTest ).get( i ).tags
            test[ 'tags' ] = map( lambda tag : tag.value, tags )
            tests.append(test)

    return tests
Exemplo n.º 4
0
def update_test(request, test_id) :
    title = html.title( [ _('Update test') + " #" + str(test_id), _('Tests'), 'Ganymede' ] )

    test_id = int(test_id)
    if request.method == "POST" :
        err = verify_test( test_id = test_id, code = request.POST['code'] )
        if len(err) == 0 :
            db.session\
            .query(models.StoredTest)\
            .filter( models.StoredTest.test_id == test_id )\
            .update( {
                "code" : request.POST['code'].encode('utf-8'),
                "status" : request.POST['status'].encode('utf-8')
            } )

            tags = json_to_tags( request.POST['tags'] )
            test = db.session.query(models.StoredTest).get( test_id )
            test.tags = tags

            json_resp = json.dumps( { "status" : "ok" } )
            return HttpResponse(json_resp, mimetype="application/json")
        else :
            json_resp = json.dumps( { "status" : "error", "content" : err } )
            return HttpResponse(json_resp, mimetype="application/json")

    else :
        test_model = db.session\
        .query( models.StoredTest )\
        .filter( models.StoredTest.test_id == test_id )\
        .one()
        test = {}
        test["id"] = test_id
        test["name"] = tests_config.all_tests()[test_id].__doc__
        test["code"] = test_model.code
        test["status"] = test_model.status
        test["tags"] = map( lambda tag : tag.value, test_model.tags )

        return render_to_response(
            "test/update/update_test.html",
            {"test":test,'title' : title},
            context_instance=RequestContext(request)
        )
Exemplo n.º 5
0
def remove_test(request) :
    test_id = int(request.POST[ 'test_id' ])

    all_tests = tests_config.all_tests()

    if issubclass( all_tests[test_id], utils.PageTest ) :
        ids_to_del = [ test_id ]
        for i in all_tests :
            if hasattr( all_tests[i], '__parent_test__' ) and\
            all_tests[i].__parent_test__ == utils.test_name( all_tests[ test_id ] ) :
                ids_to_del.append( i )

        for id in ids_to_del :
            db.session.query(models.StoredTest).\
            filter(models.StoredTest.test_id == id).\
            delete()
    else :
        db.session.query(models.StoredTest).\
        filter(models.StoredTest.test_id == test_id).\
        delete()

    json_resp = json.dumps( { "status" : "ok" } )
    return HttpResponse(json_resp, mimetype="application/json")
Exemplo n.º 6
0
def get_current_test_result( log_offset = 0 ) :
    global _task
    from testing_runtime import tests_config

    curr_id = get_current_test_id()
    if curr_id == 0 :
        return False

    with current_test( curr_id, False ) :
        obj = json.loads( memcached.get( derive_test_results_key(), "{}" ) )

    if not obj.has_key( "artifacts" ) :
        obj["artifacts"] = []
    if not obj.has_key( "log" ) :
        obj["log"] = ""
    if not obj.has_key( "status" ) :
        obj["status"] = "unknown"
    if not obj.has_key( "name" ) :
        obj["name"] = tests_config.all_tests()[curr_id].__doc__
    if not obj.has_key( "test_id" ) :
        from testing_runtime import tests_config
        obj["test_id"] = curr_id

    return obj