コード例 #1
0
def test_get_close_db(app):
    with app.app_context():
        db = get_db()
        assert db is get_db()

    with pytest.raises(sqlite3.ProgrammingError) as e:
        db.execute("SELECT 1")

    assert "closed" in str(e.value)
コード例 #2
0
    def get_post(id, check_author=True):
        """Get a post and its author by id.

        Checks that the id exists and optionally that the current user is
        the author.

        :param id: id of post to get
        :param check_author: require the current user to be the author
        :return: the post with author information
        :raise 404: if a post with the given id doesn't exist
        :raise 403: if the current user isn't the author
        """
        results = (
            get_db()
            .execute(
                "SELECT p.id, title, body, created, author_id, username"
                " FROM post p JOIN user u ON p.author_id = u.id"
                " WHERE p.id = ?",
                (id,),
            )
            .fetchone()
        )
        # verify if the query returned no results
        if results is None:
            abort(404, "Post id {id} doesn't exist.")
            
        return results
コード例 #3
0
def app():
    """Create and configure a new app instance for each test."""
    # create a temporary file to isolate the database for each test
    db_fd, db_path = tempfile.mkstemp()
    # create the app with common test config
    app = create_app({"TESTING": True, "DATABASE": db_path})

    # create the database and load test data
    with app.app_context():
        init_db()
        get_db().executescript(_data_sql)

    yield app

    # close and remove the temporary database
    os.close(db_fd)
    os.unlink(db_path)
コード例 #4
0
def test_update(client, auth, app):
    auth.login()
    assert client.get("/1/update").status_code == 200
    client.post("/1/update", data={"title": "updated", "body": ""})
    with app.app_context():
        db = get_db()
        post = db.execute("SELECT * FROM post WHERE id = 1").fetchone()
        assert post["title"] == "updated"
コード例 #5
0
def test_create(client, auth, app):
    auth.login()
    assert client.get("/create").status_code == 200
    client.post("/create", data={"title": "created", "body": ""})a
    with app.app_context():
        db = get_db()
        count = db.execute("SELECT COUNT(id) FROM post").fetchone()[0]
        assert count == 2
コード例 #6
0
def test_delete(client, auth, app):
    auth.login()
    response = client.post("/1/delete")
    assert response.headers["Location"] == "http://localhost/"

    with app.app_context():
        db = get_db()
        post = db.execute("SELECT * FROM post WHERE id = 1").fetchone()
        assert post is None
コード例 #7
0
    def delete(id):
        """Delete a post.

        Ensures that the post exists and that the logged in user is the
        author of the post.
        """
        get_post(id)
        db = get_db()
        db.execute("DELETE FROM post WHERE id = ?", (id,))
        db.commit()
        return redirect(url_for("visualizer.index"))
コード例 #8
0
def test_register(client, app):
    # test that viewing the page renders without template errors
    assert client.get("/auth/register").status_code == 200

    # test that successful registration redirects to the login page
    response = client.post("/auth/register",
                           data={
                               "username": "******",
                               "password": "******"
                           })
    assert "http://localhost/auth/login" == response.headers["Location"]

    # test that the user was inserted into the database
    with app.app_context():
        assert (get_db().execute(
            "select * from user where username = '******'").fetchone() is not None)
コード例 #9
0
def index():
    #TODO: Lee config y envía como param el número de divs y un arreglo con los campos de configuración de cada div
    """Show the mse plot for the last training process, also the last validation plot and a list of validation stats."""
    db = get_db()
    training_progress = db.execute(
        "SELECT *"
        " FROM training_progress t JOIN processes p ON t.process_id = p.id"
        " ORDER BY created DESC").fetchall()
    validation_plots = db.execute(
        "SELECT *"
        " FROM validation_plots t JOIN processes p ON t.process_id = p.id"
        " ORDER BY created DESC").fetchall()
    validation_stats = db.execute(
        "SELECT *"
        " FROM validation_stats t JOIN processes p ON t.process_id = p.id"
        " ORDER BY created DESC").fetchall()

    return render_template("index.html", training_progress=training_progress)
コード例 #10
0
 def load_data(self, p_config, process_id):
     """load the data for the mse plot for the last training process, also the last validation plot and a list of validation stats."""
     p_config = current_app.config['P_CONFIG']
     db = get_db()
     self.input_ds = []
     for table in p_config['input_plugin_config']['tables']:
         c = 0
         fields = ""
         for f in table['fields']:
             if c > 0:
                 fields = fields + ","
             fields = fields + f
             c = c + 1
         query = db.execute("SELECT " + fields + " FROM " +
                            table['table_name'] +
                            " t JOIN process p ON t.process_id = " +
                            str(process_id) +
                            " ORDER BY created DESC").fetchall()
         self.input_ds.append(query)
     return self.input_ds
コード例 #11
0
def index():
    # TODO: Lee config
    # TODO: Carga input plugin y genra variable p_data que se pasa al core plugin para que lo pase a su template
    # TODO: envía como param el número de divs y un arreglo con los campos de configuración de cada div
    """Show the mse plot for the last training process, also the last validation plot and a list of validation stats."""
    db = get_db()
    training_progress = db.execute(
        "SELECT *"
        " FROM training_progress t JOIN process p ON t.process_id = p.id"
        " ORDER BY created DESC").fetchall()
    validation_plots = db.execute(
        "SELECT *"
        " FROM validation_plots t JOIN process p ON t.process_id = p.id"
        " ORDER BY created DESC").fetchall()
    validation_stats = db.execute(
        "SELECT *"
        " FROM validation_stats t JOIN process p ON t.process_id = p.id"
        " ORDER BY created DESC").fetchall()

    return render_template("visualizer/index.html", p_data=p_data)
コード例 #12
0
    def create():
        """Create a new post for the current user."""
        if request.method == "POST":
            title = request.form["title"]
            body = request.form["body"]
            error = None

            if not title:
                error = "Title is required."

            if error is not None:
                flash(error)
            else:
                db = get_db()
                db.execute(
                    "INSERT INTO post (title, body, author_id) VALUES (?, ?, ?)",
                    (title, body, g.user["id"]),
                )
                db.commit()
                return redirect(url_for("visualizer.index"))

        return render_template("visualizer/create.html")
コード例 #13
0
def update(id):
    """Update a post if the current user is the author."""
    post = get_post(id)

    if request.method == "POST":
        title = request.form["title"]
        body = request.form["body"]
        error = None

        if not title:
            error = "Title is required."

        if error is not None:
            flash(error)
        else:
            db = get_db()
            db.execute("UPDATE post SET title = ?, body = ? WHERE id = ?",
                       (title, body, id))
            db.commit()
            return redirect(url_for("visualizer.index"))

    return render_template("visualizer/update.html", post=post)