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 test_add(dbtransaction, app): """Test that add view creates a new Entry in database.""" results = DBSession.query(Entry).filter(Entry.title == 'TEST' and Entry.text == 'TEST') assert results.count() == 0 params = {'title': 'TEST', 'text': 'TEST'} app.post('/add', params=params, status='3*') results = DBSession.query(Entry).filter(Entry.title == 'TEST' and Entry.text == 'TEST') assert results.count() == 1
def new_entry(request): """Return a fresh new Entry and flush to the database.""" entry = Entry(title="testblogpost", text="aaa") DBSession.add(entry) DBSession.flush() def teardown(): DBSession.query(Entry).filter_by(id=entry.id).delete() request.addfinalizer(teardown) return entry
def sqlengine(request, test_database_url): """Return sql engine.""" 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 new_entry(request): """Return a fresh new Entry and flush to the database.""" new_entry = Entry(title="testblogpost", text="aaa") DBSession.add(new_entry) DBSession.flush() def teardown(): DBSession.query(Entry).filter(Entry.id == new_entry.id).delete() DBSession.flush() request.addfinalizer(teardown) return new_entry
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 dbtransaction(request, sqlengine): """Create database transaction connection.""" connection = sqlengine.connect() transaction = connection.begin() DBSession.configure(bind=connection, expire_on_commit=False) def teardown(): transaction.rollback() connection.close() DBSession.remove() request.addfinalizer(teardown) return connection
def test_add(dbtransaction, app): """Test that add view creates a new Entry in database.""" results = DBSession.query(Entry).filter( Entry.title == 'TEST' and Entry.text == 'TEST') assert results.count() == 0 params = { 'title': 'TEST', 'text': 'TEST' } app.post('/add', params=params, status='3*') results = DBSession.query(Entry).filter( Entry.title == 'TEST' and Entry.text == 'TEST') assert results.count() == 1
def test_all_entry_models(response_list, dbtransaction): """Test that the full list can be instantiated and added to the DB.""" from journalapp.scripts.get_crisewing_api import ( entries_from_list, add_entries_to_db) new_entries = entries_from_list(response_list) assert add_entries_to_db(new_entries, DBSession) == 18 assert DBSession.query(Entry).count() == 18
def test_edit(dbtransaction, app, new_entry): """Test that edit view can edit an exiting Entry.""" new_title = new_entry.title + 'TEST' new_text = new_entry.text + 'TEST' params = {'title': new_title, 'text': new_text} app.post('/edit/{}'.format(new_entry.id), params=params, status='3*') results = DBSession.query(Entry).filter(Entry.title == new_title and Entry.text == new_text) assert results.count() == 1
def test_edit(dbtransaction, app, new_entry): """Test that edit view can edit an exiting Entry.""" new_title = new_entry.title + 'TEST' new_text = new_entry.text + 'TEST' params = { 'title': new_title, 'text': new_text } app.post('/edit/{}'.format(new_entry.id), params=params, status='3*') results = DBSession.query(Entry).filter( Entry.title == new_title and Entry.text == new_text) assert results.count() == 1
def test_new_view_post(dbtransaction, dummy_post_request): """Test that the new view returns a dict containing the proper form.""" from journalapp.views import new dummy_post_request.path = '/new' dummy_post_request.method = "POST" dummy_post_request.POST = MultiDict([('title', "test post title"), ('text', "test post text")]) response = new(dummy_post_request) assert response.status_code == 302 and response.title == 'Found' created_entry = DBSession.query(Entry).filter( Entry.title == "test post title").first() assert created_entry is not None expected_url = dummy_post_request.route_url('detail', pkey=created_entry.id) assert response.location.endswith(expected_url)
def test_title(dbtransaction): new_model = Entry(title="Blog Post", text="my entry goes here") DBSession.add(new_model) DBSession.flush() assert DBSession.query(Entry).order_by( desc(Entry.created))[0].title == "Blog Post"
def teardown(): transaction.rollback() connection.close() DBSession.remove()
def test_db_clear(dbtransaction): """Make sure that tests are starting from a blank database each time.""" assert DBSession.query(Entry).count() == 0
def new_entry(request): """Return a fresh new Entry and flush to the database.""" entry = Entry(title="Test Title", text="Test Text for an entry.") DBSession.add(entry) DBSession.flush() return entry
def teardown(): DBSession.query(Entry).filter(Entry.title == 'TESTadd').delete()
def teardown(): DBSession.query(Entry).filter(Entry.id == new_entry.id).delete() DBSession.flush()
def teardown(): DBSession.query(Entry).filter_by(id=entry.id).delete()
def test_text(dbtransaction): new_model = Entry(title="Blog Post", text="my entry goes here") DBSession.add(new_model) DBSession.flush() assert DBSession.query(Entry).all()[0].text == "my entry goes here"
def test_create_entry(dbtransaction): new_model = Entry(title="Blog Post", text="my entry goes here") assert new_model.id is None DBSession.add(new_model) DBSession.flush() assert new_model.id is not None
def create_entry(request): entry = Entry(title="Test Title", text="Test Text") DBSession.add(entry) DBSession.flush() return entry