Example #1
0
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
 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()
Example #3
0
 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()
Example #4
0
def redirected_home(step):
    with app.test_request_context('/'):
        home_url = url_for('show_entries')
    # assert that we have been redirected to the home page
    assert lettuce.world.response.status_code in [301, 302]
    assert lettuce.world.response.location == 'http://localhost' + home_url
    # now, fetch the homepage so we can finish this off.
    lettuce.world.response = lettuce.world.client.get(home_url)
Example #5
0
def redirected_home(step):
    with app.test_request_context('/'):
        home_url = url_for('show_entries')
    # assert that we have been redirected to the home page
    assert lettuce.world.response.status_code in [301, 302]
    assert lettuce.world.response.location == 'http://localhost' + home_url
    # now, fetch the homepage so we can finish this off.
    lettuce.world.response = lettuce.world.client.get(home_url)
Example #6
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()
Example #7
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()
Example #8
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()
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()
Example #10
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()
Example #12
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()
Example #13
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()
Example #14
0
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
Example #17
0
def click_on_edit_button(step):
    with app.test_request_context('/'):
        home_url = url_for('show_entries')
    edit_url = 'http://localhost' + home_url + "/edit/1"
    lettuce.world.response = lettuce.world.client.get(edit_url)
Example #18
0
def append_edit_to_url(step):
    with app.test_request_context('/'):
        home_url = url_for('show_entries')
    lettuce.world.response = lettuce.world.client.get(home_url + "/edit/1")
Example #19
0
def anonymous_request_edit_page(step):
    with app.test_request_context('/'):
        edit_url = url_for('show_entries') + "edit/1"
    lettuce.world.response = lettuce.world.client.get(edit_url)
Example #20
0
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()
Example #21
0
def click_on_edit_button(step):
    with app.test_request_context('/'):
        home_url = url_for('show_entries')
    edit_url = 'http://localhost' + home_url + "/edit/1"
    lettuce.world.response = lettuce.world.client.get(edit_url)
Example #22
0
def view_the_homepage(step):
    with app.test_request_context('/'):
        home_url = url_for('show_entries')
    lettuce.world.response = lettuce.world.client.get(home_url)
Example #23
0
def append_edit_to_url(step):
    with app.test_request_context('/'):
        home_url = url_for('show_entries')
    lettuce.world.response = lettuce.world.client.get(home_url + "/edit/1")
Example #24
0
def view_the_homepage(step):
    with app.test_request_context('/'):
        home_url = url_for('show_entries')
    lettuce.world.response = lettuce.world.client.get(home_url)
Example #25
0
def create_entry(step):
    with app.test_request_context('/'):
        entry = ("My Title", "My Text")
        write_entry(*entry)
Example #26
0
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 req_context(db):
	with app.test_request_context('/'):
		yield
		con = get_database_connection()
		con.rollback()
Example #28
0
def anonymous_request_edit_page(step):
    with app.test_request_context('/'):
        edit_url = url_for('show_entries') + "edit/1"
    lettuce.world.response = lettuce.world.client.get(edit_url)