def test_create_entry(dbtransaction): """Test for a change of state of the model.""" new_model = Entry(title="jill", text='jello') assert new_model.id is None DBSession.add(new_model) DBSession.flush() assert new_model.id is not None
def test_home_view_sort(dbtransaction, new_model): """Test home view sort functionality via attribute.""" new_model = Entry(title="two", text='twotext') DBSession.add(new_model) DBSession.flush() test_request = DummyRequest() dic = home_view(test_request) assert dic['entry_list'].all()[1].title == 'jill'
def sqlengine(request): engine = create_engine(TEST_DATABASE_URL) DBSession.configure(bind=engine) Base.metadata.create_all(engine) def teardown(): Base.metadata.drop_all(engine) request.addfinalizer(teardown) return engine
def dbtransaction(request, sqlengine): connection = sqlengine.connect() transaction = connection.begin() DBSession.configure(bind=connection) def teardown(): transaction.rollback() connection.close() DBSession.remove() request.addfinalizer(teardown) return connection
def test_new_post(dbtransaction, authenticated_app): """Test that a new post is created.""" db_rows = DBSession.query(Entry).filter( Entry.title == 'Testing' and Entry.text == 'Testing') assert db_rows.count() == 0 params = { 'title': 'Testing', 'text': 'Testing' } authenticated_app.post('/new', params=params, status='3*') db_rows = DBSession.query(Entry).filter( Entry.title == 'Testing' and Entry.text == 'Testing') assert db_rows.count() == 1
def main(global_config, **settings): config = Configurator() engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) simple_route(config, 'index', '/', index) # The socketio view configuration config.add_route('socket_io', 'socket.io/*remaining') config.add_static_view('static', 'static', cache_max_age=3600) config.scan('testapp.views') app = config.make_wsgi_app() return app
def test_edit_entry(dbtransaction, authenticated_app, new_model): """Test that a post can be edited.""" params = { 'title': 'T' + new_model.title, 'text': 'T' + new_model.text } authenticated_app.post('/edit/{}'.format(new_model.id), params=params, status='3*') db_rows = DBSession.query(Entry).filter( Entry.title == 'T' + new_model.title and Entry.text == 'T' + new_model.text) assert db_rows.count() == 1
def test_new_post_minimum_text_length(dbtransaction, app): """Test a new post can't be created without min characters in text.""" db_rows = DBSession.query(Entry).filter( Entry.title == 'Testing2' and Entry.text == 'Test') assert db_rows.count() == 0 params = { 'title': 'Testing2', 'text': 'Test' } with pytest.raises(AppError): app.post('/new', params=params, status='3*')
def test_new_post_over_max_title_length(dbtransaction, app): """Test that a new post adheres to max title length.""" mock_title = [] for i in range(130): mock_title.append('a') mock_title = "".join(mock_title) db_rows = DBSession.query(Entry).filter( Entry.title == mock_title and Entry.text == 'Testing') assert db_rows.count() == 0 params = { 'title': mock_title, 'text': 'Testing' } with pytest.raises(AppError): app.post('/new', params=params, status='3*')
def new_model(request, sqlengine, dbtransaction): """Create an entry to testing db.""" connection = sqlengine.connect() transaction = connection.begin() DBSession.configure(bind=connection) new_model = Entry(title="jill", text='jello') DBSession.add(new_model) DBSession.flush() def teardown(): transaction.rollback() connection.close() DBSession.remove() request.addfinalizer(teardown) return new_model
def teardown(): transaction.rollback() connection.close() DBSession.remove()