def test_add(authenticated_app): results = DBSession.query(Entry).filter( Entry.title == 'title' and Entry.text == 'text') assert results.count() == 0 entry_dict = {'title': 'title', 'text': 'text'} authenticated_app.post('/write', params=entry_dict, status='3*') results = DBSession.query(Entry).filter( Entry.title == 'title' and Entry.text == 'text') assert results.count() == 1
def test_delete_entry(loaded_db_item, authorized_app): from learning_journal.models import Entry, DBSession check_db = DBSession.query(Entry).filter( Entry.title == 'jill').first() assert check_db authorized_app.get('/delete_entry/{}'.format(loaded_db_item.id)) check_db = DBSession.query(Entry).filter( Entry.title == 'jill').first() assert not check_db
def test_edit_entry_view_functional(loaded_db_item, authenticated_app): """Test if the db updates upon request.""" from learning_journal.models import Entry, DBSession authenticated_app.post('/edit_entry/{}'.format(loaded_db_item.id), {'title': 'new title', 'text': 'new text'}) new = DBSession.query(Entry).filter(Entry.id == loaded_db_item.id).first() assert new.title == 'new title' assert new.text == 'new text'
def test_add_entry_view_functional(authenticated_app): """Test if the db updates upon request.""" from learning_journal.models import Entry, DBSession authenticated_app.post('/add_entry', {'title': 'fancy title', 'text': 'new text'}) new_entry = DBSession.query(Entry).filter( Entry.title == 'fancy title').first() assert new_entry.id assert new_entry.title == 'fancy title' assert new_entry.text == 'new text'
def test_edit_entry_view_functional(loaded_db_item, authenticated_app): """Test if the db updates upon request.""" from learning_journal.models import Entry, DBSession authenticated_app.post('/edit_entry/{}'.format(loaded_db_item.id), { 'title': 'new title', 'text': 'new text' }) new = DBSession.query(Entry).filter(Entry.id == loaded_db_item.id).first() assert new.title == 'new title' assert new.text == 'new text'
def edit_post(request): entry_id = request.matchdict['id'] entry = DBSession.query(Entry).get(entry_id) form = EntryForm(request.POST, entry) if request.method == 'POST' and form.validate(): form.populate_obj(entry) DBSession.add(entry) DBSession.flush() url = request.route_url('entry', id=entry_id) return HTTPFound(url) return {'form': form}
def test_add_entry_view_functional(authenticated_app): """Test if the db updates upon request.""" from learning_journal.models import Entry, DBSession authenticated_app.post('/add_entry', { 'title': 'fancy title', 'text': 'new text' }) new_entry = DBSession.query(Entry).filter( Entry.title == 'fancy title').first() assert new_entry.id assert new_entry.title == 'fancy title' assert new_entry.text == 'new text'
def test_edit(dbtransaction, app, new_entry, auth_env): """Test that an entry was created by a person whose logged in.""" title = new_entry.title text = new_entry.text entry_dict = {'title': title, 'text': text, 'username': '******', 'password': '******' } app.post('/{}/edit'.format(new_entry.id), params=entry_dict, status='3*') results = DBSession.query(Entry).filter( Entry.title == title and Entry.text == text) assert results.count() == 1
def teardown(): DBSession.query(Entry).filter(Entry.id == new_entry.id).delete() DBSession.flush()
def view_post(request): entry_id = '{id}'.format(**request.matchdict) entry = DBSession.query(Entry).get(entry_id) return {'entry': entry}
def post_index(request): entries = DBSession.query(Entry).all() return {'entries': entries}