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()
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)
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 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()
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 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()
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 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 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
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)
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")
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)
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 view_the_homepage(step): with app.test_request_context('/'): home_url = url_for('show_entries') lettuce.world.response = lettuce.world.client.get(home_url)
def create_entry(step): with app.test_request_context('/'): entry = ("My Title", "My Text") write_entry(*entry)
def req_context(db): with app.test_request_context('/'): yield con = get_database_connection() con.rollback()