def with_entry(db, request):

    from journal import write_entry

    expected = (u'Test Title)', u'Test Text')

    with app.test_request_context('/'):

        write_entry(*expected)

        get_database_connection().commit()

    def cleanup():

        # NOTE: "You use a test_request_context in both setup and
        # teardown to ensure that flask.g exists."
        with app.test_request_context('/'):
            con = get_database_connection()
            cur = con.cursor()
            cur.execute("DELETE FROM entries")
            con.commit()

    # Also note that allowing the two "with" blocks to close commits the
    # transactions for each test context.

    request.addfinalizer(cleanup)

    return expected
Beispiel #2
0
def write_post(step):
    from journal import write_entry
    expected = (u'Test Title', step.multiline)

    with app.test_request_context('/'):
        write_entry(*expected)
        # manually commit transaction here to avoid rollback due to
        # handled exceptions
        get_database_connection().commit()
Beispiel #3
0
def add_entry(step):

    from journal import write_entry
    expected = ('Test Title', 'Test Text')

    with app.test_request_context('/'):
        write_entry(*expected)
        # manually commit transaction here to avoid rollback due to
        # handled exceptions
        get_database_connection().commit()

    world.expected = expected
def test_app():
    """configure our app for use in testing"""
    app.config['DATABASE'] = TEST_DSN
    app.config['TESTING'] = True
    init_db()

    with app.test_request_context('/'):
        app.test_client().post(
            '/add', data=lettuce.world.entry_data, follow_redirects=True)
        # manually commit transaction here to avoid rollback
        # due to handled Exception
        get_database_connection().commit()
Beispiel #5
0
def test_app():
    """configure our app for use in testing"""
    app.config['DATABASE'] = TEST_DSN
    app.config['TESTING'] = True
    init_db()

    with app.test_request_context('/'):
        app.test_client().post('/add',
                               data=lettuce.world.entry_data,
                               follow_redirects=True)
        # manually commit transaction here to avoid rollback
        # due to handled Exception
        get_database_connection().commit()
 def cleanup():
     with app.test_request_context('/'):
         con = get_database_connection()
         cur = con.cursor()
         cur.execute("DELETE FROM entries")
         # and here as well
         con.commit()
 def cleanup():
     with app.test_request_context('/'):
         con = get_database_connection()
         cur = con.cursor()
         cur.execute("DELETE FROM entries")
         # and here as well
         con.commit()
def with_entry(db, request):
    from journal import write_entry
    expected = (u'Test Title', u'Test Text')
    with app.test_request_context('/'):
        write_entry(*expected)
        get_database_connection().commit()

    def cleanup():
        with app.test_request_context('/'):
            con = get_database_connection()
            cur = con.cursor()
            cur.execute("DELETE FROM entries")
            con.commit()
    request.addfinalizer(cleanup)

    return expected
def with_entry(db, request):
    from journal import write_entry
    expected = (u'Test Title', u'Test Text')
    with app.test_request_context('/'):
        write_entry(*expected)
        # commit transaction to avoid rollback if exception raised
        get_database_connection().commit()

    def cleanup():
        with app.test_request_context('/'):
            con = get_database_connection()
            cur = con.cursor()
            cur.execute("DELETE FROM entries")
            # and here as well
            con.commit()
    request.addfinalizer(cleanup)
    return expected
def with_entry(db, request):
    from journal import write_entry
    expected = (u'Test Title', u'Test Text')
    with app.test_request_context('/'):
        write_entry(*expected)
        # manually commit transaction here to avoid rollback
        # due to handled Exception
        get_database_connection().commit()

    def cleanup():
        with app.test_request_context('/'):
            con = get_database_connection()
            cur = con.cursor()
            cur.execute("DELETE FROM entries")
            # and here as well
            con.commit()
    request.addfinalizer(cleanup)
    return expected
Beispiel #11
0
    def cleanup():

        # NOTE: "You use a test_request_context in both setup and
        # teardown to ensure that flask.g exists."
        with app.test_request_context('/'):
            con = get_database_connection()
            cur = con.cursor()
            cur.execute("DELETE FROM entries")
            con.commit()
def teardown(total):
    with app.test_request_context('/'):
        con = get_database_connection()
        cur = con.cursor()
        cur.execute("DELETE FROM entries")
        # and here as well
        con.commit()
    with closing(connect_db()) as db:
        db.cursor().execute("DROP TABLE entries")
        db.commit()
Beispiel #13
0
def teardown(total):
    with app.test_request_context('/'):
        con = get_database_connection()
        cur = con.cursor()
        cur.execute("DELETE FROM entries")
        # and here as well
        con.commit()
    with closing(connect_db()) as db:
        db.cursor().execute("DROP TABLE entries")
        db.commit()
Beispiel #14
0
def run_independent_query(query, params=[]):

    # This function simply formalizes what I've been doing all along
    # to make DB queries inside Python.

    con = get_database_connection()
    cur = con.cursor()

    cur.execute(query, params)

    return cur.fetchall()
Beispiel #15
0
def req_context(db):

    ''' Run tests within a test request context so that 'g' is present. '''

    # Wait... flask.g would not be available if we didn't make this
    # "request context" function?

    with app.test_request_context('/'):

        # First, yield nothing.
        # Wat.
        yield

        con = get_database_connection()
        con.rollback()
def req_context(db):
	with app.test_request_context('/'):
		yield
		con = get_database_connection()
		con.rollback()
def run_independent_query(query, params=[]):
    con = get_database_connection()
    cur = con.cursor()
    cur.execute(query, params)
    return cur.fetchall()
def req_context(db):
    """run tests within a test request context so that 'g' is present"""
    with app.test_request_context('/'):
        yield
        con = get_database_connection()
        con.rollback()
def run_independent_query(query, params=[]):
    con = get_database_connection()
    cur = con.cursor()
    cur.execute(query, params)
    return cur.fetchall()
def req_context(db):
    """run tests within a test request context so that 'g' is present"""
    with app.test_request_context('/'):
        yield
        con = get_database_connection()
        con.rollback()