예제 #1
0
    def post(self):
        args = self.post_parser.parse_args()
        clientid = -1
        try:
            clientid = clientserializer.loads(args['client_id'])
        except BadSignature:
            abort(401)

        results = args['results']

        client = Client.query.get(clientid)
        if not client:
            abort(401)

        response = {'results': []}

        for test in results:

            realid = testserializer.loads(test['id'])
            output = test['output']
            testdb = Test.query.get(realid)

            if not testdb:
                abort(404)

            result = {
                'test_id': test['id'],
                'result_ok': True,
                'error': ''
            }

            try:
                testdb.validate(output)
            except MissingOutput:
                result['result_ok'] = False
                result['error'] = 'Missing output.'
            except ExcessiveOutput:
                result['result_ok'] = False
                result['error'] = 'Excessive output.'
            except WrongOutput:
                result['result_ok'] = False
                result['error'] = 'Wrong output.'

            response['results'].append(result)
            log = RequestLog(realid, clientid, result['result_ok'],
                             result['error'])
            db.session.add(log)

        db.session.commit()

        app.logger.info(
            """
[{timestamp}] Client {cid} validated test results.
            """.format(
                timestamp=datetime.now().isoformat(sep=" "),
                cid=args['client_id']
            )
        )

        return response
예제 #2
0
    def post(self):
        args = self.post_parser.parse_args()
        clientid = -1
        try:
            clientid = clientserializer.loads(args['client_id'])
        except BadSignature:
            abort(401)

        results = args['results']

        client = Client.query.get(clientid)
        if not client:
            abort(401)

        response = {'results': []}
        
        for test in results:
            
            realid = testserializer.loads(test['id'])
            output = test['output']
            testdb = Test.query.get(realid)

            if not testdb:
                abort(404)

            result = {
                'test_id': test['id'],
                'result_ok': True,
                'error': ''
            }

            try:
                testdb.validate(output)
            except MissingOutput:
                result['result_ok'] = False
                result['error'] = 'Missing output.'
            except ExcessiveOutput:
                result['result_ok'] = False
                result['error'] = 'Excessive output.'
            except WrongOutput:
                result['result_ok'] = False
                result['error'] = 'Wrong output.'

            response['results'].append(result)
            log = RequestLog(realid, clientid, result['result_ok'],
                             result['error'])
            db.session.add(log)

        db.session.commit()

        app.logger.info(
            """
[{timestamp}] Client {cid} validated test results.
            """.format(
                timestamp=datetime.now().isoformat(sep=" "),
                cid=args['client_id']
            )
        )

        return response
예제 #3
0
from moulinette import testserializer
from moulinette.homework.models import *

id = input()

test = Test.query.get(testserializer.loads(id))
db.session.delete(test)
db.session.commit()