From 5a5af4c538b49aadc4f18ee067faeaab18f76b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Nut=CC=A6iu?= Date: Wed, 12 Apr 2017 23:39:39 +0300 Subject: [PATCH] Creating test database --- src/application.py | 23 ++++++++++++++++++++++- src/models/result.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/models/result.py diff --git a/src/application.py b/src/application.py index 26fa965..7ce5d66 100644 --- a/src/application.py +++ b/src/application.py @@ -15,10 +15,31 @@ You should have received a copy of the GNU General Public License along with scoreboard-benchmark . If not, see . """ +import src.models.result import flask +import os +# General Configurations app = flask.Flask(__name__) +basedir = os.path.abspath(os.path.dirname(__file__)) + +# Database Configuration +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'database.sqlite') +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True +src.models.result.db.init_app(app) + + +@app.before_first_request +def create_test_databases(): + src.models.result.db.drop_all() + src.models.result.db.create_all() + b1 = src.models.result.Result(text="asda", score=100) + b2 = src.models.result.Result(text="i7 flips flops", score=400) + src.models.result.db.session.add(b1) + src.models.result.db.session.add(b2) + src.models.result.db.session.commit() @app.route("/upload") @@ -36,4 +57,4 @@ def page_not_found_error(e): return flask.render_template("404.html"), 404 if __name__ == "__main__": - app.run("") \ No newline at end of file + app.run("0.0.0.0") diff --git a/src/models/result.py b/src/models/result.py new file mode 100644 index 0000000..a03fbe5 --- /dev/null +++ b/src/models/result.py @@ -0,0 +1,33 @@ +""" + Author: Denis Nutiu + This file is part of scoreboard-benchmark. + + scoreboard-benchmark is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + scoreboard-benchmark is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with scoreboard-benchmark . If not, see . +""" +from flask_sqlalchemy import SQLAlchemy + +db = SQLAlchemy() + + +class Result(db.Model): + """ + The result model will store benchmark results. + """ + __tablename__ = 'results' + id = db.Column(db.Integer, primary_key=True) + text = db.Column(db.String(512)) + score = db.Column(db.Integer) + + def __repr__(self): + return self.text