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 test_start_as_anonymous(db): client = app.test_client() anon_home = client.get('/').data assert SUBMIT_BTN not in anon_home
def test_logout(db): home = login_helper('admin', 'admin').data assert SUBMIT_BTN in home client = app.test_client() response = client.get('/logout') assert SUBMIT_BTN not in response.data assert response.status_code == 302
def test_update_entry(db): entry_data = { u'title': u'Hello', u'text': u'This is a post', } with app.test_client() as c: actual = c.post( '/add', data=entry_data, follow_redirects=True ).data assert 'No entries here so far' not in actual for expected in entry_data.values(): assert expected in actual """ CMGTODO: How to test the edit? edit_data = { u'title': u"Hello Again", u'text': u"This is an edited post", } actual = c.post( '/submit/1', data=edit_data, follow_redirects=True ).data for expected in edit_data.values(): assert expected in actual """ return
def login_helper(username, password): login_data = { 'username': username, 'password': password } client = app.test_client() return client.post( '/login', data=login_data, follow_redirects=True)
def click_edit(step): login_data = { 'username': '******', 'password': '******' } with app.test_client() as c: c.post('/login', data=login_data) # Logically this should be in the response = c.get('/edit/1') # login step, but it doesn't persist world.page = response.data
def use_update_form(step, string1): entry_data = { 'title': string1, 'text': string1 } world.page = app.test_client().post( '/update/1', data=entry_data, follow_redirects=True ).data
def login_helper(username, password): login_data = { 'username': username, 'password': password } client = app.test_client() return client.post( '/login', data=login_data, follow_redirects=True )
def test_listing(with_entry): expected = with_entry actual = app.test_client().get('/').data for value in expected: assert value in actual
def login(step): login_data = { 'username': '******', 'password': '******' } client = app.test_client() response = client.post( '/login', data=login_data, follow_redirects=True ) world.page = response.data
def test_add_entries(db): entry_data = { u'title': u'Hello', u'text': u'This is a post', } actual = app.test_client().post( '/add', data=entry_data, follow_redirects=True).data assert 'No entries here so far' not in actual for expected in entry_data.values(): assert expected in actual
def test_add_entries(db): entry_data = { u'title': u'Hello', u'text': u'This is a post', } actual = app.test_client().post('/add', data=entry_data, follow_redirects=True).data assert 'No entries here so far' not in actual for expected in entry_data.values(): assert expected in actual
def test_empty_listing(db): # "app.test_client() returns a mock HTTP client, # like a web browser for development." # "Because this test actually creates a request, we don't need to use # the req_context fixture. Having an initialized database is enough" # "The data attribute of the response returned by client.get() # holds the full rendered HTML of our page." actual = app.test_client().get('/').data expected = 'No entries here so far' assert expected in actual
def test_add_entries(db): entry_data = { u'title': u'Hello', u'text': u'This is a post', } with app.test_client() as c: with c.session_transaction() as sess: sess['logged_in'] = True actual = c.post('/add', data=entry_data, follow_redirects=True).data assert 'No entries here so far' not in actual for expected in entry_data.values(): assert expected in actual
def test_add_entries(db): entry_data = { u'title': u'Hello', u'text': u'This is a post', } with app.test_client() as c: with c.session_transaction() as sess: sess['logged_in'] = True actual = c.post( '/add', data=entry_data, follow_redirects=True).data assert 'No entries here so far' not in actual for expected in entry_data.values(): assert expected in actual
def test_edit_entries(req_context): entry_data = { u'title': u'Hello2', u'text': u'This is a post2', } actual = '' with app.test_client() as c: with c.session_transaction() as sess: sess['logged_in'] = True actual = c.post( '/edit/4?id=4', data=entry_data, follow_redirects=True).data assert actual != '' assert 'No entries here so far' not in actual for expected in entry_data.values(): assert expected in actual
def test_add_entries(db): entry_data = { u'title': u'Hello', u'text': u'This is a post', } # "The post method of the Flask test_client sends an HTTP POST # request to the provided URL." actual = app.test_client().post( '/add', data=entry_data, follow_redirects=True ).data assert 'No entries here so far' not in actual for expected in entry_data.values(): # "assert that the line in entry data is also in the actual data" assert expected in actual
def anonymous_user(step): with app.test_client() as client: lettuce.world.client = client
def logged_in_user(step): with app.test_client() as client: with client.session_transaction() as sess: sess['logged_in'] = True lettuce.world.client = client
def test_empty_listing(db): actual = app.test_client().get('/').data expected = 'No entries here so far' assert expected in actual
def test_empty_listing(db): # returns the html of the page as a string actual = app.test_client().get('/').data expected = 'No entries here so far' # checks to see if expected is a substring of actual assert expected in actual
def anonymous_user(step): with app.test_client() as client: with client.session_transaction() as sess: sess['logged_in'] = False lettuce.world.client = client
def logout(step): client = app.test_client() response = client.get('/') world.page = response.data
def post_contains(step): client = app.test_client() response = client.get('/') print response.data assert step.multiline in response.data