Adding positive score constraint

This commit is contained in:
Denis-Cosmin Nutiu 2017-04-22 13:56:34 +03:00
parent 304435162b
commit 5acf92155d
2 changed files with 11 additions and 4 deletions

View file

@ -32,7 +32,7 @@ class Result(db.Model):
log = db.Column(db.String(10000))
score = db.Column(db.Integer)
def __init__(self, name="Anonymous", gpu=None, cpu=None, log=None, score=0):
def __init__(self, name="Anonymous", gpu=None, cpu=None, log=None, score=1):
self.name = name
self.gpu = gpu
self.cpu = cpu
@ -41,3 +41,8 @@ class Result(db.Model):
def __repr__(self):
return self.gpu
__table_args__ = (
db.CheckConstraint(score > 0, name="positive_score_constraint"),
{}
)

View file

@ -54,10 +54,12 @@ def result_post():
cpu = content['cpu']
log = content['log']
score = int(content['score'])
if score <= 0:
error = "Score must be positive!"
except KeyError: # Json doesn't contain the keys we need.
error = "invalid json keys: gpu, cpu, log, score name"
error = "Invalid json keys: gpu, cpu, log, score name!"
except TypeError: # The types from the json object are not correct.
error = "invalid json object"
error = "Invalid json object!"
if error:
return flask.jsonify({'error': error, 'success': False}), 400
@ -69,7 +71,7 @@ def result_post():
location = "/result/{}".format(entry.id)
return flask.jsonify({'success': True, 'location': location}), 201, {'location': location}
return flask.jsonify({'success': True}), 201, {'location': location}
@utilities.cache.cached(timeout=60*5)