def test_app_open_connection_connection_module3():
    assert 'g' in dir(app), 'Have you imported the `g` class from `flask`?'
    assert 'app' in dir(app), 'Have you created an instance of the `Flask` class called `app`?'
    assert 'open_connection' in dir(app), 'Have you defined a function named `open_connection`.'
    with app.app.app_context():
        app.open_connection()
        assert hasattr(app.g, '_connection'), 'Did you assign the `_connection` attribute to `g`?'
        _, _, db_name = app.g._connection.execute('PRAGMA database_list').fetchone()
        assert os.path.join(os.getcwd(), 'db', 'jobs.sqlite') == db_name, 'Did you pass the `connect` function the `PATH` constant?'
def test_app_open_connection_row_factory_module3():
    assert 'g' in dir(app), 'Have you imported the `g` class from `flask`?'
    assert 'app' in dir(app), 'Have you created an instance of the `Flask` class called `app`?'
    assert 'open_connection' in dir(app), 'Have you defined a function named `open_connection`.'
    with app.app.app_context():
        db = app.open_connection()
        assert isinstance(db, app.sqlite3.Connection), 'Are you returning the database connection?'
        assert id(db.row_factory) == id(
            app.sqlite3.Row), 'Have you set the database `row_factory` to the sqlite3.Row class?'
Пример #3
0
def test_app_open_connection_connection_module3():
    g_import = "g" in dir(app)
    assert g_import, "Have you imported the `g` class from `flask`?"

    flask_app = "app" in dir(app)
    assert flask_app, "Have you created an instance of the `Flask` class called `app`?"

    open_connection = "open_connection" in dir(app)
    assert open_connection, "Have you defined a function named `open_connection`?"

    with app.app.app_context():
        app.open_connection()

        connection_exists = hasattr(app.g, "_connection")
        assert connection_exists, "Did you assign the `_connection` attribute to `g`?"

        _, _, db_name = app.g._connection.execute("PRAGMA database_list").fetchone()
        db_exists = os.path.join(os.getcwd(), "db", "jobs.sqlite") == db_name
        assert db_exists, "Did you pass the `connect` function the `PATH` constant?"
def test_app_open_connection_row_factory_module3():
    g_import = "g" in dir(app)
    assert g_import, "Have you imported the `g` class from `flask`?"

    flask_app = "app" in dir(app)
    assert flask_app, "Have you created an instance of the `Flask` class called `app`?"

    open_connection = "open_connection" in dir(app)
    assert open_connection, "Have you defined a function named `open_connection`?"

    with app.app.app_context():
        db = app.open_connection()
        return_connection = isinstance(db, app.sqlite3.Connection)
        assert return_connection, "Are you returning the database connection?"

        row_factory = id(db.row_factory) == id(app.sqlite3.Row)
        assert (
            row_factory
        ), "Have you set the database `row_factory` to the sqlite3.Row class?"